aboutsummaryrefslogtreecommitdiffstats
path: root/usr/klibc/stdio/fseek.c
blob: e35f85e64a6323d070040ae891bdd2096c3213d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
 * fseek.c
 */

#include "stdioint.h"

__extern int fseek(FILE *file, off_t where, int whence)
{
	struct _IO_file_pvt *f = stdio_pvt(file);
	off_t rv;

	if (f->obytes)
		if (__fflush(f))
			return -1;

	if (whence == SEEK_CUR)
		where -= f->ibytes;

	rv = lseek(f->pub._IO_fileno, where, whence);
	if (__likely(rv >= 0)) {
		f->pub._IO_eof = false;
		f->ibytes = 0;
		return 0;
	} else {
		f->pub._IO_error = true;
		return -1;
	}
}