Skip to content
Snippets Groups Projects
Select Git revision
  • ae15d22ab59c8d01b7934d49d7cd40c7f76ca86a
  • master default protected
  • streebog
  • gost28147
  • master-updates
  • ed448
  • shake256
  • curve448
  • ecc-sqrt
  • gosthash94cp
  • cmac64
  • block16-refactor
  • siv-mode
  • cmac-layout
  • delete-des-compat
  • delete-rsa_blind
  • aes-struct-layout
  • release-3.4-fixes
  • struct-layout
  • attribute-deprecated
  • rename-data-symbols
  • nettle_3.5.1_release_20190627
  • nettle_3.5_release_20190626
  • nettle_3.5rc1
  • nettle_3.4.1_release_20181204
  • nettle_3.4.1rc1
  • nettle_3.4_release_20171119
  • nettle_3.4rc2
  • nettle_3.4rc1
  • nettle_3.3_release_20161001
  • nettle_3.2_release_20160128
  • nettle_3.1.1_release_20150424
  • nettle_3.1_release_20150407
  • nettle_3.1rc3
  • nettle_3.1rc2
  • nettle_3.1rc1
  • nettle_3.0_release_20140607
  • nettle_2.7.1_release_20130528
  • nettle_2.7_release_20130424
  • nettle_2.6_release_20130116
  • nettle_2.5_release_20120707
41 results

.bootstrap

Blame
  • Forked from Nettle / nettle
    Source project has a limited visibility.
    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