3 * _open.c - Unix compatible open() (SAS/C)
5 * Copyright © 1994 AmiTCP/IP Group,
6 * Network Solutions Development Inc.
17 #include <proto/dos.h>
18 #include <proto/usergroup.h>
22 #include <bsdsocket.h>
26 extern int (*__closefunc
)(int);
29 __open(const char *name
, int mode
, ...)
38 * Set up __closefunc (which is used at cleanup)
40 __closefunc
= __close
;
43 * Check for the break signals
50 ufb
= __allocufb(&fd
);
52 return -1; /* errno is set by the __allocufb() */
55 * malloc space for the name & copy it
57 if ((ufb
->ufbfn
= malloc(strlen(name
)+1)) == NULL
) {
58 SET_OSERR(ERROR_NO_FREE_STORE
);
62 strcpy(ufb
->ufbfn
, name
);
64 * Translate mode to ufb flags
66 switch (mode
& (O_WRONLY
| O_RDWR
)) {
68 if (mode
& (O_APPEND
| O_CREAT
| O_TRUNC
| O_EXCL
)) {
78 flags
= UFB_RA
| UFB_WA
;
92 if (lock
= Lock((char *)name
, SHARED_LOCK
)) {
108 if (mode
& O_CREAT
) {
109 if ((file
= Open((char *)name
, MODE_NEWFILE
)) == NULL
)
118 cmode
= va_arg(va
, int) & ~getumask();
120 chmod((char *)name
, cmode
); /* hope this doesn't fail :-) */
124 if ((file
= Open((char *)name
,
125 (flags
& UFB_WA
&& mode
& O_LOCK
) ?
126 MODE_READWRITE
: MODE_OLDFILE
)) == NULL
)
131 * All done! Setting the ufb->ufbflg field to non-zero value marks
135 ufb
->ufbfh
= (long)file
;