2 Copyright © 1995-2012, 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>
17 /*****************************************************************************
28 Closes an open file. If this is the last file descriptor
29 associated with this file, then all allocated resources
33 fd - The result of a successful open()
36 -1 for error or zero on success.
39 This function must not be used in a shared library or
40 in a threaded application.
47 open(), read(), write(), fopen()
51 ******************************************************************************/
55 if (!(fdesc
= __getfdesc(fd
)))
62 if (--fdesc
->fcb
->opencount
== 0)
64 /* Due to a *stupid* behaviour of the dos.library we cannot handle closing failures cleanly :-(
66 !(fdesc->fcb->privflags & _FCB_DONTCLOSE_FH) &&
71 errno = __arosc_ioerr2errno(IoErr());
76 /* FIXME: Damn dos.library! We cannot report the error code correctly! This oughta change someday... */
77 /* Since the dos.library destroys the file handle anyway, even if the closing fails, we cannot
78 report the error code correctly, so just close the file and get out of here */
80 if (!(fdesc
->fcb
->privflags
& _FCB_DONTCLOSE_FH
))
82 // don't close directories because we don't Open() them.
83 if (fdesc
->fcb
->isdir
)
85 UnLock(fdesc
->fcb
->fh
);
89 Close(fdesc
->fcb
->fh
);