2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
5 POSIX.1-2008 function close().
10 #include <proto/exec.h>
11 #include <proto/dos.h>
15 /*****************************************************************************
26 Closes an open file. If this is the last file descriptor
27 associated with this file, then all allocated resources
31 fd - The result of a successful open()
34 -1 for error or zero on success.
37 This function must not be used in a shared library or
38 in a threaded application.
45 open(), read(), write(), fopen()
49 ******************************************************************************/
53 if (!(fdesc
= __getfdesc(fd
)))
60 if (--fdesc
->fcb
->opencount
== 0)
62 /* Due to a *stupid* behaviour of the dos.library we cannot handle closing failures cleanly :-(
64 !(fdesc->fcb->privflags & _FCB_DONTCLOSE_FH) &&
69 errno = __stdc_ioerr2errno(IoErr());
74 /* FIXME: Damn dos.library! We cannot report the error code correctly! This oughta change someday... */
75 /* Since the dos.library destroys the file handle anyway, even if the closing fails, we cannot
76 report the error code correctly, so just close the file and get out of here */
78 if (!(fdesc
->fcb
->privflags
& _FCB_DONTCLOSE_FH
))
80 // don't close directories because we don't Open() them.
81 if (fdesc
->fcb
->privflags
& _FCB_ISDIR
)
83 UnLock(fdesc
->fcb
->handle
);
87 Close(fdesc
->fcb
->handle
);