Keep the posix module buildable, and add some CVS sugar for easier scanning.
[reactos.git] / posix / lib / psxdll / unistd / dup.c
1 /* $Id: dup.c,v 1.4 2002/10/29 04:45:46 rex Exp $
2 */
3 /*
4 * COPYRIGHT: See COPYING in the top level directory
5 * PROJECT: ReactOS POSIX+ Subsystem
6 * FILE: subsys/psx/lib/psxdll/unistd/dup.c
7 * PURPOSE: Duplicate an open file descriptor
8 * PROGRAMMER: KJK::Hyperion <noog@libero.it>
9 * UPDATE HISTORY:
10 * 13/02/2002: Created
11 */
12
13 #include <unistd.h>
14 #include <limits.h>
15 #include <errno.h>
16 #include <fcntl.h>
17
18 int dup(int fildes)
19 {
20 return (fcntl(fildes, F_DUPFD, 0));
21 }
22
23 int dup2(int fildes, int fildes2)
24 {
25 if(fildes < 0 || fildes >= OPEN_MAX)
26 {
27 errno = EBADF;
28 return (-1);
29 }
30
31 /* TODO: check if fildes is valid */
32
33 if(fildes == fildes2)
34 return fildes2;
35
36 close(fildes2);
37 return (fcntl(fildes, F_DUPFD, fildes2));
38 }
39
40 /* EOF */
41