aboutsummaryrefslogtreecommitdiffstats
path: root/usr/kinit/open.c
blob: a430ea96c6fea5028f7f6ede447438d1d589b8e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
 * open.c
 *
 * A quick hack to do an open() and set the cloexec flag
 */

#include <unistd.h>
#include <fcntl.h>

int open_cloexec(const char *path, int flags, mode_t mode)
{
  int fd = open(path, flags, mode);
  
  if ( fd >= 0 )
    fcntl(fd, F_SETFD, FD_CLOEXEC);

  return fd;
}