From 5329e5a3ea8138fa4debb5375e9608c1e418267c Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sat, 6 Jan 2007 20:01:15 +0000 Subject: [PATCH] * Implemented rewind(). --- src/load-stream.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/load-stream.c b/src/load-stream.c index 00bda76..e6b129a 100644 --- a/src/load-stream.c +++ b/src/load-stream.c @@ -41,6 +41,7 @@ static FILE * (*fopen_orig) (const char *path, const char *mode); static FILE * (*fopen64_orig) (const char *path, const char *mode); #endif static int (*fseek_orig) (FILE *stream, long offset, int whence); +static void (*rewind_orig) (FILE *stream); static size_t (*fread_orig) (void *ptr, size_t size, size_t nmemb, FILE *stream); static int (*getc_orig) (FILE *stream); @@ -74,6 +75,7 @@ void _zz_load_stream(void) LOADSYM(fopen64); #endif LOADSYM(fseek); + LOADSYM(rewind); LOADSYM(fread); LOADSYM(getc); LOADSYM(fgetc); @@ -143,6 +145,7 @@ int fseek(FILE *stream, long offset, int whence) if(ret != 0) return ret; + /* FIXME: check what happens when fseek()ing a pipe */ switch(whence) { case SEEK_END: @@ -158,6 +161,28 @@ int fseek(FILE *stream, long offset, int whence) return 0; } +void rewind(FILE *stream) +{ + int fd; + + if(!_zz_ready) + LOADSYM(rewind); + fd = fileno(stream); + if(!_zz_ready || !_zz_iswatched(fd)) + { + rewind_orig(stream); + return; + } + + _zz_disabled = 1; + rewind_orig(stream); + _zz_disabled = 0; + debug("rewind([%i])", fd); + + /* FIXME: check what happens when rewind()ing a pipe */ + _zz_setpos(fd, 0); +} + size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream) { long int pos;