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 */
|
1999-11-17 10:59:06 -08:00
|
|
|
/* en Automatique. All rights reserved. This file is distributed */
|
|
|
|
/* under the terms of the GNU Library General Public License. */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $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
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim 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;
|
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim 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
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim 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
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim 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
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value unix_set_close_on_exec(value fd)
|
1996-04-12 08:57:28 -07:00
|
|
|
{ invalid_argument("set_close_on_exec not implemented"); }
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim 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
|