Changeset 1699 for zzuf/trunk
- Timestamp:
- Jan 23, 2007, 9:45:47 AM (15 years ago)
- Location:
- zzuf/trunk/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
zzuf/trunk/src/lib-fd.c
r1696 r1699 36 36 #include <stdio.h> 37 37 38 #if defined HAVE_WINSOCK2_H 39 # include <winsock2.h> 40 #endif 38 41 #include <sys/types.h> 39 42 #if defined HAVE_SYS_SOCKET_H … … 69 72 70 73 /* Library functions that we divert */ 71 static int (* open_orig) (const char *file, int oflag, ...);74 static int (*ORIG(open)) (const char *file, int oflag, ...); 72 75 #if defined HAVE_OPEN64 73 static int (* open64_orig) (const char *file, int oflag, ...);76 static int (*ORIG(open64)) (const char *file, int oflag, ...); 74 77 #endif 75 78 #if defined HAVE_ACCEPT 76 static int (* accept_orig) (int sockfd, struct sockaddr *addr,77 SOCKLEN_T *addrlen);79 static int (*ORIG(accept)) (int sockfd, struct sockaddr *addr, 80 SOCKLEN_T *addrlen); 78 81 #endif 79 82 #if defined HAVE_SOCKET 80 static int (* socket_orig) (int domain, int type, int protocol);83 static int (*ORIG(socket)) (int domain, int type, int protocol); 81 84 #endif 82 85 #if defined HAVE_RECV 83 static RECV_T (* recv_orig) (int s, void *buf, size_t len, int flags);86 static RECV_T (*ORIG(recv)) (int s, void *buf, size_t len, int flags); 84 87 #endif 85 88 #if defined HAVE_RECVFROM 86 static RECV_T (* recvfrom_orig)(int s, void *buf, size_t len, int flags,87 struct sockaddr *from, SOCKLEN_T *fromlen);89 static RECV_T (*ORIG(recvfrom))(int s, void *buf, size_t len, int flags, 90 struct sockaddr *from, SOCKLEN_T *fromlen); 88 91 #endif 89 92 #if defined HAVE_RECVMSG 90 static RECV_T (* recvmsg_orig) (int s, struct msghdr *hdr, int flags);93 static RECV_T (*ORIG(recvmsg)) (int s, struct msghdr *hdr, int flags); 91 94 #endif 92 95 #if defined READ_USES_SSIZE_T 93 static ssize_t (* read_orig) (int fd, void *buf, size_t count);96 static ssize_t (*ORIG(read)) (int fd, void *buf, size_t count); 94 97 #else 95 static int (* read_orig) (int fd, void *buf, unsigned int count);98 static int (*ORIG(read)) (int fd, void *buf, unsigned int count); 96 99 #endif 97 100 #if defined HAVE_READV 98 static ssize_t (* readv_orig) (int fd, const struct iovec *iov, int count);101 static ssize_t (*ORIG(readv)) (int fd, const struct iovec *iov, int count); 99 102 #endif 100 103 #if defined HAVE_PREAD 101 static ssize_t (* pread_orig) (int fd, void *buf, size_t count, off_t offset);104 static ssize_t (*ORIG(pread)) (int fd, void *buf, size_t count, off_t offset); 102 105 #endif 103 106 #if defined HAVE_AIO_READ 104 static int (* aio_read_orig) (struct aiocb *aiocbp);105 static ssize_t (* aio_return_orig) (struct aiocb *aiocbp);106 #endif 107 static off_t (* lseek_orig) (int fd, off_t offset, int whence);107 static int (*ORIG(aio_read)) (struct aiocb *aiocbp); 108 static ssize_t (*ORIG(aio_return)) (struct aiocb *aiocbp); 109 #endif 110 static off_t (*ORIG(lseek)) (int fd, off_t offset, int whence); 108 111 #if defined HAVE_LSEEK64 109 static off64_t (* lseek64_orig) (int fd, off64_t offset, int whence);110 #endif 111 static int (* close_orig) (int fd);112 static off64_t (*ORIG(lseek64)) (int fd, off64_t offset, int whence); 113 #endif 114 static int (*ORIG(close)) (int fd); 112 115 113 116 #define OPEN(fn) \ … … 143 146 } while(0) 144 147 145 int open(const char *file, int oflag, ...)148 int NEW(open)(const char *file, int oflag, ...) 146 149 { 147 150 int ret; OPEN(open); return ret; … … 149 152 150 153 #if defined HAVE_OPEN64 151 int open64(const char *file, int oflag, ...)154 int NEW(open64)(const char *file, int oflag, ...) 152 155 { 153 156 int ret; OPEN(open64); return ret; … … 156 159 157 160 #if defined HAVE_ACCEPT 158 int accept(int sockfd, struct sockaddr *addr, SOCKLEN_T *addrlen)161 int NEW(accept)(int sockfd, struct sockaddr *addr, SOCKLEN_T *addrlen) 159 162 { 160 163 int ret; 161 164 162 165 LOADSYM(accept); 163 ret = accept_orig(sockfd, addr, addrlen);166 ret = ORIG(accept)(sockfd, addr, addrlen); 164 167 if(!_zz_ready || _zz_islocked(-1) || !_zz_network) 165 168 return ret; … … 176 179 177 180 #if defined HAVE_SOCKET 178 int socket(int domain, int type, int protocol)181 int NEW(socket)(int domain, int type, int protocol) 179 182 { 180 183 int ret; 181 184 182 185 LOADSYM(socket); 183 ret = socket_orig(domain, type, protocol);186 ret = ORIG(socket)(domain, type, protocol); 184 187 if(!_zz_ready || _zz_islocked(-1) || !_zz_network) 185 188 return ret; … … 196 199 197 200 #if defined HAVE_RECV 198 RECV_T recv(int s, void *buf, size_t len, int flags)201 RECV_T NEW(recv)(int s, void *buf, size_t len, int flags) 199 202 { 200 203 int ret; 201 204 202 205 LOADSYM(recv); 203 ret = recv_orig(s, buf, len, flags);206 ret = ORIG(recv)(s, buf, len, flags); 204 207 if(!_zz_ready || !_zz_iswatched(s) || _zz_islocked(s)) 205 208 return ret; … … 228 231 229 232 #if defined HAVE_RECVFROM 230 RECV_T recvfrom(int s, void *buf, size_t len, int flags,231 struct sockaddr *from, SOCKLEN_T *fromlen)233 RECV_T NEW(recvfrom)(int s, void *buf, size_t len, int flags, 234 struct sockaddr *from, SOCKLEN_T *fromlen) 232 235 { 233 236 int ret; 234 237 235 238 LOADSYM(recvfrom); 236 ret = recvfrom_orig(s, buf, len, flags, from, fromlen);239 ret = ORIG(recvfrom)(s, buf, len, flags, from, fromlen); 237 240 if(!_zz_ready || !_zz_iswatched(s) || _zz_islocked(s)) 238 241 return ret; … … 262 265 263 266 #if defined HAVE_RECVMSG 264 RECV_T recvmsg(int s, struct msghdr *hdr, int flags)267 RECV_T NEW(recvmsg)(int s, struct msghdr *hdr, int flags) 265 268 { 266 269 ssize_t ret; 267 270 268 271 LOADSYM(recvmsg); 269 ret = recvmsg_orig(s, hdr, flags);272 ret = ORIG(recvmsg)(s, hdr, flags); 270 273 if(!_zz_ready || !_zz_iswatched(s) || _zz_islocked(s)) 271 274 return ret; … … 279 282 280 283 #if defined READ_USES_SSIZE_T 281 ssize_t read(int fd, void *buf, size_t count)284 ssize_t NEW(read)(int fd, void *buf, size_t count) 282 285 #else 283 int read(int fd, void *buf, unsigned int count)286 int NEW(read)(int fd, void *buf, unsigned int count) 284 287 #endif 285 288 { … … 287 290 288 291 LOADSYM(read); 289 ret = read_orig(fd, buf, count);292 ret = ORIG(read)(fd, buf, count); 290 293 if(!_zz_ready || !_zz_iswatched(fd) || _zz_islocked(fd)) 291 294 return ret; … … 313 316 314 317 #if defined HAVE_READV 315 ssize_t readv(int fd, const struct iovec *iov, int count)318 ssize_t NEW(readv)(int fd, const struct iovec *iov, int count) 316 319 { 317 320 ssize_t ret; 318 321 319 322 LOADSYM(readv); 320 ret = readv_orig(fd, iov, count);323 ret = ORIG(readv)(fd, iov, count); 321 324 if(!_zz_ready || !_zz_iswatched(fd) || _zz_islocked(fd)) 322 325 return ret; … … 331 334 332 335 #if defined HAVE_PREAD 333 ssize_t pread(int fd, void *buf, size_t count, off_t offset)336 ssize_t NEW(pread)(int fd, void *buf, size_t count, off_t offset) 334 337 { 335 338 int ret; 336 339 337 340 LOADSYM(pread); 338 ret = pread_orig(fd, buf, count, offset);341 ret = ORIG(pread)(fd, buf, count, offset); 339 342 if(!_zz_ready || !_zz_iswatched(fd) || _zz_islocked(fd)) 340 343 return ret; … … 378 381 } while(0) 379 382 380 off_t lseek(int fd, off_t offset, int whence)383 off_t NEW(lseek)(int fd, off_t offset, int whence) 381 384 { 382 385 off_t ret; … … 386 389 387 390 #if defined HAVE_LSEEK64 388 off64_t lseek64(int fd, off64_t offset, int whence)391 off64_t NEW(lseek64)(int fd, off64_t offset, int whence) 389 392 { 390 393 off64_t ret; … … 395 398 396 399 #if defined HAVE_AIO_READ 397 int aio_read(struct aiocb *aiocbp)400 int NEW(aio_read)(struct aiocb *aiocbp) 398 401 { 399 402 int ret; … … 402 405 LOADSYM(aio_read); 403 406 if(!_zz_ready || !_zz_iswatched(fd)) 404 return aio_read_orig(aiocbp);407 return ORIG(aio_read)(aiocbp); 405 408 406 409 _zz_lock(fd); 407 ret = aio_read_orig(aiocbp);410 ret = ORIG(aio_read)(aiocbp); 408 411 409 412 debug("%s({%i, %i, %i, %p, %li, ..., %li}) = %i", __func__, … … 414 417 } 415 418 416 ssize_t aio_return(struct aiocb *aiocbp)419 ssize_t NEW(aio_return)(struct aiocb *aiocbp) 417 420 { 418 421 ssize_t ret; … … 421 424 LOADSYM(aio_return); 422 425 if(!_zz_ready || !_zz_iswatched(fd)) 423 return aio_return_orig(aiocbp);424 425 ret = aio_return_orig(aiocbp);426 return ORIG(aio_return)(aiocbp); 427 428 ret = ORIG(aio_return)(aiocbp); 426 429 _zz_unlock(fd); 427 430 … … 443 446 #endif 444 447 445 int close(int fd)448 int NEW(close)(int fd) 446 449 { 447 450 int ret; … … 452 455 453 456 LOADSYM(close); 454 ret = close_orig(fd);457 ret = ORIG(close)(fd); 455 458 if(!_zz_ready || !_zz_iswatched(fd) || _zz_islocked(fd)) 456 459 return ret; … … 491 494 off64_t ret; 492 495 LOADSYM(lseek64); 493 ret = lseek64_orig(fd, 0, SEEK_CUR);496 ret = ORIG(lseek64)(fd, 0, SEEK_CUR); 494 497 #else 495 498 off_t ret; 496 499 LOADSYM(lseek); 497 ret = lseek_orig(fd, 0, SEEK_CUR);500 ret = ORIG(lseek)(fd, 0, SEEK_CUR); 498 501 #endif 499 502 if(ret != -1 && ret != _zz_getpos(fd)) -
zzuf/trunk/src/lib-load.h
r1695 r1699 29 29 #define STR(x) #x 30 30 #define ORIG(x) x##_orig 31 #ifdef HAVE_DLFCN_H 32 # define NEW(x) x 33 #else 34 # define NEW(x) x##_new 35 #endif 31 36 32 37 /* TODO: do the Win32 part */ -
zzuf/trunk/src/lib-mem.c
r1695 r1699 62 62 63 63 /* Library functions that we divert */ 64 static void * (* calloc_orig) (size_t nmemb, size_t size);65 static void * (* malloc_orig) (size_t size);66 static void (* free_orig) (void *ptr);64 static void * (*ORIG(calloc)) (size_t nmemb, size_t size); 65 static void * (*ORIG(malloc)) (size_t size); 66 static void (*ORIG(free)) (void *ptr); 67 67 #if defined HAVE_VALLOC 68 static void * (* valloc_orig) (size_t size);68 static void * (*ORIG(valloc)) (size_t size); 69 69 #endif 70 70 #if defined HAVE_MEMALIGN 71 static void * (* memalign_orig) (size_t boundary, size_t size);71 static void * (*ORIG(memalign)) (size_t boundary, size_t size); 72 72 #endif 73 73 #if defined HAVE_POSIX_MEMALIGN 74 static int (* posix_memalign_orig) (void **memptr, size_t alignment,75 size_t size);76 #endif 77 static void * (* realloc_orig) (void *ptr, size_t size);74 static int (*ORIG(posix_memalign)) (void **memptr, size_t alignment, 75 size_t size); 76 #endif 77 static void * (*ORIG(realloc)) (void *ptr, size_t size); 78 78 79 79 #if defined HAVE_MMAP 80 static void * (* mmap_orig) (void *start, size_t length, int prot,81 int flags, int fd, off_t offset);80 static void * (*ORIG(mmap)) (void *start, size_t length, int prot, 81 int flags, int fd, off_t offset); 82 82 #endif 83 83 #if defined HAVE_MMAP64 84 static void * (* mmap64_orig) (void *start, size_t length, int prot,85 int flags, int fd, off64_t offset);84 static void * (*ORIG(mmap64)) (void *start, size_t length, int prot, 85 int flags, int fd, off64_t offset); 86 86 #endif 87 87 #if defined HAVE_MUNMAP 88 static int (* munmap_orig) (void *start, size_t length);88 static int (*ORIG(munmap)) (void *start, size_t length); 89 89 #endif 90 90 #if defined HAVE_MAP_FD 91 static kern_return_t (* map_fd_orig) (int fd, vm_offset_t offset,92 vm_offset_t *addr, boolean_t find_space,93 vm_size_t numbytes);91 static kern_return_t (*ORIG(map_fd)) (int fd, vm_offset_t offset, 92 vm_offset_t *addr, boolean_t find_space, 93 vm_size_t numbytes); 94 94 #endif 95 95 … … 103 103 #define DUMMY_STOP ((uintptr_t)dummy_buffer + DUMMY_BYTES) 104 104 105 void * calloc(size_t nmemb, size_t size)106 { 107 void *ret; 108 if(! calloc_orig)105 void *NEW(calloc)(size_t nmemb, size_t size) 106 { 107 void *ret; 108 if(!ORIG(calloc)) 109 109 { 110 110 ret = dummy_buffer + dummy_offset; … … 113 113 return ret; 114 114 } 115 ret = calloc_orig(nmemb, size);116 if(ret == NULL && _zz_memory && errno == ENOMEM) 117 raise(SIGKILL); 118 return ret; 119 } 120 121 void * malloc(size_t size)122 { 123 void *ret; 124 if(! malloc_orig)115 ret = ORIG(calloc)(nmemb, size); 116 if(ret == NULL && _zz_memory && errno == ENOMEM) 117 raise(SIGKILL); 118 return ret; 119 } 120 121 void *NEW(malloc)(size_t size) 122 { 123 void *ret; 124 if(!ORIG(malloc)) 125 125 { 126 126 ret = dummy_buffer + dummy_offset; … … 128 128 return ret; 129 129 } 130 ret = malloc_orig(size);131 if(ret == NULL && _zz_memory && errno == ENOMEM) 132 raise(SIGKILL); 133 return ret; 134 } 135 136 void free(void *ptr)130 ret = ORIG(malloc)(size); 131 if(ret == NULL && _zz_memory && errno == ENOMEM) 132 raise(SIGKILL); 133 return ret; 134 } 135 136 void NEW(free)(void *ptr) 137 137 { 138 138 if((uintptr_t)ptr >= DUMMY_START && (uintptr_t)ptr < DUMMY_STOP) 139 139 return; 140 140 LOADSYM(free); 141 free_orig(ptr);142 } 143 144 void * realloc(void *ptr, size_t size)141 ORIG(free)(ptr); 142 } 143 144 void *NEW(realloc)(void *ptr, size_t size) 145 145 { 146 146 void *ret; … … 153 153 } 154 154 LOADSYM(realloc); 155 ret = realloc_orig(ptr, size);155 ret = ORIG(realloc)(ptr, size); 156 156 if(ret == NULL && _zz_memory && errno == ENOMEM) 157 157 raise(SIGKILL); … … 160 160 161 161 #if defined HAVE_VALLOC 162 void * valloc(size_t size)162 void *NEW(valloc)(size_t size) 163 163 { 164 164 void *ret; 165 165 LOADSYM(valloc); 166 ret = valloc_orig(size);166 ret = ORIG(valloc)(size); 167 167 if(ret == NULL && _zz_memory && errno == ENOMEM) 168 168 raise(SIGKILL); … … 172 172 173 173 #if defined HAVE_MEMALIGN 174 void * memalign(size_t boundary, size_t size)174 void *NEW(memalign)(size_t boundary, size_t size) 175 175 { 176 176 void *ret; 177 177 LOADSYM(memalign); 178 ret = memalign_orig(boundary, size);178 ret = ORIG(memalign)(boundary, size); 179 179 if(ret == NULL && _zz_memory && errno == ENOMEM) 180 180 raise(SIGKILL); … … 184 184 185 185 #if defined HAVE_POSIX_MEMALIGN 186 int posix_memalign(void **memptr, size_t alignment, size_t size)186 int NEW(posix_memalign)(void **memptr, size_t alignment, size_t size) 187 187 { 188 188 int ret; 189 189 LOADSYM(posix_memalign); 190 ret = posix_memalign_orig(memptr, alignment, size);190 ret = ORIG(posix_memalign)(memptr, alignment, size); 191 191 if(ret == ENOMEM && _zz_memory) 192 192 raise(SIGKILL); … … 241 241 242 242 #if defined HAVE_MMAP 243 void * mmap(void *start, size_t length, int prot, int flags,244 int fd, off_t offset)243 void *NEW(mmap)(void *start, size_t length, int prot, int flags, 244 int fd, off_t offset) 245 245 { 246 246 void *ret; MMAP(mmap, off_t); return ret; … … 249 249 250 250 #if defined HAVE_MMAP64 251 void * mmap64(void *start, size_t length, int prot, int flags,252 int fd, off64_t offset)251 void *NEW(mmap64)(void *start, size_t length, int prot, int flags, 252 int fd, off64_t offset) 253 253 { 254 254 void *ret; MMAP(mmap64, off64_t); return ret; … … 257 257 258 258 #if defined HAVE_MUNMAP 259 int munmap(void *start, size_t length)259 int NEW(munmap)(void *start, size_t length) 260 260 { 261 261 int ret, i; … … 268 268 269 269 free(start); 270 ret = munmap_orig(maps[i + 1], length);270 ret = ORIG(munmap)(maps[i + 1], length); 271 271 maps[i] = NULL; 272 272 maps[i + 1] = NULL; … … 275 275 } 276 276 277 return munmap_orig(start, length);277 return ORIG(munmap)(start, length); 278 278 } 279 279 #endif 280 280 281 281 #if defined HAVE_MAP_FD 282 kern_return_t map_fd(int fd, vm_offset_t offset, vm_offset_t *addr,283 boolean_t find_space, vm_size_t numbytes)282 kern_return_t NEW(map_fd)(int fd, vm_offset_t offset, vm_offset_t *addr, 283 boolean_t find_space, vm_size_t numbytes) 284 284 { 285 285 kern_return_t ret; 286 286 287 287 LOADSYM(map_fd); 288 ret = map_fd_orig(fd, offset, addr, find_space, numbytes);288 ret = ORIG(map_fd)(fd, offset, addr, find_space, numbytes); 289 289 if(!_zz_ready || !_zz_iswatched(fd) || _zz_islocked(fd)) 290 290 return ret; -
zzuf/trunk/src/lib-signal.c
r1695 r1699 46 46 47 47 /* Library functions that we divert */ 48 static SIG_T (* signal_orig) (int signum, SIG_T handler);48 static SIG_T (*ORIG(signal)) (int signum, SIG_T handler); 49 49 #if defined HAVE_SIGACTION 50 static int (* sigaction_orig) (int signum, const struct sigaction *act,51 struct sigaction *oldact);50 static int (*ORIG(sigaction)) (int signum, const struct sigaction *act, 51 struct sigaction *oldact); 52 52 #endif 53 53 /* Local functions */ … … 89 89 } 90 90 91 SIG_T signal(int signum, SIG_T handler)91 SIG_T NEW(signal)(int signum, SIG_T handler) 92 92 { 93 93 SIG_T ret; … … 96 96 97 97 if(!_zz_signal) 98 return signal_orig(signum, handler);98 return ORIG(signal)(signum, handler); 99 99 100 ret = signal_orig(signum, isfatal(signum) ? SIG_DFL : handler);100 ret = ORIG(signal)(signum, isfatal(signum) ? SIG_DFL : handler); 101 101 102 102 debug("%s(%i, %p) = %p", __func__, signum, handler, ret); … … 106 106 107 107 #if defined HAVE_SIGACTION 108 int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) 108 int NEW(sigaction)(int signum, const struct sigaction *act, 109 struct sigaction *oldact) 109 110 { 110 111 int ret; … … 113 114 114 115 if(!_zz_signal) 115 return sigaction_orig(signum, act, oldact);116 return ORIG(sigaction)(signum, act, oldact); 116 117 117 118 if(act && isfatal(signum)) … … 120 121 memcpy(&newact, act, sizeof(struct sigaction)); 121 122 newact.sa_handler = SIG_DFL; 122 ret = sigaction_orig(signum, &newact, oldact);123 ret = ORIG(sigaction)(signum, &newact, oldact); 123 124 } 124 125 else 125 ret = sigaction_orig(signum, act, oldact);126 ret = ORIG(sigaction)(signum, act, oldact); 126 127 127 128 debug("%s(%i, %p, %p) = %i", __func__, signum, act, oldact, ret); -
zzuf/trunk/src/lib-stream.c
r1697 r1699 41 41 42 42 #if defined HAVE___SREFILL 43 int __srefill(FILE *fp);43 int NEW(__srefill)(FILE *fp); 44 44 #endif 45 45 46 46 /* Library functions that we divert */ 47 static FILE * (* fopen_orig) (const char *path, const char *mode);47 static FILE * (*ORIG(fopen)) (const char *path, const char *mode); 48 48 #if defined HAVE_FOPEN64 49 static FILE * (* fopen64_orig) (const char *path, const char *mode);50 #endif 51 static FILE * (* freopen_orig) (const char *path, const char *mode,52 FILE *stream);53 static int (* fseek_orig) (FILE *stream, long offset, int whence);49 static FILE * (*ORIG(fopen64)) (const char *path, const char *mode); 50 #endif 51 static FILE * (*ORIG(freopen)) (const char *path, const char *mode, 52 FILE *stream); 53 static int (*ORIG(fseek)) (FILE *stream, long offset, int whence); 54 54 #if defined HAVE_FSEEKO 55 static int (* fseeko_orig) (FILE *stream, off_t offset, int whence);56 #endif 57 static void (* rewind_orig) (FILE *stream);58 static size_t (* fread_orig) (void *ptr, size_t size, size_t nmemb,59 FILE *stream);60 static int (* getc_orig) (FILE *stream);61 static int (* fgetc_orig) (FILE *stream);55 static int (*ORIG(fseeko)) (FILE *stream, off_t offset, int whence); 56 #endif 57 static void (*ORIG(rewind)) (FILE *stream); 58 static size_t (*ORIG(fread)) (void *ptr, size_t size, size_t nmemb, 59 FILE *stream); 60 static int (*ORIG(getc)) (FILE *stream); 61 static int (*ORIG(fgetc)) (FILE *stream); 62 62 #if defined HAVE__IO_GETC 63 static int (* _IO_getc_orig) (FILE *stream);64 #endif 65 static char * (* fgets_orig) (char *s, int size, FILE *stream);66 static int (* ungetc_orig) (int c, FILE *stream);67 static int (* fclose_orig) (FILE *fp);63 static int (*ORIG(_IO_getc)) (FILE *stream); 64 #endif 65 static char * (*ORIG(fgets)) (char *s, int size, FILE *stream); 66 static int (*ORIG(ungetc)) (int c, FILE *stream); 67 static int (*ORIG(fclose)) (FILE *fp); 68 68 69 69 /* Additional GNUisms */ 70 70 #if defined HAVE_GETLINE 71 static ssize_t (* getline_orig) (char **lineptr, size_t *n, FILE *stream);71 static ssize_t (*ORIG(getline)) (char **lineptr, size_t *n, FILE *stream); 72 72 #endif 73 73 #if defined HAVE_GETDELIM 74 static ssize_t (* getdelim_orig) (char **lineptr, size_t *n, int delim,75 FILE *stream);74 static ssize_t (*ORIG(getdelim)) (char **lineptr, size_t *n, int delim, 75 FILE *stream); 76 76 #endif 77 77 #if defined HAVE___GETDELIM 78 static ssize_t (* __getdelim_orig) (char **lineptr, size_t *n, int delim,79 FILE *stream);78 static ssize_t (*ORIG(__getdelim)) (char **lineptr, size_t *n, int delim, 79 FILE *stream); 80 80 #endif 81 81 82 82 /* Additional BSDisms */ 83 83 #if defined HAVE_FGETLN 84 static char * (* fgetln_orig) (FILE *stream, size_t *len);84 static char * (*ORIG(fgetln)) (FILE *stream, size_t *len); 85 85 #endif 86 86 #if defined HAVE___SREFILL 87 int (* __srefill_orig) (FILE *fp);87 int (*ORIG(__srefill)) (FILE *fp); 88 88 #endif 89 89 … … 106 106 } while(0) 107 107 108 FILE * fopen(const char *path, const char *mode)108 FILE *NEW(fopen)(const char *path, const char *mode) 109 109 { 110 110 FILE *ret; FOPEN(fopen); return ret; … … 112 112 113 113 #if defined HAVE_FOPEN64 114 FILE * fopen64(const char *path, const char *mode)114 FILE *NEW(fopen64)(const char *path, const char *mode) 115 115 { 116 116 FILE *ret; FOPEN(fopen64); return ret; … … 118 118 #endif 119 119 120 FILE * freopen(const char *path, const char *mode, FILE *stream)120 FILE *NEW(freopen)(const char *path, const char *mode, FILE *stream) 121 121 { 122 122 FILE *ret; … … 131 131 132 132 _zz_lock(-1); 133 ret = freopen_orig(path, mode, stream);133 ret = ORIG(freopen)(path, mode, stream); 134 134 _zz_unlock(-1); 135 135 … … 186 186 } while(0) 187 187 188 int fseek(FILE *stream, long offset, int whence)188 int NEW(fseek)(FILE *stream, long offset, int whence) 189 189 { 190 190 int ret; FSEEK(fseek, ftell); return ret; … … 192 192 193 193 #if defined HAVE_FSEEKO 194 int fseeko(FILE *stream, off_t offset, int whence)194 int NEW(fseeko)(FILE *stream, off_t offset, int whence) 195 195 { 196 196 int ret; FSEEK(fseeko, ftello); return ret; … … 198 198 #endif 199 199 200 void rewind(FILE *stream)200 void NEW(rewind)(FILE *stream) 201 201 { 202 202 int fd; … … 206 206 if(!_zz_ready || !_zz_iswatched(fd)) 207 207 { 208 rewind_orig(stream);208 ORIG(rewind)(stream); 209 209 return; 210 210 } 211 211 212 212 _zz_lock(fd); 213 rewind_orig(stream);213 ORIG(rewind)(stream); 214 214 _zz_unlock(fd); 215 215 debug("%s([%i])", __func__, fd); … … 222 222 } 223 223 224 size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)224 size_t NEW(fread)(void *ptr, size_t size, size_t nmemb, FILE *stream) 225 225 { 226 226 long int pos; … … 235 235 fd = fileno(stream); 236 236 if(!_zz_ready || !_zz_iswatched(fd)) 237 return fread_orig(ptr, size, nmemb, stream);237 return ORIG(fread)(ptr, size, nmemb, stream); 238 238 239 239 pos = ftell(stream); 240 240 _zz_lock(fd); 241 ret = fread_orig(ptr, size, nmemb, stream);241 ret = ORIG(fread)(ptr, size, nmemb, stream); 242 242 _zz_unlock(fd); 243 243 debug("%s(%p, %li, %li, [%i]) = %li", __func__, ptr, … … 291 291 292 292 #undef getc /* can be a macro; we don’t want that */ 293 int getc(FILE *stream)293 int NEW(getc)(FILE *stream) 294 294 { 295 295 int ret; FGETC(getc); return ret; 296 296 } 297 297 298 int fgetc(FILE *stream)298 int NEW(fgetc)(FILE *stream) 299 299 { 300 300 int ret; FGETC(fgetc); return ret; … … 302 302 303 303 #if defined HAVE__IO_GETC 304 int _IO_getc(FILE *stream)304 int NEW(_IO_getc)(FILE *stream) 305 305 { 306 306 int ret; FGETC(_IO_getc); return ret; … … 308 308 #endif 309 309 310 char * fgets(char *s, int size, FILE *stream)310 char *NEW(fgets)(char *s, int size, FILE *stream) 311 311 { 312 312 char *ret = s; … … 317 317 fd = fileno(stream); 318 318 if(!_zz_ready || !_zz_iswatched(fd)) 319 return fgets_orig(s, size, stream);320 321 #if defined HAVE___SREFILL /* Don't fuzz or seek if we have __srefill() */ 322 _zz_lock(fd); 323 ret = fgets_orig(s, size, stream);319 return ORIG(fgets)(s, size, stream); 320 321 #if defined HAVE___SREFILL /* Don't fuzz or seek if we have __srefill() */ 322 _zz_lock(fd); 323 ret = ORIG(fgets)(s, size, stream); 324 324 _zz_unlock(fd); 325 325 #else … … 337 337 338 338 _zz_lock(fd); 339 ch = fgetc_orig(stream);339 ch = ORIG(fgetc)(stream); 340 340 _zz_unlock(fd); 341 341 … … 363 363 } 364 364 365 int ungetc(int c, FILE *stream)365 int NEW(ungetc)(int c, FILE *stream) 366 366 { 367 367 unsigned char ch = c; … … 371 371 fd = fileno(stream); 372 372 if(!_zz_ready || !_zz_iswatched(fd)) 373 return ungetc_orig(c, stream);373 return ORIG(ungetc)(c, stream); 374 374 375 375 #if defined HAVE___SREFILL /* Don't fuzz or seek if we have __srefill() */ … … 379 379 #endif 380 380 _zz_lock(fd); 381 ret = ungetc_orig((int)ch, stream);381 ret = ORIG(ungetc)((int)ch, stream); 382 382 _zz_unlock(fd); 383 383 … … 394 394 } 395 395 396 int fclose(FILE *fp)396 int NEW(fclose)(FILE *fp) 397 397 { 398 398 int ret, fd; … … 401 401 fd = fileno(fp); 402 402 if(!_zz_ready || !_zz_iswatched(fd)) 403 return fclose_orig(fp);404 405 _zz_lock(fd); 406 ret = fclose_orig(fp);403 return ORIG(fclose)(fp); 404 405 _zz_lock(fd); 406 ret = ORIG(fclose)(fp); 407 407 _zz_unlock(fd); 408 408 debug("%s([%i]) = %i", __func__, fd, ret); … … 422 422 fd = fileno(stream); \ 423 423 if(!_zz_ready || !_zz_iswatched(fd)) \ 424 return getdelim_orig(lineptr, n, delim, stream); \424 return ORIG(getdelim)(lineptr, n, delim, stream); \ 425 425 line = *lineptr; \ 426 426 size = line ? *n : 0; \ … … 439 439 } \ 440 440 _zz_lock(fd); \ 441 ch = fgetc_orig(stream); \441 ch = ORIG(fgetc)(stream); \ 442 442 _zz_unlock(fd); \ 443 443 if(ch == EOF) \ … … 469 469 470 470 #if defined HAVE_GETLINE 471 ssize_t getline(char **lineptr, size_t *n, FILE *stream)471 ssize_t NEW(getline)(char **lineptr, size_t *n, FILE *stream) 472 472 { 473 473 ssize_t ret; GETDELIM(getline, '\n', 0); return ret; … … 476 476 477 477 #if defined HAVE_GETDELIM 478 ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream)478 ssize_t NEW(getdelim)(char **lineptr, size_t *n, int delim, FILE *stream) 479 479 { 480 480 ssize_t ret; GETDELIM(getdelim, delim, 1); return ret; … … 483 483 484 484 #if defined HAVE___GETDELIM 485 ssize_t __getdelim(char **lineptr, size_t *n, int delim, FILE *stream)485 ssize_t NEW(__getdelim)(char **lineptr, size_t *n, int delim, FILE *stream) 486 486 { 487 487 ssize_t ret; GETDELIM(__getdelim, delim, 1); return ret; … … 490 490 491 491 #if defined HAVE_FGETLN 492 char * fgetln(FILE *stream, size_t *len)492 char *NEW(fgetln)(FILE *stream, size_t *len) 493 493 { 494 494 char *ret; … … 504 504 fd = fileno(stream); 505 505 if(!_zz_ready || !_zz_iswatched(fd)) 506 return fgetln_orig(stream, len);507 508 #if defined HAVE___SREFILL /* Don't fuzz or seek if we have __srefill() */ 509 _zz_lock(fd); 510 ret = fgetln_orig(stream, len);506 return ORIG(fgetln)(stream, len); 507 508 #if defined HAVE___SREFILL /* Don't fuzz or seek if we have __srefill() */ 509 _zz_lock(fd); 510 ret = ORIG(fgetln)(stream, len); 511 511 _zz_unlock(fd); 512 512 #else … … 518 518 519 519 _zz_lock(fd); 520 ch = fgetc_orig(stream);520 ch = ORIG(fgetc)(stream); 521 521 _zz_unlock(fd); 522 522 … … 545 545 546 546 #if defined HAVE___SREFILL 547 int __srefill(FILE *fp)547 int NEW(__srefill)(FILE *fp) 548 548 { 549 549 off_t newpos; … … 553 553 fd = fileno(fp); 554 554 if(!_zz_ready || !_zz_iswatched(fd)) 555 return __srefill_orig(fp);556 557 _zz_lock(fd); 558 ret = __srefill_orig(fp);555 return ORIG(__srefill)(fp); 556 557 _zz_lock(fd); 558 ret = ORIG(__srefill)(fp); 559 559 newpos = lseek(fd, 0, SEEK_CUR); 560 560 _zz_unlock(fd); -
zzuf/trunk/src/zzuf.c
r1698 r1699 32 32 #if defined HAVE_REGEX_H 33 33 # include <regex.h> 34 #endif 35 #if defined HAVE_WINSOCK2_H 36 # include <winsock2.h> 34 37 #endif 35 38 #include <string.h>
Note: See TracChangeset
for help on using the changeset viewer.