source: trunk/minix/lib/posix/_dup2.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 561 bytes
Line 
1#include <lib.h>
2#define close _close
3#define dup2 _dup2
4#define fcntl _fcntl
5#include <fcntl.h>
6#include <unistd.h>
7
8PUBLIC int dup2(fd, fd2)
9int fd, fd2;
10{
11/* The behavior of dup2 is defined by POSIX in 6.2.1.2 as almost, but not
12 * quite the same as fcntl.
13 */
14
15 if (fd2 < 0 || fd2 > OPEN_MAX) {
16 errno = EBADF;
17 return(-1);
18 }
19
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));
29 }
30}
Note: See TracBrowser for help on using the repository browser.