Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / network / stacks / AROSTCP / netlib / _close.c
blob395189b82f95b97a21f18d2e1f82000a23955c92
1 /* $Id$
3 * _close.c - close a file (SAS/C)
5 * Copyright © 1994 AmiTCP/IP Group,
6 * Network Solutions Development Inc.
7 * All rights reserved.
8 */
10 #include <ios1.h>
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <dos.h>
14 #include <proto/dos.h>
15 #include <errno.h>
16 #include <bsdsocket.h>
18 int
19 __close(int fd)
21 struct UFB *ufb;
24 * Check for the break signals
26 __chkabort();
29 * Find the ufb *
31 if ((ufb = __chkufb(fd)) == NULL) {
32 /* __chkufb sets the errno to EBADF */
33 return -1;
37 * Check if close is not needed
39 if ((ufb->ufbflg & (UFB_NC | UFB_CLO)) != UFB_NC) {
42 * Empty flags mean empty ufb
44 if (ufb->ufbflg == 0) {
45 errno = EBADF;
46 return -1;
50 * Close the file
52 if (!(ufb->ufbflg & UFB_SOCK) && ufb->ufbfh != NULL) {
53 Close(ufb->ufbfh);
56 * Remove the file if it was temporary
58 if (ufb->ufbflg & UFB_TEMP && ufb->ufbfn != NULL)
59 remove(ufb->ufbfn);
65 * Free the file name
67 if (ufb->ufbfn != NULL) {
68 free(ufb->ufbfn);
69 ufb->ufbfn = NULL;
73 * Clear the flags to free this ufb
75 ufb->ufbflg = 0;
76 ufb->ufbfh = NULL; /* just in case */
78 /*
79 * closes the socket OR the file mark
81 CloseSocket(fd);
83 return 0;