summaryrefslogtreecommitdiff
path: root/src/fd.c
blob: c3cc0f7f74fe505186429da14791f9796458bee0 (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
#include <fcntl.h>
#include "fd.h"

/**
  * @file fd.c
  * @autor djb
  * @ref qmail
  * @brief file descriptor manipulation
  */

int close(int __fd);  /* we won't use unistd.h here */

int fd_copy(int to,int from)
{
  if (to == from) return 0;
  if (fcntl(from,F_GETFL,0) == -1) return -1;
  close(to);
  if (fcntl(from,F_DUPFD,to) == -1) return -1;
  return 0;
}

int fd_move(int to,int from)
{
  if (to == from) return 0;
  if (fd_copy(to,from) == -1) return -1;
  close(from);
  return 0;
}

int fd_coe(int fd) 
{
  return fcntl(fd,F_SETFD,1); 
}