1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #include <config.h>
18
19
20 #include <stdio.h>
21
22
23 #include <unistd.h>
24
25 #include "stdio-impl.h"
26
27 int
28 fseeko (FILE *fp, off_t offset, int whence)
29 #undef fseeko
30 #if !HAVE_FSEEKO
31 # undef fseek
32 # define fseeko fseek
33 #endif
34 #if _GL_WINDOWS_64_BIT_OFF_T
35 # undef fseeko
36 # if HAVE__FSEEKI64 && HAVE_DECL__FSEEKI64
37 # define fseeko _fseeki64
38 # else
39 # define fseeko fseeko64
40 # endif
41 #endif
42 {
43 #if LSEEK_PIPE_BROKEN
44
45 if (lseek (fileno (fp), 0, SEEK_CUR) == -1)
46 return EOF;
47 #endif
48
49
50 #if defined _IO_EOF_SEEN || defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1
51
52 if (fp->_IO_read_end == fp->_IO_read_ptr
53 && fp->_IO_write_ptr == fp->_IO_write_base
54 && fp->_IO_save_base == NULL)
55 #elif defined __sferror || defined __DragonFly__ || defined __ANDROID__
56
57 # if defined __SL64 && defined __SCLE
58 if ((fp->_flags & __SL64) == 0)
59 {
60
61
62 FILE *tmp = fopen ("/dev/null", "r");
63 if (!tmp)
64 return -1;
65 fp->_flags |= __SL64;
66 fp->_seek64 = tmp->_seek64;
67 fclose (tmp);
68 }
69 # endif
70 if (fp_->_p == fp_->_bf._base
71 && fp_->_r == 0
72 && fp_->_w == ((fp_->_flags & (__SLBF | __SNBF | __SRD)) == 0
73 ? fp_->_bf._size
74 : 0)
75 && fp_ub._base == NULL)
76 #elif defined __EMX__
77 if (fp->_ptr == fp->_buffer
78 && fp->_rcount == 0
79 && fp->_wcount == 0
80 && fp->_ungetc_count == 0)
81 #elif defined __minix
82 if (fp_->_ptr == fp_->_buf
83 && (fp_->_ptr == NULL || fp_->_count == 0))
84 #elif defined _IOERR
85 if (fp_->_ptr == fp_->_base
86 && (fp_->_ptr == NULL || fp_->_cnt == 0))
87 #elif defined __UCLIBC__
88 if (((fp->__modeflags & __FLAG_WRITING) == 0
89 || fp->__bufpos == fp->__bufstart)
90 && ((fp->__modeflags & (__FLAG_READONLY | __FLAG_READING)) == 0
91 || fp->__bufpos == fp->__bufread))
92 #elif defined __QNX__
93 if ((fp->_Mode & 0x2000 ? fp->_Next == fp->_Buf : fp->_Next == fp->_Rend)
94 && fp->_Rback == fp->_Back + sizeof (fp->_Back)
95 && fp->_Rsave == NULL)
96 #elif defined __MINT__
97 if (fp->__bufp == fp->__buffer
98 && fp->__get_limit == fp->__bufp
99 && fp->__put_limit == fp->__bufp
100 && !fp->__pushed_back)
101 #elif defined EPLAN9
102 if (fp->rp == fp->buf
103 && fp->wp == fp->buf)
104 #elif FUNC_FFLUSH_STDIN < 0 && 200809 <= _POSIX_VERSION
105
106
107
108
109 if (0)
110 #else
111 #error "Please port gnulib fseeko.c to your platform! Look at the code in fseeko.c, then report this to bug-gnulib."
112 #endif
113 {
114
115
116
117 off_t pos = lseek (fileno (fp), offset, whence);
118 if (pos == -1)
119 {
120 #if defined __sferror || defined __DragonFly__ || defined __ANDROID__
121
122 fp_->_flags &= ~__SOFF;
123 #endif
124 return -1;
125 }
126
127 #if defined _IO_EOF_SEEN || defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1
128
129 fp->_flags &= ~_IO_EOF_SEEN;
130 fp->_offset = pos;
131 #elif defined __sferror || defined __DragonFly__ || defined __ANDROID__
132
133 # if defined __CYGWIN__ || (defined __NetBSD__ && __NetBSD_Version__ >= 600000000) || defined __minix
134
135 fp_->_offset = pos;
136 # else
137
138 {
139
140
141
142 union
143 {
144 fpos_t f;
145 off_t o;
146 } u;
147 u.o = pos;
148 fp_->_offset = u.f;
149 }
150 # endif
151 fp_->_flags |= __SOFF;
152 fp_->_flags &= ~__SEOF;
153 #elif defined __EMX__
154 fp->_flags &= ~_IOEOF;
155 #elif defined _IOERR
156 fp_->_flag &= ~_IOEOF;
157 #elif defined __MINT__
158 fp->__offset = pos;
159 fp->__eof = 0;
160 #endif
161 return 0;
162 }
163 return fseeko (fp, offset, whence);
164 }