| OLD | NEW |
| 1 #include "stdio_impl.h" | 1 #include "stdio_impl.h" |
| 2 | 2 |
| 3 int __fseeko_unlocked(FILE *f, off_t off, int whence) | 3 int __fseeko_unlocked(FILE* f, off_t off, int whence) { |
| 4 { | 4 /* Adjust relative offset for unread data in buffer, if any. */ |
| 5 » /* Adjust relative offset for unread data in buffer, if any. */ | 5 if (whence == SEEK_CUR) |
| 6 » if (whence == SEEK_CUR) off -= f->rend - f->rpos; | 6 off -= f->rend - f->rpos; |
| 7 | 7 |
| 8 » /* Flush write buffer, and report error on failure. */ | 8 /* Flush write buffer, and report error on failure. */ |
| 9 » if (f->wpos > f->wbase) { | 9 if (f->wpos > f->wbase) { |
| 10 » » f->write(f, 0, 0); | 10 f->write(f, 0, 0); |
| 11 » » if (!f->wpos) return -1; | 11 if (!f->wpos) |
| 12 » } | 12 return -1; |
| 13 } |
| 13 | 14 |
| 14 » /* Leave writing mode */ | 15 /* Leave writing mode */ |
| 15 » f->wpos = f->wbase = f->wend = 0; | 16 f->wpos = f->wbase = f->wend = 0; |
| 16 | 17 |
| 17 » /* Perform the underlying seek. */ | 18 /* Perform the underlying seek. */ |
| 18 » if (f->seek(f, off, whence) < 0) return -1; | 19 if (f->seek(f, off, whence) < 0) |
| 20 return -1; |
| 19 | 21 |
| 20 » /* If seek succeeded, file is seekable and we discard read buffer. */ | 22 /* If seek succeeded, file is seekable and we discard read buffer. */ |
| 21 » f->rpos = f->rend = 0; | 23 f->rpos = f->rend = 0; |
| 22 » f->flags &= ~F_EOF; | 24 f->flags &= ~F_EOF; |
| 23 » | 25 |
| 24 » return 0; | 26 return 0; |
| 25 } | 27 } |
| 26 | 28 |
| 27 int __fseeko(FILE *f, off_t off, int whence) | 29 int __fseeko(FILE* f, off_t off, int whence) { |
| 28 { | 30 int result; |
| 29 » int result; | 31 FLOCK(f); |
| 30 » FLOCK(f); | 32 result = __fseeko_unlocked(f, off, whence); |
| 31 » result = __fseeko_unlocked(f, off, whence); | 33 FUNLOCK(f); |
| 32 » FUNLOCK(f); | 34 return result; |
| 33 » return result; | |
| 34 } | 35 } |
| 35 | 36 |
| 36 int fseek(FILE *f, long off, int whence) | 37 int fseek(FILE* f, long off, int whence) { |
| 37 { | 38 return __fseeko(f, off, whence); |
| 38 » return __fseeko(f, off, whence); | |
| 39 } | 39 } |
| 40 | 40 |
| 41 weak_alias(__fseeko, fseeko); | 41 weak_alias(__fseeko, fseeko); |
| 42 | 42 |
| 43 weak_alias(__fseeko, fseeko64); | 43 weak_alias(__fseeko, fseeko64); |
| OLD | NEW |