2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
5 ANSI C function close().
8 #include "__arosc_privdata.h"
12 #include <proto/exec.h>
13 #include <proto/dos.h>
18 /*****************************************************************************
29 Closes an open file. If this is the last file descriptor
30 associated with this file, then all allocated resources
34 fd - The result of a successful open()
37 -1 for error or zero on success.
40 This function must not be used in a shared library or
41 in a threaded application.
48 open(), read(), write(), fopen()
52 ******************************************************************************/
58 if (!(fdesc
= __getfdesc(fd
)))
65 if (--fdesc
->opencount
== 0)
67 /* Due to a *stupid* behaviour of the dos.library we cannot handle closing failures cleanly :-(
69 fdesc->fh!=__stdfiles[STDIN_FILENO] &&
70 fdesc->fh!=__stdfiles[STDOUT_FILENO] &&
71 fdesc->fh!=__stdfiles[STDERR_FILENO] &&
76 errno = IoErr2errno(IoErr());
81 #warning Damn dos.library! We cannot report the error code correctly! This oughta change someday...
82 /* Since the dos.library destroyes the file handle anyway, even if the closing fails, we cannot
83 report the error code correctly, so just close the file and get out of here */
87 fdesc
->fh
!=__stdfiles
[STDIN_FILENO
] &&
88 fdesc
->fh
!=__stdfiles
[STDOUT_FILENO
] &&
89 fdesc
->fh
!=__stdfiles
[STDERR_FILENO
]
92 (void)Close(fdesc
->fh
);