Former-commit-id:133dc97f67
[formerlya02aeb236c
] [formerly9f19e3f712
] [formerly133dc97f67
[formerlya02aeb236c
] [formerly9f19e3f712
] [formerly06a8b51d6d
[formerly9f19e3f712
[formerly 64fa9254b946eae7e61bbc3f513b7c3696c4f54f]]]] Former-commit-id:06a8b51d6d
Former-commit-id:9bb8decbcf
[formerly8e80217e59
] [formerly377dcd10b9
[formerly3360eb6c5f
]] Former-commit-id:377dcd10b9
Former-commit-id:e2ecdcfe33
83 lines
1.6 KiB
C
83 lines
1.6 KiB
C
/*
|
|
* Copyright 1993, University Corporation for Atmospheric Research
|
|
* See ../COPYRIGHT file for copying and redistribution conditions.
|
|
*/
|
|
/* $Id: fdnb.c,v 1.5 2002/12/09 18:23:56 steve Exp $ */
|
|
|
|
#include <ldmconfig.h>
|
|
#include <sys/types.h>
|
|
#include <fcntl.h>
|
|
#include "ulog.h"
|
|
#include "fdnb.h"
|
|
|
|
/* some systems have FNDELAY (== O_NDELAY) different from O_NONBLOCK */
|
|
#if defined(__ultrix) || defined(ultrix)
|
|
/* ultrix 4.3 (and before?) */
|
|
/* #define NB_O_NONBLOCK (FNDELAY | O_NONBLOCK) */
|
|
#define NB_O_NONBLOCK FNDELAY
|
|
#endif
|
|
/* default do like posix sez */
|
|
#ifndef NB_O_NONBLOCK
|
|
#define NB_O_NONBLOCK O_NONBLOCK
|
|
#endif
|
|
/*
|
|
* Set descriptor for non blocking
|
|
* return 1 if changed, 0 otherwise.
|
|
*/
|
|
int
|
|
set_fd_nonblock(int fd)
|
|
{
|
|
unsigned flags = (unsigned)fcntl(fd, F_GETFL, 0);
|
|
|
|
if(flags == (unsigned)-1)
|
|
{
|
|
serror("fcntl(..., F_GETFL,)");
|
|
return 0;
|
|
}
|
|
/* else */
|
|
|
|
if(flags & NB_O_NONBLOCK)
|
|
return 0; /* no change required */
|
|
/* else */
|
|
|
|
flags |= NB_O_NONBLOCK;
|
|
if(fcntl(fd, F_SETFL, (int)flags) == -1)
|
|
{
|
|
serror("fcntl(..., F_SETFL, O_NONBLOCK)");
|
|
return 0;
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
|
|
/*
|
|
* clear descriptor for non blocking
|
|
* (EG, set to blocking)
|
|
* return 1 if changed, 0 otherwise.
|
|
*/
|
|
int
|
|
clr_fd_nonblock(int fd)
|
|
{
|
|
int flags = fcntl(fd, F_GETFL, 0);
|
|
|
|
if(flags == -1)
|
|
{
|
|
serror("fcntl(..., F_GETFL,)");
|
|
return 0;
|
|
}
|
|
/* else */
|
|
|
|
if(!((unsigned int)flags & NB_O_NONBLOCK))
|
|
return 0; /* no change required */
|
|
/* else */
|
|
|
|
flags &= ~NB_O_NONBLOCK;
|
|
if(fcntl(fd, F_SETFL, flags) == -1)
|
|
{
|
|
serror("fcntl(..., F_SETFL, &= ~O_NONBLOCK)");
|
|
return 0;
|
|
}
|
|
|
|
return 1;
|
|
}
|