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

/**
	@file fd.c
	@autor djb
	@source 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); }