netinet/in.h: add IPPROTO_MH
[uclibc-ng.git] / libc / stdio / fseeko.c
blob781032a538c7719021d2a390fdede2285f8859a2
1 /* Copyright (C) 2004 Manuel Novoa III <mjn3@codepoet.org>
3 * GNU Library General Public License (LGPL) version 2 or later.
5 * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
6 */
8 #include "_stdio.h"
10 #if SEEK_SET != 0 || SEEK_CUR != 1 || SEEK_END != 2
11 # error Assumption violated -- values of SEEK_SET, SEEK_CUR, SEEK_END
12 #endif
14 #ifndef __DO_LARGEFILE
15 # define FSEEK fseek
16 # define OFFSET_TYPE long int
17 #endif
19 int FSEEK(register FILE *stream, OFFSET_TYPE offset, int whence)
21 #if !defined(__DO_LARGEFILE)
23 return fseeko64(stream, offset, whence);
25 #else
27 __offmax_t pos = offset;
28 int retval = -1;
29 __STDIO_AUTO_THREADLOCK_VAR;
31 if (((unsigned int) whence) > 2) {
32 __set_errno(EINVAL);
33 } else {
34 __STDIO_AUTO_THREADLOCK(stream);
36 __STDIO_STREAM_VALIDATE(stream);
38 if ((!__STDIO_STREAM_IS_WRITING(stream)
39 || !__STDIO_COMMIT_WRITE_BUFFER(stream))
40 && ((whence != SEEK_CUR)
41 || (__stdio_adjust_position(stream, &pos) >= 0))
42 && (__SEEK(stream, &pos, whence) >= 0)
43 ) {
45 /* Clear reading/writing modes, EOF, and ungots. */
46 stream->__modeflags &=
47 ~(__MASK_READING|__FLAG_WRITING|__FLAG_EOF);
49 /* Make sure all pointers are reset. */
50 __STDIO_STREAM_INIT_BUFREAD_BUFPOS(stream);
51 __STDIO_STREAM_DISABLE_GETC(stream);
52 __STDIO_STREAM_DISABLE_PUTC(stream);
54 /* We reinitialize the mbstate object. Doing so is
55 * implementation defined behavior. */
56 #ifdef __STDIO_MBSTATE
57 __INIT_MBSTATE(&(stream->__state));
58 #endif
59 #ifdef __UCLIBC_HAS_WCHAR__
60 stream->__ungot_width[0] = 0;
61 #endif
63 retval = 0;
66 __STDIO_STREAM_VALIDATE(stream);
68 __STDIO_AUTO_THREADUNLOCK(stream);
71 return retval;
73 #endif
76 #ifdef __DO_LARGEFILE
77 libc_hidden_def(fseeko64)
78 #else
79 libc_hidden_def(fseek)
80 strong_alias_untyped(fseek,fseeko)
81 #endif