Select Git revision
fd_control.c
-
Fredrik Hübinette (Hubbe) authored
Rev: src/array.c:1.8 Rev: src/builtin_functions.c:1.35 Rev: src/callback.c:1.8 Rev: src/configure.in:1.84 Rev: src/constants.c:1.10 Rev: src/encode.c:1.9 Rev: src/fd_control.c:1.6 Rev: src/gc.c:1.8 Rev: src/interpret.c:1.42 Rev: src/las.c:1.31 Rev: src/lex.c:1.21 Rev: src/main.c:1.21 Rev: src/mapping.c:1.17 Rev: src/memory.h:1.3 Rev: src/module_support.c:1.7 Rev: src/modules/Gmp/mpz_glue.c:1.11 Rev: src/modules/Image/font.c:1.7 Rev: src/modules/Pipe/pipe.c:1.6 Rev: src/modules/Regexp/glue.c:1.5 Rev: src/modules/Yp/yp.c:1.6 Rev: src/modules/_Crypto/Makefile.in:1.9 Rev: src/modules/_Crypto/lib/Makefile.in:1.5 Rev: src/modules/dynamic_module_makefile.in:1.7 Rev: src/modules/files/efuns.c:1.22 Rev: src/modules/files/file.c:1.36 Rev: src/modules/math/math.c:1.4 Rev: src/modules/spider/accesseddb.c:1.7 Rev: src/modules/spider/discdate.c:1.4 Rev: src/modules/spider/dumudp.c:1.8 Rev: src/modules/spider/spider.c:1.29 Rev: src/modules/spider/streamed_parser.c:1.5 Rev: src/modules/sprintf/sprintf.c:1.10 Rev: src/modules/static_module_makefile.in:1.5 Rev: src/modules/system/passwords.c:1.2 Rev: src/modules/system/syslog.c:1.3 Rev: src/modules/system/system.c:1.16 Rev: src/object.c:1.17 Rev: src/opcodes.c:1.6 Rev: src/operators.c:1.13 Rev: src/peep.c:1.10 Rev: src/pike_types.c:1.21 Rev: src/port.c:1.11 Rev: src/port.h:1.16 Rev: src/program.c:1.33 Rev: src/signal_handler.c:1.11 Rev: src/stralloc.c:1.14 Rev: src/stuff.c:1.2 Rev: src/svalue.c:1.9 Rev: src/threads.c:1.21
Fredrik Hübinette (Hubbe) authoredRev: src/array.c:1.8 Rev: src/builtin_functions.c:1.35 Rev: src/callback.c:1.8 Rev: src/configure.in:1.84 Rev: src/constants.c:1.10 Rev: src/encode.c:1.9 Rev: src/fd_control.c:1.6 Rev: src/gc.c:1.8 Rev: src/interpret.c:1.42 Rev: src/las.c:1.31 Rev: src/lex.c:1.21 Rev: src/main.c:1.21 Rev: src/mapping.c:1.17 Rev: src/memory.h:1.3 Rev: src/module_support.c:1.7 Rev: src/modules/Gmp/mpz_glue.c:1.11 Rev: src/modules/Image/font.c:1.7 Rev: src/modules/Pipe/pipe.c:1.6 Rev: src/modules/Regexp/glue.c:1.5 Rev: src/modules/Yp/yp.c:1.6 Rev: src/modules/_Crypto/Makefile.in:1.9 Rev: src/modules/_Crypto/lib/Makefile.in:1.5 Rev: src/modules/dynamic_module_makefile.in:1.7 Rev: src/modules/files/efuns.c:1.22 Rev: src/modules/files/file.c:1.36 Rev: src/modules/math/math.c:1.4 Rev: src/modules/spider/accesseddb.c:1.7 Rev: src/modules/spider/discdate.c:1.4 Rev: src/modules/spider/dumudp.c:1.8 Rev: src/modules/spider/spider.c:1.29 Rev: src/modules/spider/streamed_parser.c:1.5 Rev: src/modules/sprintf/sprintf.c:1.10 Rev: src/modules/static_module_makefile.in:1.5 Rev: src/modules/system/passwords.c:1.2 Rev: src/modules/system/syslog.c:1.3 Rev: src/modules/system/system.c:1.16 Rev: src/object.c:1.17 Rev: src/opcodes.c:1.6 Rev: src/operators.c:1.13 Rev: src/peep.c:1.10 Rev: src/pike_types.c:1.21 Rev: src/port.c:1.11 Rev: src/port.h:1.16 Rev: src/program.c:1.33 Rev: src/signal_handler.c:1.11 Rev: src/stralloc.c:1.14 Rev: src/stuff.c:1.2 Rev: src/svalue.c:1.9 Rev: src/threads.c:1.21
fd_control.c 2.05 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 Don 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 Don 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>
/* a part of the autoconf thingy */
RETSIGTYPE sigalrm_handler0(int tmp) { exit(0); }
RETSIGTYPE sigalrm_handler1(int tmp) { exit(1); }
main()
{
char foo[1000];
set_nonblocking(0,1);
signal(SIGALRM, sigalrm_handler1);
alarm(1);
read(0,foo,999);
set_nonblocking(0,0);
signal(SIGALRM, sigalrm_handler0);
alarm(1);
read(0,foo,999);
exit(1);
}
#endif