tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / workbench / network / stacks / AROSTCP / netlib / _dup2.c
blob88327513070bbab20509947764682810a6dd0efe
1 /* $Id$
3 * _dup2.c - duplicate a file descriptor (SAS/C)
5 * Copyright © 1994 AmiTCP/IP Group,
6 * Network Solutions Development Inc.
7 * All rights reserved.
8 */
10 #include <ios1.h>
11 #include <fcntl.h>
12 #include <stdlib.h>
13 #include <dos.h>
14 #define USE_BUILTIN_MATH
15 #include <string.h>
16 #include <errno.h>
17 #include <dos/dos.h>
18 #include <proto/dos.h>
20 #include <bsdsocket.h>
22 /****** net.lib/dup2 **********************************************************
23 SEE ALSO
24 dup()
25 *******************************************************************************
29 int
30 __dup2(int old_fd, int new_fd)
32 struct UFB *ufb;
33 int ufbflg;
36 * Check if there is nothing to do
38 if (old_fd == new_fd)
39 return old_fd;
42 * Check for the break signals
44 __chkabort();
46 __close(new_fd);
49 * Find the ufb * for the old FD
51 if ((ufb = __chkufb(old_fd)) == NULL) {
52 errno = EBADF;
53 return -1;
56 ufbflg = ufb->ufbflg;
58 /*
59 * The brain dead UFB system won't allow duplicating ordinary files
61 if ((ufbflg & UFB_SOCK) == UFB_SOCK) {
62 return Dup2Socket(old_fd, new_fd);
63 } else {
64 errno = EBADF;
65 return -1;