Select Git revision
-
Fredrik Hübinette (Hubbe) authored
Rev: src/.cvsignore:1.24 Rev: src/Makefile.in:1.198 Rev: src/aclocal.m4:1.17 Rev: src/array.c:1.79 Rev: src/array.h:1.22 Rev: src/backend.c:1.53 Rev: src/backend.h:1.9 Rev: src/bignum.c:1.17 Rev: src/bignum.h:1.14 Rev: src/builtin_functions.c:1.293 Rev: src/builtin_functions.h:1.14 Rev: src/callback.c:1.20 Rev: src/configure.in:1.387 Rev: src/constants.c:1.22 Rev: src/dynamic_buffer.c:1.10 Rev: src/dynamic_load.c:1.41 Rev: src/error.c:1.56 Rev: src/error.h:1.46 Rev: src/fd_control.c:1.32 Rev: src/fdlib.c:1.37 Rev: src/fdlib.h:1.34 Rev: src/fsort.c:1.13 Rev: src/fsort_template.h:1.7 Rev: src/gc.c:1.110 Rev: src/gc.h:1.57 Rev: src/global.h:1.44 Rev: src/interpret.c:1.158 Rev: src/interpret.h:1.52 Rev: src/main.c:1.94 Rev: src/mapping.c:1.94 Rev: src/mapping.h:1.28 Rev: src/module_magic.h:1.1 Rev: src/module_support.c:1.34 Rev: src/module_support.h:1.7 Rev: src/multiset.c:1.26 Rev: src/object.c:1.137 Rev: src/object.h:1.50 Rev: src/opcodes.c:1.78 Rev: src/operators.c:1.93 Rev: src/operators.h:1.8 Rev: src/pike_macros.h:1.17 Rev: src/pike_memory.c:1.71 Rev: src/pike_memory.h:1.14 Rev: src/pike_types.c:1.132 Rev: src/port.c:1.28 Rev: src/precompile.sh.in:1.2 Rev: src/program.c:1.252 Rev: src/program.h:1.97 Rev: src/signal_handler.c:1.173 Rev: src/stralloc.c:1.85 Rev: src/stralloc.h:1.42 Rev: src/stuff.c:1.11 Rev: src/svalue.c:1.85 Rev: src/svalue.h:1.62 Rev: src/testsuite.in:1.316 Rev: src/threads.c:1.133 Rev: src/threads.h:1.99
Fredrik Hübinette (Hubbe) authoredRev: src/.cvsignore:1.24 Rev: src/Makefile.in:1.198 Rev: src/aclocal.m4:1.17 Rev: src/array.c:1.79 Rev: src/array.h:1.22 Rev: src/backend.c:1.53 Rev: src/backend.h:1.9 Rev: src/bignum.c:1.17 Rev: src/bignum.h:1.14 Rev: src/builtin_functions.c:1.293 Rev: src/builtin_functions.h:1.14 Rev: src/callback.c:1.20 Rev: src/configure.in:1.387 Rev: src/constants.c:1.22 Rev: src/dynamic_buffer.c:1.10 Rev: src/dynamic_load.c:1.41 Rev: src/error.c:1.56 Rev: src/error.h:1.46 Rev: src/fd_control.c:1.32 Rev: src/fdlib.c:1.37 Rev: src/fdlib.h:1.34 Rev: src/fsort.c:1.13 Rev: src/fsort_template.h:1.7 Rev: src/gc.c:1.110 Rev: src/gc.h:1.57 Rev: src/global.h:1.44 Rev: src/interpret.c:1.158 Rev: src/interpret.h:1.52 Rev: src/main.c:1.94 Rev: src/mapping.c:1.94 Rev: src/mapping.h:1.28 Rev: src/module_magic.h:1.1 Rev: src/module_support.c:1.34 Rev: src/module_support.h:1.7 Rev: src/multiset.c:1.26 Rev: src/object.c:1.137 Rev: src/object.h:1.50 Rev: src/opcodes.c:1.78 Rev: src/operators.c:1.93 Rev: src/operators.h:1.8 Rev: src/pike_macros.h:1.17 Rev: src/pike_memory.c:1.71 Rev: src/pike_memory.h:1.14 Rev: src/pike_types.c:1.132 Rev: src/port.c:1.28 Rev: src/precompile.sh.in:1.2 Rev: src/program.c:1.252 Rev: src/program.h:1.97 Rev: src/signal_handler.c:1.173 Rev: src/stralloc.c:1.85 Rev: src/stralloc.h:1.42 Rev: src/stuff.c:1.11 Rev: src/svalue.c:1.85 Rev: src/svalue.h:1.62 Rev: src/testsuite.in:1.316 Rev: src/threads.c:1.133 Rev: src/threads.h:1.99
fd_control.c 2.19 KiB
/*\
||| This file a part of Pike, and is copyright by Fredrik Hubinette
||| Pike is distributed as GPL (General Public License)
||| See the files COPYING and DISCLAIMER for more information.
\*/
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include "fd_control.h"
#ifndef TESTING
#include "global.h"
#include "error.h"
#else
#undef DEBUG
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#ifdef HAVE_SYS_FILIO_H
#include <sys/filio.h>
#endif
#ifdef HAVE_SYS_SOCKIO_H
#include <sys/sockio.h>
#endif
void set_nonblocking(int fd,int which)
{
#ifdef DEBUG
if(fd<0 || fd >MAX_OPEN_FILEDESCRIPTORS)
fatal("Filedescriptor out of range.\n");
#endif
#ifdef USE_IOCTL_FIONBIO
ioctl(fd, FIONBIO, &which);
#else
#ifdef USE_FCNTL_O_NDELAY
fcntl(fd, F_SETFL, which?O_NDELAY:0);
#else
#ifdef USE_FCNTL_O_NONBLOCK
fcntl(fd, F_SETFL, which?O_NONBLOCK:0);
#else
#ifdef USE_FCNTL_FNDELAY
fcntl(fd, F_SETFL, which?FNDELAY:0);
#else
#error Do not know how to set your filedescriptors nonblocking.
#endif
#endif
#endif
#endif
}
int query_nonblocking(int fd)
{
#ifdef DEBUG
if(fd<0 || fd > MAX_OPEN_FILEDESCRIPTORS)
fatal("Filedescriptor out of range.\n");
#endif
#ifdef USE_IOCTL_FIONBIO
/* I don't know how to query this!!!! */
return 0;
#else
#ifdef USE_FCNTL_O_NDELAY
return fcntl(fd, F_GETFL, 0) & O_NDELAY;
#else
#ifdef USE_FCNTL_O_NONBLOCK
return fcntl(fd, F_GETFL, 0) & O_NONBLOCK;
#else
#ifdef USE_FCNTL_FNDELAY
return fcntl(fd, F_GETFL, 0) & FNDELAY;
#else
#error Do not know how to set your filedescriptors nonblocking.
#endif
#endif
#endif
#endif
}
int set_close_on_exec(int fd, int which)
{
return fcntl(fd, F_SETFD, !!which);
}
#ifdef TESTING
#include <signal.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
/* a part of the autoconf thingy */
RETSIGTYPE sigalrm_handler0(int tmp) { exit(0); }
RETSIGTYPE sigalrm_handler1(int tmp) { exit(1); }
main()
{
int tmp[2];
char foo[1000];
tmp[0]=0;
tmp[1]=0;
#ifdef HAVE_PIPE
pipe(tmp);
#endif
set_nonblocking(tmp[0],1);
signal(SIGALRM, sigalrm_handler1);
alarm(1);
read(tmp[0],foo,999);
set_nonblocking(tmp[0],0);
signal(SIGALRM, sigalrm_handler0);
alarm(1);
read(tmp[0],foo,999);
exit(1);
}
#endif