Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / network / stacks / AROSTCP / netlib / fhopen.c
blob86271c14e9606a57b32279af2679544a21607d66
1 /* $Id$
3 * fhopen.c - open level 1 file from an AmigaDOS file handle (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 #include <string.h>
15 #include <errno.h>
16 #include <dos/dos.h>
17 #include <proto/dos.h>
19 #include <bsdsocket.h>
21 extern int (*__closefunc)(int);
23 int
24 fhopen(long file, int mode)
26 struct UFB *ufb;
27 int fd;
28 int flags;
31 * Set up __closefunc (which is used at cleanup)
33 __closefunc = __close;
35 * Check for the break signals
37 __chkabort();
39 * find first free ufb
41 ufb = __allocufb(&fd);
42 if (ufb == NULL)
43 return -1; /* errno is set by the __allocufb() */
46 * Translate mode to ufb flags
48 switch (mode & (O_WRONLY | O_RDWR)) {
49 case O_RDONLY:
50 if (mode & (O_APPEND | O_CREAT | O_TRUNC | O_EXCL)) {
51 errno = EINVAL;
52 return -1;
54 flags = UFB_RA;
55 break;
56 case O_WRONLY:
57 flags = UFB_WA;
58 break;
59 case O_RDWR:
60 flags = UFB_RA | UFB_WA;
61 break;
62 default:
63 errno = EINVAL;
64 return -1;
66 if (mode & O_APPEND)
67 flags |= UFB_APP;
68 if (mode & O_XLATE)
69 flags |= UFB_XLAT;
71 * All done!
73 ufb->ufbflg = flags;
74 ufb->ufbfh = (long)file;
75 ufb->ufbfn = NULL;
77 #if 0
78 if (Dup2Socket(-1, fd) < 0) /* mark the fd as used in the AmiTCP's dTable */
79 perror("Dup2Socket failed on " __FILE__);
80 #endif
82 return fd;