summaryrefslogtreecommitdiff
path: root/src/libstddjb/open3.c
blob: a9ff9e6c4337197940114b3995dba66f1ea3eaac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* ISC license. */

#include <skalibs/sysdeps.h>
#include <skalibs/nonposix.h>

#include <sys/stat.h>
#include <errno.h>

#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>

#ifdef SKALIBS_HASOCLOEXEC

int open3 (char const *s, unsigned int flags, unsigned int mode)
{
  int r ;
  do r = open(s, flags, mode) ;
  while (r == -1 && errno == EINTR) ;
  return r ;
}

#else

int open3 (char const *s, unsigned int flags, unsigned int mode)
{
  int fd ;
  do fd = open(s, flags & ~O_CLOEXEC, mode) ;
  while (fd == -1 && errno == EINTR) ;
  if (fd == -1) return -1 ;
  if (flags & O_CLOEXEC && coe(fd) == -1)
  {
    fd_close(fd) ;
    return -1 ;
  }
  return fd ;
}

#endif