Changeset 1594 for zzuf/trunk/src/load-stream.c
- Timestamp:
- Jan 7, 2007, 10:34:42 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
zzuf/trunk/src/load-stream.c
r1593 r1594 30 30 31 31 #include <stdio.h> 32 #include <sys/types.h> 32 33 33 34 #include "libzzuf.h" … … 42 43 #endif 43 44 static int (*fseek_orig) (FILE *stream, long offset, int whence); 45 #ifdef HAVE_FSEEKO 46 static int (*fseeko_orig) (FILE *stream, off_t offset, int whence); 47 #endif 44 48 static void (*rewind_orig) (FILE *stream); 45 49 static size_t (*fread_orig) (void *ptr, size_t size, size_t nmemb, … … 76 80 #endif 77 81 LOADSYM(fseek); 82 #ifdef HAVE_FSEEKO 83 LOADSYM(fseeko); 84 #endif 78 85 LOADSYM(rewind); 79 86 LOADSYM(fread); … … 129 136 #endif 130 137 138 #define FSEEK(fn, fn2) \ 139 do \ 140 { \ 141 int fd; \ 142 if(!_zz_ready) \ 143 LOADSYM(fn); \ 144 fd = fileno(stream); \ 145 if(!_zz_ready || !_zz_iswatched(fd)) \ 146 return ORIG(fn)(stream, offset, whence); \ 147 _zz_disabled = 1; \ 148 ret = ORIG(fn)(stream, offset, whence); \ 149 _zz_disabled = 0; \ 150 debug(STR(fn)"([%i], %lli, %i) = %i", \ 151 fd, (long long int)offset, whence, ret); \ 152 if(ret == 0) \ 153 { \ 154 /* FIXME: check what happens when fseek()ing a pipe */ \ 155 switch(whence) \ 156 { \ 157 case SEEK_END: \ 158 offset = fn2(stream); \ 159 /* fall through */ \ 160 case SEEK_SET: \ 161 _zz_setpos(fd, offset); \ 162 break; \ 163 case SEEK_CUR: \ 164 _zz_addpos(fd, offset); \ 165 break; \ 166 } \ 167 } \ 168 } while(0) 169 131 170 int fseek(FILE *stream, long offset, int whence) 132 171 { 133 int ret, fd; 134 135 if(!_zz_ready) 136 LOADSYM(fseek); 137 fd = fileno(stream); 138 if(!_zz_ready || !_zz_iswatched(fd)) 139 return fseek_orig(stream, offset, whence); 140 141 _zz_disabled = 1; 142 ret = fseek_orig(stream, offset, whence); 143 _zz_disabled = 0; 144 debug("fseek([%i], %li, %i) = %i", fd, offset, whence, ret); 145 if(ret != 0) 146 return ret; 147 148 /* FIXME: check what happens when fseek()ing a pipe */ 149 switch(whence) 150 { 151 case SEEK_END: 152 offset = ftell(stream); 153 /* fall through */ 154 case SEEK_SET: 155 _zz_setpos(fd, offset); 156 break; 157 case SEEK_CUR: 158 _zz_addpos(fd, offset); 159 break; 160 } 161 return 0; 162 } 172 int ret; FSEEK(fseek, ftell); return ret; 173 } 174 175 #ifdef HAVE_FSEEKO 176 int fseeko(FILE *stream, off_t offset, int whence) 177 { 178 int ret; FSEEK(fseeko, ftello); return ret; 179 } 180 #endif 163 181 164 182 void rewind(FILE *stream)
Note: See TracChangeset
for help on using the changeset viewer.