Add lwevent_cloexec()

This commit is contained in:
Laurence Withers 2007-10-27 13:34:14 +00:00
parent dfb8feedfd
commit e617f1b835
2 changed files with 33 additions and 0 deletions

View File

@ -26,6 +26,25 @@ int lwevent_nonblock(int fd)
/* lwevent_cloexec()
* Uses fcntl(2) to set FD_CLOEXEC for `fd'. No-op if it is already set. Does not affect any other
* file status flags.
*/
int lwevent_cloexec(int fd)
{
long flags;
flags = TEMP_FAILURE_RETRY( fcntl(fd, F_GETFD) );
if(flags == -1) return -1;
if(flags & FD_CLOEXEC) return 0;
flags |= FD_CLOEXEC;
return TEMP_FAILURE_RETRY( fcntl(fd, F_SETFD, flags) );
}
/* options for text editors /* options for text editors
kate: replace-trailing-space-save true; space-indent true; tab-width 4; kate: replace-trailing-space-save true; space-indent true; tab-width 4;
vim: expandtab:ts=4:sw=4 vim: expandtab:ts=4:sw=4

View File

@ -30,6 +30,20 @@ int lwevent_nonblock(int fd) __attribute__((warn_unused_result));
/*! \brief Set file descriptor to close on exec().
\param fd File descriptor.
\retval 0 on success.
\retval -1 on error (and see \a errno).
This function is provided to switch the file descriptor \a fd into close-on-exec mode using
\c fcntl(2).
*/
int lwevent_cloexec(int fd) __attribute__((warn_unused_result));
/*!@}*/ /*!@}*/
/* options for text editors /* options for text editors
kate: replace-trailing-space-save true; space-indent true; tab-width 4; kate: replace-trailing-space-save true; space-indent true; tab-width 4;