1995-08-09 08:06:35 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Objective Caml */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* */
|
|
|
|
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* Automatique. Distributed only by permission. */
|
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
1995-05-08 08:18:32 -07:00
|
|
|
#include <mlvalues.h>
|
1996-09-04 07:15:31 -07:00
|
|
|
#include "unixsupport.h"
|
1996-04-12 08:57:28 -07:00
|
|
|
#ifdef HAS_UNISTD
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <fcntl.h>
|
1995-05-08 08:18:32 -07:00
|
|
|
|
1996-04-12 08:57:28 -07:00
|
|
|
#ifndef O_NONBLOCK
|
|
|
|
#define O_NONBLOCK O_NDELAY
|
|
|
|
#endif
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value unix_set_nonblock(value fd)
|
1996-04-12 08:57:28 -07:00
|
|
|
{
|
|
|
|
int retcode;
|
|
|
|
retcode = fcntl(Int_val(fd), F_GETFL, 0);
|
|
|
|
if (retcode == -1 ||
|
|
|
|
fcntl(Int_val(fd), F_SETFL, retcode | O_NONBLOCK) == -1)
|
|
|
|
uerror("set_nonblock", Nothing);
|
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value unix_clear_nonblock(value fd)
|
1996-04-12 08:57:28 -07:00
|
|
|
{
|
|
|
|
int retcode;
|
|
|
|
retcode = fcntl(Int_val(fd), F_GETFL, 0);
|
|
|
|
if (retcode == -1 ||
|
|
|
|
fcntl(Int_val(fd), F_SETFL, retcode & ~O_NONBLOCK) == -1)
|
|
|
|
uerror("clear_nonblock", Nothing);
|
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef FD_CLOEXEC
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value unix_set_close_on_exec(value fd)
|
1995-05-08 08:18:32 -07:00
|
|
|
{
|
|
|
|
int retcode;
|
1996-04-12 08:57:28 -07:00
|
|
|
retcode = fcntl(Int_val(fd), F_GETFD, 0);
|
|
|
|
if (retcode == -1 ||
|
|
|
|
fcntl(Int_val(fd), F_SETFD, retcode | FD_CLOEXEC) == -1)
|
|
|
|
uerror("set_close_on_exec", Nothing);
|
|
|
|
return Val_unit;
|
1995-05-08 08:18:32 -07:00
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value unix_clear_close_on_exec(value fd)
|
1995-05-08 08:18:32 -07:00
|
|
|
{
|
|
|
|
int retcode;
|
1996-04-12 08:57:28 -07:00
|
|
|
retcode = fcntl(Int_val(fd), F_GETFD, 0);
|
|
|
|
if (retcode == -1 ||
|
|
|
|
fcntl(Int_val(fd), F_SETFD, retcode & ~FD_CLOEXEC) == -1)
|
|
|
|
uerror("clear_close_on_exec", Nothing);
|
|
|
|
return Val_unit;
|
1995-05-08 08:18:32 -07:00
|
|
|
}
|
1996-04-12 08:57:28 -07:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value unix_set_close_on_exec(value fd)
|
1996-04-12 08:57:28 -07:00
|
|
|
{ invalid_argument("set_close_on_exec not implemented"); }
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value unix_clear_close_on_exec(value fd)
|
1996-04-12 08:57:28 -07:00
|
|
|
{ invalid_argument("clear_close_on_exec not implemented"); }
|
|
|
|
|
|
|
|
#endif
|