ftp.nice.ch/Attic/openStep/implementation/gnustep/sources/alpha-snapshots/pthreads.0.9.2.tgz#/pthreads-0.9.2/socklib/noblock.c

This is noblock.c in view mode; [Download] [Up]

#include "pthread_socket.h"

int
nonblock_is_set( int fd )
{
   int non_blocking = FALSE, fd_flags;

   pthread_lock_global_np();
   fd_flags = fcntl( fd, F_GETFL, 0 );
   pthread_unlock_global_np();

   if( fd_flags & O_NONBLOCK )
       non_blocking = TRUE;

   return( non_blocking );
}
   
/*
 * Set the input file descriptor to specify non-blocking I/O.  The
 * original value of the file descriptor's flags are saved in the
 * location referenced by the saved_flags variable.
 */
int
set_fd_nonblock( int fd )
{
   int st, flags;

   pthread_lock_global_np();
   flags = fcntl( fd, F_GETFL, 0 );
   if( flags < 0 )
   {
       pthread_unlock_global_np();
       return( NOTOK );
   }

   st = fcntl( fd, F_SETFL, (flags |= O_NONBLOCK) );

   pthread_unlock_global_np();
   return( st );
}

int
clear_fd_nonblock( int fd )
{
   int st, flags;

   pthread_lock_global_np();
   flags = fcntl( fd, F_GETFL, 0 );
   if( flags < 0 )
   {
       pthread_unlock_global_np();
       return( NOTOK );
   }

   st = fcntl( fd, F_SETFL, (flags &= ~O_NONBLOCK) );

   pthread_unlock_global_np();
   return( st );
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.