Changeset 2320 for zzuf


Ignore:
Timestamp:
Apr 26, 2008, 2:24:57 PM (12 years ago)
Author:
Sam Hocevar
Message:
  • Implement dup() and dup2(). They are needed for Debian's implementation of dd which otherwise causes the regression tests to fail.
Location:
zzuf/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/.gitignore

    r2319 r2320  
    1919stamp-*
    2020*-stamp
     21src/zzuf
     22test/zzcat
  • zzuf/trunk/configure.ac

    r2319 r2320  
    3030
    3131AC_CHECK_FUNCS(setenv waitpid setrlimit gettimeofday fork kill pipe _pipe)
    32 AC_CHECK_FUNCS(open64 lseek64 mmap64 fopen64 fseeko _IO_getc getline getdelim __getdelim fgetln __srefill map_fd memalign posix_memalign aio_read accept bind connect socket readv pread recv recvfrom recvmsg mmap valloc sigaction getpagesize)
     32AC_CHECK_FUNCS(open64 lseek64 mmap64 fopen64 dup dup2 fseeko _IO_getc getline getdelim __getdelim fgetln __srefill map_fd memalign posix_memalign aio_read accept bind connect socket readv pread recv recvfrom recvmsg mmap valloc sigaction getpagesize)
    3333
    3434AC_CHECK_TYPES(sighandler_t, [], [],
  • zzuf/trunk/doc/zzuf.1

    r1865 r2320  
    410410.TP
    411411Unix file descriptor handling:
    412 \fBopen\fR(), \fBlseek\fR(), \fBread\fR(), \fBreadv\fR(), \fBpread\fR(),
    413 \fBaccept\fR(), \fBsocket\fR(), \fBrecv\fR(), \fBrecvfrom\fR(), \fBrecvmsg\fR(),
    414 \fBaio_read\fR(), \fBaio_return\fR(), \fBclose\fR()
     412\fBopen\fR(), \fBdup\fR(), \fBdup2\fR(), \fBlseek\fR(), \fBread\fR(),
     413\fBreadv\fR(), \fBpread\fR(), \fBaccept\fR(), \fBsocket\fR(), \fBrecv\fR(),
     414\fBrecvfrom\fR(), \fBrecvmsg\fR(), \fBaio_read\fR(), \fBaio_return\fR(),
     415\fBclose\fR()
    415416.TP
    416417Standard IO streams:
  • zzuf/trunk/src/lib-fd.c

    r1864 r2320  
    8181#if defined HAVE_OPEN64
    8282static int     (*ORIG(open64))  (const char *file, int oflag, ...);
     83#endif
     84#if defined HAVE_DUP
     85static int     (*ORIG(dup))     (int oldfd);
     86#endif
     87#if defined HAVE_DUP2
     88static int     (*ORIG(dup2))    (int oldfd, int newfd);
    8389#endif
    8490#if defined HAVE_ACCEPT
     
    172178#endif
    173179
     180#if defined HAVE_DUP
     181int NEW(dup)(int oldfd)
     182{
     183    int ret;
     184
     185    LOADSYM(dup);
     186    ret = ORIG(dup)(oldfd);
     187    if(!_zz_ready || _zz_islocked(-1) || !_zz_iswatched(oldfd)
     188         || !_zz_isactive(oldfd))
     189        return ret;
     190
     191    if(ret >= 0)
     192    {
     193        debug("%s(%i) = %i", __func__, oldfd, ret);
     194        _zz_register(ret);
     195    }
     196
     197    return ret;
     198}
     199#endif
     200
     201#if defined HAVE_DUP2
     202int NEW(dup2)(int oldfd, int newfd)
     203{
     204    int ret;
     205
     206    LOADSYM(dup2);
     207    ret = ORIG(dup2)(oldfd, newfd);
     208    if(!_zz_ready || _zz_islocked(-1) || !_zz_iswatched(oldfd)
     209         || !_zz_isactive(oldfd))
     210        return ret;
     211
     212    if(ret >= 0)
     213    {
     214        /* We must close newfd if it was open, but only if oldfd != newfd
     215         * and if dup2() suceeded. */
     216        if(oldfd != newfd && _zz_iswatched(newfd) && _zz_isactive(newfd))
     217            _zz_unregister(newfd);
     218
     219        debug("%s(%i, %i) = %i", __func__, oldfd, newfd, ret);
     220        _zz_register(ret);
     221    }
     222
     223    return ret;
     224}
     225#endif
     226
    174227#if defined HAVE_ACCEPT
    175228int NEW(accept)(int sockfd, struct sockaddr *addr, SOCKLEN_T *addrlen)
Note: See TracChangeset for help on using the changeset viewer.