* Put either ORIG() or NEW(() around functions, because the naming scheme is

likely to change for the Win32 port.
This commit is contained in:
Sam Hocevar
2007-01-23 08:45:47 +00:00
committed by sam
parent 0f82d17c66
commit e9e1a7dfe7
6 changed files with 174 additions and 162 deletions

View File

@@ -35,6 +35,9 @@
#include <string.h>
#include <stdio.h>
#if defined HAVE_WINSOCK2_H
# include <winsock2.h>
#endif
#include <sys/types.h>
#if defined HAVE_SYS_SOCKET_H
# include <sys/socket.h>
@@ -68,47 +71,47 @@ static void fuzz_iovec (int fd, const struct iovec *iov, ssize_t ret);
static void offset_check (int fd);
/* Library functions that we divert */
static int (*open_orig) (const char *file, int oflag, ...);
static int (*ORIG(open)) (const char *file, int oflag, ...);
#if defined HAVE_OPEN64
static int (*open64_orig) (const char *file, int oflag, ...);
static int (*ORIG(open64)) (const char *file, int oflag, ...);
#endif
#if defined HAVE_ACCEPT
static int (*accept_orig) (int sockfd, struct sockaddr *addr,
SOCKLEN_T *addrlen);
static int (*ORIG(accept)) (int sockfd, struct sockaddr *addr,
SOCKLEN_T *addrlen);
#endif
#if defined HAVE_SOCKET
static int (*socket_orig) (int domain, int type, int protocol);
static int (*ORIG(socket)) (int domain, int type, int protocol);
#endif
#if defined HAVE_RECV
static RECV_T (*recv_orig) (int s, void *buf, size_t len, int flags);
static RECV_T (*ORIG(recv)) (int s, void *buf, size_t len, int flags);
#endif
#if defined HAVE_RECVFROM
static RECV_T (*recvfrom_orig)(int s, void *buf, size_t len, int flags,
struct sockaddr *from, SOCKLEN_T *fromlen);
static RECV_T (*ORIG(recvfrom))(int s, void *buf, size_t len, int flags,
struct sockaddr *from, SOCKLEN_T *fromlen);
#endif
#if defined HAVE_RECVMSG
static RECV_T (*recvmsg_orig) (int s, struct msghdr *hdr, int flags);
static RECV_T (*ORIG(recvmsg)) (int s, struct msghdr *hdr, int flags);
#endif
#if defined READ_USES_SSIZE_T
static ssize_t (*read_orig) (int fd, void *buf, size_t count);
static ssize_t (*ORIG(read)) (int fd, void *buf, size_t count);
#else
static int (*read_orig) (int fd, void *buf, unsigned int count);
static int (*ORIG(read)) (int fd, void *buf, unsigned int count);
#endif
#if defined HAVE_READV
static ssize_t (*readv_orig) (int fd, const struct iovec *iov, int count);
static ssize_t (*ORIG(readv)) (int fd, const struct iovec *iov, int count);
#endif
#if defined HAVE_PREAD
static ssize_t (*pread_orig) (int fd, void *buf, size_t count, off_t offset);
static ssize_t (*ORIG(pread)) (int fd, void *buf, size_t count, off_t offset);
#endif
#if defined HAVE_AIO_READ
static int (*aio_read_orig) (struct aiocb *aiocbp);
static ssize_t (*aio_return_orig) (struct aiocb *aiocbp);
static int (*ORIG(aio_read)) (struct aiocb *aiocbp);
static ssize_t (*ORIG(aio_return)) (struct aiocb *aiocbp);
#endif
static off_t (*lseek_orig) (int fd, off_t offset, int whence);
static off_t (*ORIG(lseek)) (int fd, off_t offset, int whence);
#if defined HAVE_LSEEK64
static off64_t (*lseek64_orig) (int fd, off64_t offset, int whence);
static off64_t (*ORIG(lseek64)) (int fd, off64_t offset, int whence);
#endif
static int (*close_orig) (int fd);
static int (*ORIG(close)) (int fd);
#define OPEN(fn) \
do \
@@ -142,25 +145,25 @@ static int (*close_orig) (int fd);
} \
} while(0)
int open(const char *file, int oflag, ...)
int NEW(open)(const char *file, int oflag, ...)
{
int ret; OPEN(open); return ret;
}
#if defined HAVE_OPEN64
int open64(const char *file, int oflag, ...)
int NEW(open64)(const char *file, int oflag, ...)
{
int ret; OPEN(open64); return ret;
}
#endif
#if defined HAVE_ACCEPT
int accept(int sockfd, struct sockaddr *addr, SOCKLEN_T *addrlen)
int NEW(accept)(int sockfd, struct sockaddr *addr, SOCKLEN_T *addrlen)
{
int ret;
LOADSYM(accept);
ret = accept_orig(sockfd, addr, addrlen);
ret = ORIG(accept)(sockfd, addr, addrlen);
if(!_zz_ready || _zz_islocked(-1) || !_zz_network)
return ret;
@@ -175,12 +178,12 @@ int accept(int sockfd, struct sockaddr *addr, SOCKLEN_T *addrlen)
#endif
#if defined HAVE_SOCKET
int socket(int domain, int type, int protocol)
int NEW(socket)(int domain, int type, int protocol)
{
int ret;
LOADSYM(socket);
ret = socket_orig(domain, type, protocol);
ret = ORIG(socket)(domain, type, protocol);
if(!_zz_ready || _zz_islocked(-1) || !_zz_network)
return ret;
@@ -195,12 +198,12 @@ int socket(int domain, int type, int protocol)
#endif
#if defined HAVE_RECV
RECV_T recv(int s, void *buf, size_t len, int flags)
RECV_T NEW(recv)(int s, void *buf, size_t len, int flags)
{
int ret;
LOADSYM(recv);
ret = recv_orig(s, buf, len, flags);
ret = ORIG(recv)(s, buf, len, flags);
if(!_zz_ready || !_zz_iswatched(s) || _zz_islocked(s))
return ret;
@@ -227,13 +230,13 @@ RECV_T recv(int s, void *buf, size_t len, int flags)
#endif
#if defined HAVE_RECVFROM
RECV_T recvfrom(int s, void *buf, size_t len, int flags,
struct sockaddr *from, SOCKLEN_T *fromlen)
RECV_T NEW(recvfrom)(int s, void *buf, size_t len, int flags,
struct sockaddr *from, SOCKLEN_T *fromlen)
{
int ret;
LOADSYM(recvfrom);
ret = recvfrom_orig(s, buf, len, flags, from, fromlen);
ret = ORIG(recvfrom)(s, buf, len, flags, from, fromlen);
if(!_zz_ready || !_zz_iswatched(s) || _zz_islocked(s))
return ret;
@@ -261,12 +264,12 @@ RECV_T recvfrom(int s, void *buf, size_t len, int flags,
#endif
#if defined HAVE_RECVMSG
RECV_T recvmsg(int s, struct msghdr *hdr, int flags)
RECV_T NEW(recvmsg)(int s, struct msghdr *hdr, int flags)
{
ssize_t ret;
LOADSYM(recvmsg);
ret = recvmsg_orig(s, hdr, flags);
ret = ORIG(recvmsg)(s, hdr, flags);
if(!_zz_ready || !_zz_iswatched(s) || _zz_islocked(s))
return ret;
@@ -278,15 +281,15 @@ RECV_T recvmsg(int s, struct msghdr *hdr, int flags)
#endif
#if defined READ_USES_SSIZE_T
ssize_t read(int fd, void *buf, size_t count)
ssize_t NEW(read)(int fd, void *buf, size_t count)
#else
int read(int fd, void *buf, unsigned int count)
int NEW(read)(int fd, void *buf, unsigned int count)
#endif
{
int ret;
LOADSYM(read);
ret = read_orig(fd, buf, count);
ret = ORIG(read)(fd, buf, count);
if(!_zz_ready || !_zz_iswatched(fd) || _zz_islocked(fd))
return ret;
@@ -312,12 +315,12 @@ int read(int fd, void *buf, unsigned int count)
}
#if defined HAVE_READV
ssize_t readv(int fd, const struct iovec *iov, int count)
ssize_t NEW(readv)(int fd, const struct iovec *iov, int count)
{
ssize_t ret;
LOADSYM(readv);
ret = readv_orig(fd, iov, count);
ret = ORIG(readv)(fd, iov, count);
if(!_zz_ready || !_zz_iswatched(fd) || _zz_islocked(fd))
return ret;
@@ -330,12 +333,12 @@ ssize_t readv(int fd, const struct iovec *iov, int count)
#endif
#if defined HAVE_PREAD
ssize_t pread(int fd, void *buf, size_t count, off_t offset)
ssize_t NEW(pread)(int fd, void *buf, size_t count, off_t offset)
{
int ret;
LOADSYM(pread);
ret = pread_orig(fd, buf, count, offset);
ret = ORIG(pread)(fd, buf, count, offset);
if(!_zz_ready || !_zz_iswatched(fd) || _zz_islocked(fd))
return ret;
@@ -377,7 +380,7 @@ ssize_t pread(int fd, void *buf, size_t count, off_t offset)
_zz_setpos(fd, ret); \
} while(0)
off_t lseek(int fd, off_t offset, int whence)
off_t NEW(lseek)(int fd, off_t offset, int whence)
{
off_t ret;
LSEEK(lseek, off_t);
@@ -385,7 +388,7 @@ off_t lseek(int fd, off_t offset, int whence)
}
#if defined HAVE_LSEEK64
off64_t lseek64(int fd, off64_t offset, int whence)
off64_t NEW(lseek64)(int fd, off64_t offset, int whence)
{
off64_t ret;
LSEEK(lseek64, off64_t);
@@ -394,17 +397,17 @@ off64_t lseek64(int fd, off64_t offset, int whence)
#endif
#if defined HAVE_AIO_READ
int aio_read(struct aiocb *aiocbp)
int NEW(aio_read)(struct aiocb *aiocbp)
{
int ret;
int fd = aiocbp->aio_fildes;
LOADSYM(aio_read);
if(!_zz_ready || !_zz_iswatched(fd))
return aio_read_orig(aiocbp);
return ORIG(aio_read)(aiocbp);
_zz_lock(fd);
ret = aio_read_orig(aiocbp);
ret = ORIG(aio_read)(aiocbp);
debug("%s({%i, %i, %i, %p, %li, ..., %li}) = %i", __func__,
fd, aiocbp->aio_lio_opcode, aiocbp->aio_reqprio, aiocbp->aio_buf,
@@ -413,16 +416,16 @@ int aio_read(struct aiocb *aiocbp)
return ret;
}
ssize_t aio_return(struct aiocb *aiocbp)
ssize_t NEW(aio_return)(struct aiocb *aiocbp)
{
ssize_t ret;
int fd = aiocbp->aio_fildes;
LOADSYM(aio_return);
if(!_zz_ready || !_zz_iswatched(fd))
return aio_return_orig(aiocbp);
return ORIG(aio_return)(aiocbp);
ret = aio_return_orig(aiocbp);
ret = ORIG(aio_return)(aiocbp);
_zz_unlock(fd);
/* FIXME: make sure were actually *reading* */
@@ -442,7 +445,7 @@ ssize_t aio_return(struct aiocb *aiocbp)
}
#endif
int close(int fd)
int NEW(close)(int fd)
{
int ret;
@@ -451,7 +454,7 @@ int close(int fd)
return 0;
LOADSYM(close);
ret = close_orig(fd);
ret = ORIG(close)(fd);
if(!_zz_ready || !_zz_iswatched(fd) || _zz_islocked(fd))
return ret;
@@ -490,11 +493,11 @@ static void offset_check(int fd)
#if defined HAVE_LSEEK64
off64_t ret;
LOADSYM(lseek64);
ret = lseek64_orig(fd, 0, SEEK_CUR);
ret = ORIG(lseek64)(fd, 0, SEEK_CUR);
#else
off_t ret;
LOADSYM(lseek);
ret = lseek_orig(fd, 0, SEEK_CUR);
ret = ORIG(lseek)(fd, 0, SEEK_CUR);
#endif
if(ret != -1 && ret != _zz_getpos(fd))
debug("warning: offset inconsistency");

View File

@@ -28,6 +28,11 @@
/* Symbol loading stuff */
#define STR(x) #x
#define ORIG(x) x##_orig
#ifdef HAVE_DLFCN_H
# define NEW(x) x
#else
# define NEW(x) x##_new
#endif
/* TODO: do the Win32 part */
#ifdef HAVE_DLFCN_H

View File

@@ -61,36 +61,36 @@
/* TODO: mremap, maybe brk/sbrk (haha) */
/* Library functions that we divert */
static void * (*calloc_orig) (size_t nmemb, size_t size);
static void * (*malloc_orig) (size_t size);
static void (*free_orig) (void *ptr);
static void * (*ORIG(calloc)) (size_t nmemb, size_t size);
static void * (*ORIG(malloc)) (size_t size);
static void (*ORIG(free)) (void *ptr);
#if defined HAVE_VALLOC
static void * (*valloc_orig) (size_t size);
static void * (*ORIG(valloc)) (size_t size);
#endif
#if defined HAVE_MEMALIGN
static void * (*memalign_orig) (size_t boundary, size_t size);
static void * (*ORIG(memalign)) (size_t boundary, size_t size);
#endif
#if defined HAVE_POSIX_MEMALIGN
static int (*posix_memalign_orig) (void **memptr, size_t alignment,
size_t size);
static int (*ORIG(posix_memalign)) (void **memptr, size_t alignment,
size_t size);
#endif
static void * (*realloc_orig) (void *ptr, size_t size);
static void * (*ORIG(realloc)) (void *ptr, size_t size);
#if defined HAVE_MMAP
static void * (*mmap_orig) (void *start, size_t length, int prot,
int flags, int fd, off_t offset);
static void * (*ORIG(mmap)) (void *start, size_t length, int prot,
int flags, int fd, off_t offset);
#endif
#if defined HAVE_MMAP64
static void * (*mmap64_orig) (void *start, size_t length, int prot,
int flags, int fd, off64_t offset);
static void * (*ORIG(mmap64)) (void *start, size_t length, int prot,
int flags, int fd, off64_t offset);
#endif
#if defined HAVE_MUNMAP
static int (*munmap_orig) (void *start, size_t length);
static int (*ORIG(munmap)) (void *start, size_t length);
#endif
#if defined HAVE_MAP_FD
static kern_return_t (*map_fd_orig) (int fd, vm_offset_t offset,
vm_offset_t *addr, boolean_t find_space,
vm_size_t numbytes);
static kern_return_t (*ORIG(map_fd)) (int fd, vm_offset_t offset,
vm_offset_t *addr, boolean_t find_space,
vm_size_t numbytes);
#endif
/* We need a static memory buffer because some functions call memory
@@ -102,46 +102,46 @@ static int dummy_offset = 0;
#define DUMMY_START ((uintptr_t)dummy_buffer)
#define DUMMY_STOP ((uintptr_t)dummy_buffer + DUMMY_BYTES)
void *calloc(size_t nmemb, size_t size)
void *NEW(calloc)(size_t nmemb, size_t size)
{
void *ret;
if(!calloc_orig)
if(!ORIG(calloc))
{
ret = dummy_buffer + dummy_offset;
memset(ret, 0, (nmemb * size + 7) / 8);
dummy_offset += (nmemb * size + 7) / 8;
return ret;
}
ret = calloc_orig(nmemb, size);
ret = ORIG(calloc)(nmemb, size);
if(ret == NULL && _zz_memory && errno == ENOMEM)
raise(SIGKILL);
return ret;
}
void *malloc(size_t size)
void *NEW(malloc)(size_t size)
{
void *ret;
if(!malloc_orig)
if(!ORIG(malloc))
{
ret = dummy_buffer + dummy_offset;
dummy_offset += (size + 7) / 8;
return ret;
}
ret = malloc_orig(size);
ret = ORIG(malloc)(size);
if(ret == NULL && _zz_memory && errno == ENOMEM)
raise(SIGKILL);
return ret;
}
void free(void *ptr)
void NEW(free)(void *ptr)
{
if((uintptr_t)ptr >= DUMMY_START && (uintptr_t)ptr < DUMMY_STOP)
return;
LOADSYM(free);
free_orig(ptr);
ORIG(free)(ptr);
}
void *realloc(void *ptr, size_t size)
void *NEW(realloc)(void *ptr, size_t size)
{
void *ret;
if((uintptr_t)ptr >= DUMMY_START && (uintptr_t)ptr < DUMMY_STOP)
@@ -152,18 +152,18 @@ void *realloc(void *ptr, size_t size)
return ret;
}
LOADSYM(realloc);
ret = realloc_orig(ptr, size);
ret = ORIG(realloc)(ptr, size);
if(ret == NULL && _zz_memory && errno == ENOMEM)
raise(SIGKILL);
return ret;
}
#if defined HAVE_VALLOC
void *valloc(size_t size)
void *NEW(valloc)(size_t size)
{
void *ret;
LOADSYM(valloc);
ret = valloc_orig(size);
ret = ORIG(valloc)(size);
if(ret == NULL && _zz_memory && errno == ENOMEM)
raise(SIGKILL);
return ret;
@@ -171,11 +171,11 @@ void *valloc(size_t size)
#endif
#if defined HAVE_MEMALIGN
void *memalign(size_t boundary, size_t size)
void *NEW(memalign)(size_t boundary, size_t size)
{
void *ret;
LOADSYM(memalign);
ret = memalign_orig(boundary, size);
ret = ORIG(memalign)(boundary, size);
if(ret == NULL && _zz_memory && errno == ENOMEM)
raise(SIGKILL);
return ret;
@@ -183,11 +183,11 @@ void *memalign(size_t boundary, size_t size)
#endif
#if defined HAVE_POSIX_MEMALIGN
int posix_memalign(void **memptr, size_t alignment, size_t size)
int NEW(posix_memalign)(void **memptr, size_t alignment, size_t size)
{
int ret;
LOADSYM(posix_memalign);
ret = posix_memalign_orig(memptr, alignment, size);
ret = ORIG(posix_memalign)(memptr, alignment, size);
if(ret == ENOMEM && _zz_memory)
raise(SIGKILL);
return ret;
@@ -240,23 +240,23 @@ int nbmaps = 0;
} while(0)
#if defined HAVE_MMAP
void *mmap(void *start, size_t length, int prot, int flags,
int fd, off_t offset)
void *NEW(mmap)(void *start, size_t length, int prot, int flags,
int fd, off_t offset)
{
void *ret; MMAP(mmap, off_t); return ret;
}
#endif
#if defined HAVE_MMAP64
void *mmap64(void *start, size_t length, int prot, int flags,
int fd, off64_t offset)
void *NEW(mmap64)(void *start, size_t length, int prot, int flags,
int fd, off64_t offset)
{
void *ret; MMAP(mmap64, off64_t); return ret;
}
#endif
#if defined HAVE_MUNMAP
int munmap(void *start, size_t length)
int NEW(munmap)(void *start, size_t length)
{
int ret, i;
@@ -267,25 +267,25 @@ int munmap(void *start, size_t length)
continue;
free(start);
ret = munmap_orig(maps[i + 1], length);
ret = ORIG(munmap)(maps[i + 1], length);
maps[i] = NULL;
maps[i + 1] = NULL;
debug("%s(%p, %li) = %i", __func__, start, (long int)length, ret);
return ret;
}
return munmap_orig(start, length);
return ORIG(munmap)(start, length);
}
#endif
#if defined HAVE_MAP_FD
kern_return_t map_fd(int fd, vm_offset_t offset, vm_offset_t *addr,
boolean_t find_space, vm_size_t numbytes)
kern_return_t NEW(map_fd)(int fd, vm_offset_t offset, vm_offset_t *addr,
boolean_t find_space, vm_size_t numbytes)
{
kern_return_t ret;
LOADSYM(map_fd);
ret = map_fd_orig(fd, offset, addr, find_space, numbytes);
ret = ORIG(map_fd)(fd, offset, addr, find_space, numbytes);
if(!_zz_ready || !_zz_iswatched(fd) || _zz_islocked(fd))
return ret;

View File

@@ -45,10 +45,10 @@
#endif
/* Library functions that we divert */
static SIG_T (*signal_orig) (int signum, SIG_T handler);
static SIG_T (*ORIG(signal)) (int signum, SIG_T handler);
#if defined HAVE_SIGACTION
static int (*sigaction_orig) (int signum, const struct sigaction *act,
struct sigaction *oldact);
static int (*ORIG(sigaction)) (int signum, const struct sigaction *act,
struct sigaction *oldact);
#endif
/* Local functions */
static int isfatal(int signum);
@@ -88,16 +88,16 @@ static int isfatal(int signum)
}
}
SIG_T signal(int signum, SIG_T handler)
SIG_T NEW(signal)(int signum, SIG_T handler)
{
SIG_T ret;
LOADSYM(signal);
if(!_zz_signal)
return signal_orig(signum, handler);
return ORIG(signal)(signum, handler);
ret = signal_orig(signum, isfatal(signum) ? SIG_DFL : handler);
ret = ORIG(signal)(signum, isfatal(signum) ? SIG_DFL : handler);
debug("%s(%i, %p) = %p", __func__, signum, handler, ret);
@@ -105,24 +105,25 @@ SIG_T signal(int signum, SIG_T handler)
}
#if defined HAVE_SIGACTION
int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact)
int NEW(sigaction)(int signum, const struct sigaction *act,
struct sigaction *oldact)
{
int ret;
LOADSYM(sigaction);
if(!_zz_signal)
return sigaction_orig(signum, act, oldact);
return ORIG(sigaction)(signum, act, oldact);
if(act && isfatal(signum))
{
struct sigaction newact;
memcpy(&newact, act, sizeof(struct sigaction));
newact.sa_handler = SIG_DFL;
ret = sigaction_orig(signum, &newact, oldact);
ret = ORIG(sigaction)(signum, &newact, oldact);
}
else
ret = sigaction_orig(signum, act, oldact);
ret = ORIG(sigaction)(signum, act, oldact);
debug("%s(%i, %p, %p) = %i", __func__, signum, act, oldact, ret);

View File

@@ -40,51 +40,51 @@
#include "fd.h"
#if defined HAVE___SREFILL
int __srefill(FILE *fp);
int NEW(__srefill)(FILE *fp);
#endif
/* Library functions that we divert */
static FILE * (*fopen_orig) (const char *path, const char *mode);
static FILE * (*ORIG(fopen)) (const char *path, const char *mode);
#if defined HAVE_FOPEN64
static FILE * (*fopen64_orig) (const char *path, const char *mode);
static FILE * (*ORIG(fopen64)) (const char *path, const char *mode);
#endif
static FILE * (*freopen_orig) (const char *path, const char *mode,
FILE *stream);
static int (*fseek_orig) (FILE *stream, long offset, int whence);
static FILE * (*ORIG(freopen)) (const char *path, const char *mode,
FILE *stream);
static int (*ORIG(fseek)) (FILE *stream, long offset, int whence);
#if defined HAVE_FSEEKO
static int (*fseeko_orig) (FILE *stream, off_t offset, int whence);
static int (*ORIG(fseeko)) (FILE *stream, off_t offset, int whence);
#endif
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);
static int (*fgetc_orig) (FILE *stream);
static void (*ORIG(rewind)) (FILE *stream);
static size_t (*ORIG(fread)) (void *ptr, size_t size, size_t nmemb,
FILE *stream);
static int (*ORIG(getc)) (FILE *stream);
static int (*ORIG(fgetc)) (FILE *stream);
#if defined HAVE__IO_GETC
static int (*_IO_getc_orig) (FILE *stream);
static int (*ORIG(_IO_getc)) (FILE *stream);
#endif
static char * (*fgets_orig) (char *s, int size, FILE *stream);
static int (*ungetc_orig) (int c, FILE *stream);
static int (*fclose_orig) (FILE *fp);
static char * (*ORIG(fgets)) (char *s, int size, FILE *stream);
static int (*ORIG(ungetc)) (int c, FILE *stream);
static int (*ORIG(fclose)) (FILE *fp);
/* Additional GNUisms */
#if defined HAVE_GETLINE
static ssize_t (*getline_orig) (char **lineptr, size_t *n, FILE *stream);
static ssize_t (*ORIG(getline)) (char **lineptr, size_t *n, FILE *stream);
#endif
#if defined HAVE_GETDELIM
static ssize_t (*getdelim_orig) (char **lineptr, size_t *n, int delim,
FILE *stream);
static ssize_t (*ORIG(getdelim)) (char **lineptr, size_t *n, int delim,
FILE *stream);
#endif
#if defined HAVE___GETDELIM
static ssize_t (*__getdelim_orig) (char **lineptr, size_t *n, int delim,
FILE *stream);
static ssize_t (*ORIG(__getdelim)) (char **lineptr, size_t *n, int delim,
FILE *stream);
#endif
/* Additional BSDisms */
#if defined HAVE_FGETLN
static char * (*fgetln_orig) (FILE *stream, size_t *len);
static char * (*ORIG(fgetln)) (FILE *stream, size_t *len);
#endif
#if defined HAVE___SREFILL
int (*__srefill_orig) (FILE *fp);
int (*ORIG(__srefill)) (FILE *fp);
#endif
/* Our function wrappers */
@@ -105,19 +105,19 @@ int (*__srefill_orig) (FILE *fp);
} \
} while(0)
FILE *fopen(const char *path, const char *mode)
FILE *NEW(fopen)(const char *path, const char *mode)
{
FILE *ret; FOPEN(fopen); return ret;
}
#if defined HAVE_FOPEN64
FILE *fopen64(const char *path, const char *mode)
FILE *NEW(fopen64)(const char *path, const char *mode)
{
FILE *ret; FOPEN(fopen64); return ret;
}
#endif
FILE *freopen(const char *path, const char *mode, FILE *stream)
FILE *NEW(freopen)(const char *path, const char *mode, FILE *stream)
{
FILE *ret;
int fd0 = -1, fd1 = -1, disp = 0;
@@ -130,7 +130,7 @@ FILE *freopen(const char *path, const char *mode, FILE *stream)
}
_zz_lock(-1);
ret = freopen_orig(path, mode, stream);
ret = ORIG(freopen)(path, mode, stream);
_zz_unlock(-1);
if(ret && _zz_mustwatch(path))
@@ -185,19 +185,19 @@ FILE *freopen(const char *path, const char *mode, FILE *stream)
FSEEK_FUZZ(fn2) \
} while(0)
int fseek(FILE *stream, long offset, int whence)
int NEW(fseek)(FILE *stream, long offset, int whence)
{
int ret; FSEEK(fseek, ftell); return ret;
}
#if defined HAVE_FSEEKO
int fseeko(FILE *stream, off_t offset, int whence)
int NEW(fseeko)(FILE *stream, off_t offset, int whence)
{
int ret; FSEEK(fseeko, ftello); return ret;
}
#endif
void rewind(FILE *stream)
void NEW(rewind)(FILE *stream)
{
int fd;
@@ -205,12 +205,12 @@ void rewind(FILE *stream)
fd = fileno(stream);
if(!_zz_ready || !_zz_iswatched(fd))
{
rewind_orig(stream);
ORIG(rewind)(stream);
return;
}
_zz_lock(fd);
rewind_orig(stream);
ORIG(rewind)(stream);
_zz_unlock(fd);
debug("%s([%i])", __func__, fd);
@@ -221,7 +221,7 @@ void rewind(FILE *stream)
#endif
}
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
size_t NEW(fread)(void *ptr, size_t size, size_t nmemb, FILE *stream)
{
long int pos;
#if defined HAVE___SREFILL /* Don't fuzz or seek if we have __srefill() */
@@ -234,11 +234,11 @@ size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
LOADSYM(fread);
fd = fileno(stream);
if(!_zz_ready || !_zz_iswatched(fd))
return fread_orig(ptr, size, nmemb, stream);
return ORIG(fread)(ptr, size, nmemb, stream);
pos = ftell(stream);
_zz_lock(fd);
ret = fread_orig(ptr, size, nmemb, stream);
ret = ORIG(fread)(ptr, size, nmemb, stream);
_zz_unlock(fd);
debug("%s(%p, %li, %li, [%i]) = %li", __func__, ptr,
(long int)size, (long int)nmemb, fd, (long int)ret);
@@ -290,24 +290,24 @@ size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
} while(0)
#undef getc /* can be a macro; we dont want that */
int getc(FILE *stream)
int NEW(getc)(FILE *stream)
{
int ret; FGETC(getc); return ret;
}
int fgetc(FILE *stream)
int NEW(fgetc)(FILE *stream)
{
int ret; FGETC(fgetc); return ret;
}
#if defined HAVE__IO_GETC
int _IO_getc(FILE *stream)
int NEW(_IO_getc)(FILE *stream)
{
int ret; FGETC(_IO_getc); return ret;
}
#endif
char *fgets(char *s, int size, FILE *stream)
char *NEW(fgets)(char *s, int size, FILE *stream)
{
char *ret = s;
int fd;
@@ -316,11 +316,11 @@ char *fgets(char *s, int size, FILE *stream)
LOADSYM(fgetc);
fd = fileno(stream);
if(!_zz_ready || !_zz_iswatched(fd))
return fgets_orig(s, size, stream);
return ORIG(fgets)(s, size, stream);
#if defined HAVE___SREFILL /* Don't fuzz or seek if we have __srefill() */
_zz_lock(fd);
ret = fgets_orig(s, size, stream);
ret = ORIG(fgets)(s, size, stream);
_zz_unlock(fd);
#else
if(size <= 0)
@@ -336,7 +336,7 @@ char *fgets(char *s, int size, FILE *stream)
int ch;
_zz_lock(fd);
ch = fgetc_orig(stream);
ch = ORIG(fgetc)(stream);
_zz_unlock(fd);
if(ch == EOF)
@@ -362,7 +362,7 @@ char *fgets(char *s, int size, FILE *stream)
return ret;
}
int ungetc(int c, FILE *stream)
int NEW(ungetc)(int c, FILE *stream)
{
unsigned char ch = c;
int ret, fd;
@@ -370,7 +370,7 @@ int ungetc(int c, FILE *stream)
LOADSYM(ungetc);
fd = fileno(stream);
if(!_zz_ready || !_zz_iswatched(fd))
return ungetc_orig(c, stream);
return ORIG(ungetc)(c, stream);
#if defined HAVE___SREFILL /* Don't fuzz or seek if we have __srefill() */
#else
@@ -378,7 +378,7 @@ int ungetc(int c, FILE *stream)
_zz_fuzz(fd, &ch, 1);
#endif
_zz_lock(fd);
ret = ungetc_orig((int)ch, stream);
ret = ORIG(ungetc)((int)ch, stream);
_zz_unlock(fd);
if(ret >= 0)
@@ -393,17 +393,17 @@ int ungetc(int c, FILE *stream)
return ret;
}
int fclose(FILE *fp)
int NEW(fclose)(FILE *fp)
{
int ret, fd;
LOADSYM(fclose);
fd = fileno(fp);
if(!_zz_ready || !_zz_iswatched(fd))
return fclose_orig(fp);
return ORIG(fclose)(fp);
_zz_lock(fd);
ret = fclose_orig(fp);
ret = ORIG(fclose)(fp);
_zz_unlock(fd);
debug("%s([%i]) = %i", __func__, fd, ret);
_zz_unregister(fd);
@@ -421,7 +421,7 @@ int fclose(FILE *fp)
LOADSYM(fgetc); \
fd = fileno(stream); \
if(!_zz_ready || !_zz_iswatched(fd)) \
return getdelim_orig(lineptr, n, delim, stream); \
return ORIG(getdelim)(lineptr, n, delim, stream); \
line = *lineptr; \
size = line ? *n : 0; \
ret = done = finished = 0; \
@@ -438,7 +438,7 @@ int fclose(FILE *fp)
break; \
} \
_zz_lock(fd); \
ch = fgetc_orig(stream); \
ch = ORIG(fgetc)(stream); \
_zz_unlock(fd); \
if(ch == EOF) \
{ \
@@ -468,28 +468,28 @@ int fclose(FILE *fp)
} while(0)
#if defined HAVE_GETLINE
ssize_t getline(char **lineptr, size_t *n, FILE *stream)
ssize_t NEW(getline)(char **lineptr, size_t *n, FILE *stream)
{
ssize_t ret; GETDELIM(getline, '\n', 0); return ret;
}
#endif
#if defined HAVE_GETDELIM
ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream)
ssize_t NEW(getdelim)(char **lineptr, size_t *n, int delim, FILE *stream)
{
ssize_t ret; GETDELIM(getdelim, delim, 1); return ret;
}
#endif
#if defined HAVE___GETDELIM
ssize_t __getdelim(char **lineptr, size_t *n, int delim, FILE *stream)
ssize_t NEW(__getdelim)(char **lineptr, size_t *n, int delim, FILE *stream)
{
ssize_t ret; GETDELIM(__getdelim, delim, 1); return ret;
}
#endif
#if defined HAVE_FGETLN
char *fgetln(FILE *stream, size_t *len)
char *NEW(fgetln)(FILE *stream, size_t *len)
{
char *ret;
#if defined HAVE___SREFILL /* Don't fuzz or seek if we have __srefill() */
@@ -503,11 +503,11 @@ char *fgetln(FILE *stream, size_t *len)
LOADSYM(fgetc);
fd = fileno(stream);
if(!_zz_ready || !_zz_iswatched(fd))
return fgetln_orig(stream, len);
return ORIG(fgetln)(stream, len);
#if defined HAVE___SREFILL /* Don't fuzz or seek if we have __srefill() */
_zz_lock(fd);
ret = fgetln_orig(stream, len);
ret = ORIG(fgetln)(stream, len);
_zz_unlock(fd);
#else
fuzz = _zz_getfuzz(fd);
@@ -517,7 +517,7 @@ char *fgetln(FILE *stream, size_t *len)
int ch;
_zz_lock(fd);
ch = fgetc_orig(stream);
ch = ORIG(fgetc)(stream);
_zz_unlock(fd);
if(ch == EOF)
@@ -544,7 +544,7 @@ char *fgetln(FILE *stream, size_t *len)
#endif
#if defined HAVE___SREFILL
int __srefill(FILE *fp)
int NEW(__srefill)(FILE *fp)
{
off_t newpos;
int ret, fd, tmp;
@@ -552,10 +552,10 @@ int __srefill(FILE *fp)
LOADSYM(__srefill);
fd = fileno(fp);
if(!_zz_ready || !_zz_iswatched(fd))
return __srefill_orig(fp);
return ORIG(__srefill)(fp);
_zz_lock(fd);
ret = __srefill_orig(fp);
ret = ORIG(__srefill)(fp);
newpos = lseek(fd, 0, SEEK_CUR);
_zz_unlock(fd);
if(ret != EOF)

View File

@@ -32,6 +32,9 @@
#if defined HAVE_REGEX_H
# include <regex.h>
#endif
#if defined HAVE_WINSOCK2_H
# include <winsock2.h>
#endif
#include <string.h>
#include <errno.h>
#include <signal.h>