. pci driver now returns devices, even when they have been pci_reserve()d
[minix3.git] / lib / posix / _dup2.c
blobe630a51d5439fe9cb33afb96e1275953cc6adc24
1 #include <lib.h>
2 #define close _close
3 #define dup2 _dup2
4 #define fcntl _fcntl
5 #include <fcntl.h>
6 #include <unistd.h>
8 PUBLIC int dup2(fd, fd2)
9 int fd, fd2;
11 /* The behavior of dup2 is defined by POSIX in 6.2.1.2 as almost, but not
12 * quite the same as fcntl.
15 if (fd2 < 0 || fd2 > OPEN_MAX) {
16 errno = EBADF;
17 return(-1);
20 /* Check to see if fildes is valid. */
21 if (fcntl(fd, F_GETFL) < 0) {
22 /* 'fd' is not valid. */
23 return(-1);
24 } else {
25 /* 'fd' is valid. */
26 if (fd == fd2) return(fd2);
27 close(fd2);
28 return(fcntl(fd, F_DUPFD, fd2));