* Implement __srget on FreeBSD, which is yet another version of __srefill.
This commit is contained in:
+11
-8
@@ -39,7 +39,7 @@ AC_SUBST(DLL_LDFLAGS)
|
||||
AC_CHECK_HEADERS(windows.h winsock2.h io.h process.h unistd.h inttypes.h stdint.h getopt.h libc.h malloc.h dlfcn.h regex.h sys/cdefs.h sys/socket.h netinet/in.h arpa/inet.h sys/uio.h aio.h sys/mman.h sys/wait.h sys/resource.h sys/time.h endian.h)
|
||||
|
||||
AC_CHECK_FUNCS(setenv waitpid setrlimit gettimeofday fork kill pipe _pipe)
|
||||
AC_CHECK_FUNCS(open64 __open64 lseek64 __lseek64 mmap64 fopen64 __fopen64 freopen64 __freopen64 dup dup2 fseeko fseeko64 __fseeko64 fsetpos64 __fsetpos64 _IO_getc getline getdelim __getdelim fgetln __srefill __filbuf map_fd memalign posix_memalign aio_read accept bind connect socket readv pread recv recvfrom recvmsg mmap valloc sigaction getpagesize getc_unlocked getchar_unlocked fgetc_unlocked fread_unlocked fgets_unlocked)
|
||||
AC_CHECK_FUNCS(open64 __open64 lseek64 __lseek64 mmap64 fopen64 __fopen64 freopen64 __freopen64 dup dup2 fseeko fseeko64 __fseeko64 fsetpos64 __fsetpos64 _IO_getc getline getdelim __getdelim fgetln __srefill __filbuf __srget map_fd memalign posix_memalign aio_read accept bind connect socket readv pread recv recvfrom recvmsg mmap valloc sigaction getpagesize getc_unlocked getchar_unlocked fgetc_unlocked fread_unlocked fgets_unlocked)
|
||||
|
||||
AC_CHECK_TYPES(sighandler_t, [], [],
|
||||
[#define _GNU_SOURCE
|
||||
@@ -73,13 +73,16 @@ ac_v_fp_cnt="unknown"
|
||||
ac_v_fp_ptr="unknown"
|
||||
AC_TRY_COMPILE([#include <stdio.h>],
|
||||
[FILE *fp; fp->__cnt++; fp->__ptr++],
|
||||
[ac_v_fp_cnt=__cnt; ac_v_fp_ptr=__ptr])
|
||||
AC_TRY_COMPILE([#include <stdio.h>],
|
||||
[FILE *fp; fp->_cnt++; fp->_ptr++],
|
||||
[ac_v_fp_cnt=_cnt; ac_v_fp_ptr=_ptr])
|
||||
AC_TRY_COMPILE([#include <stdio.h>],
|
||||
[FILE *fp; fp->_c++; fp->_p++],
|
||||
[ac_v_fp_cnt=_c; ac_v_fp_ptr=_p])
|
||||
[ac_v_fp_cnt=__cnt; ac_v_fp_ptr=__ptr],
|
||||
[AC_TRY_COMPILE([#include <stdio.h>],
|
||||
[FILE *fp; fp->_cnt++; fp->_ptr++],
|
||||
[ac_v_fp_cnt=_cnt; ac_v_fp_ptr=_ptr],
|
||||
[AC_TRY_COMPILE([#include <stdio.h>],
|
||||
[FILE *fp; fp->_c++; fp->_p++],
|
||||
[ac_v_fp_cnt=_c; ac_v_fp_ptr=_p],
|
||||
[AC_TRY_COMPILE([#include <stdio.h>],
|
||||
[FILE *fp; fp->_r++; fp->_p++],
|
||||
[ac_v_fp_cnt=_r; ac_v_fp_ptr=_p])])])])
|
||||
AC_MSG_RESULT($ac_v_fp_cnt/$ac_v_fp_ptr)
|
||||
AC_DEFINE_UNQUOTED(FILE_CNT, $ac_v_fp_cnt, [Define to the FILE::cnt member name])
|
||||
AC_DEFINE_UNQUOTED(FILE_PTR, $ac_v_fp_ptr, [Define to the FILE::ptr member name])
|
||||
|
||||
+1
-1
@@ -100,7 +100,7 @@ Required on Linux:
|
||||
\fBfread_unlocked\fR()
|
||||
.TP
|
||||
Required on BSD systems:
|
||||
\fBfgetln\fR(), \fB__srefill\fR()
|
||||
\fBfgetln\fR(), \fB__srefill\fR(), \fB__srget\fR()
|
||||
.TP
|
||||
Required on Mac OS X:
|
||||
\fBmap_fd\fR()
|
||||
|
||||
+41
-49
@@ -55,6 +55,10 @@ int NEW(__srefill)(FILE *fp);
|
||||
int NEW(__filbuf)(FILE *fp);
|
||||
#endif
|
||||
|
||||
#if defined HAVE___SRGET
|
||||
int NEW(__srget)(FILE *fp);
|
||||
#endif
|
||||
|
||||
/* Library functions that we divert */
|
||||
static FILE * (*ORIG(fopen)) (const char *path, const char *mode);
|
||||
#if defined HAVE_FOPEN64
|
||||
@@ -138,6 +142,9 @@ static char * (*ORIG(fgetln)) (FILE *stream, size_t *len);
|
||||
#if defined HAVE___SREFILL
|
||||
int (*ORIG(__srefill)) (FILE *fp);
|
||||
#endif
|
||||
#if defined HAVE___SRGET
|
||||
int (*ORIG(__srget)) (FILE *fp);
|
||||
#endif
|
||||
|
||||
/* Additional HP-UXisms */
|
||||
#if defined HAVE___FILBUF
|
||||
@@ -748,65 +755,50 @@ char *NEW(fgetln)(FILE *stream, size_t *len)
|
||||
}
|
||||
#endif
|
||||
|
||||
#define REFILL(fn) \
|
||||
do \
|
||||
{ \
|
||||
off_t newpos; \
|
||||
int fd; \
|
||||
LOADSYM(fn); \
|
||||
fd = fileno(fp); \
|
||||
if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \
|
||||
return ORIG(fn)(fp); \
|
||||
_zz_lock(fd); \
|
||||
ret = ORIG(fn)(fp); \
|
||||
newpos = lseek(fd, 0, SEEK_CUR); \
|
||||
_zz_unlock(fd); \
|
||||
if(ret != EOF) \
|
||||
{ \
|
||||
if(newpos != -1) \
|
||||
_zz_setpos(fd, newpos - fp->FILE_CNT - 1); \
|
||||
_zz_fuzz(fd, fp->FILE_PTR - 1, fp->FILE_CNT + 1); \
|
||||
ret = (uint8_t)fp->FILE_PTR[-1]; \
|
||||
_zz_addpos(fd, fp->FILE_CNT + 1); \
|
||||
} \
|
||||
if(!_zz_islocked(fd)) \
|
||||
debug("%s([%i]) = %i", __func__, fd, ret); \
|
||||
} \
|
||||
while(0)
|
||||
|
||||
#if defined HAVE___SREFILL
|
||||
int NEW(__srefill)(FILE *fp)
|
||||
{
|
||||
off_t newpos;
|
||||
int ret, fd;
|
||||
int ret; REFILL(__srefill); return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
LOADSYM(__srefill);
|
||||
fd = fileno(fp);
|
||||
if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd))
|
||||
return ORIG(__srefill)(fp);
|
||||
|
||||
_zz_lock(fd);
|
||||
ret = ORIG(__srefill)(fp);
|
||||
newpos = lseek(fd, 0, SEEK_CUR);
|
||||
_zz_unlock(fd);
|
||||
if(ret != EOF)
|
||||
{
|
||||
/* FIXME: do we have to fuzz ret, too, like in __filbuf? */
|
||||
if(newpos != -1)
|
||||
_zz_setpos(fd, newpos - fp->_r);
|
||||
_zz_fuzz(fd, fp->_p, fp->_r);
|
||||
_zz_addpos(fd, fp->_r);
|
||||
}
|
||||
|
||||
if(!_zz_islocked(fd))
|
||||
debug("%s([%i]) = %i", __func__, fd, ret);
|
||||
|
||||
return ret;
|
||||
#if defined HAVE___SRGET
|
||||
int NEW(__srget)(FILE *fp)
|
||||
{
|
||||
int ret; REFILL(__srget); return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined HAVE___FILBUF
|
||||
int NEW(__filbuf)(FILE *fp)
|
||||
{
|
||||
off_t newpos;
|
||||
int ret, fd;
|
||||
|
||||
LOADSYM(__filbuf);
|
||||
fd = fileno(fp);
|
||||
if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd))
|
||||
return ORIG(__filbuf)(fp);
|
||||
|
||||
_zz_lock(fd);
|
||||
ret = ORIG(__filbuf)(fp);
|
||||
newpos = lseek(fd, 0, SEEK_CUR);
|
||||
_zz_unlock(fd);
|
||||
if(ret != EOF)
|
||||
{
|
||||
if(newpos != -1)
|
||||
_zz_setpos(fd, newpos - fp->FILE_CNT - 1);
|
||||
_zz_fuzz(fd, fp->FILE_PTR - 1, fp->FILE_CNT + 1);
|
||||
ret = (uint8_t)fp->FILE_PTR[-1];
|
||||
_zz_addpos(fd, fp->FILE_CNT + 1);
|
||||
}
|
||||
|
||||
if(!_zz_islocked(fd))
|
||||
debug("%s([%i]) = %i", __func__, fd, ret);
|
||||
|
||||
return ret;
|
||||
int ret; REFILL(__filbuf); return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user