use same location as .configured, etc, to store .files-touched
[AROS.git] / compiler / clib / closedir.c
blobd0f9a835486673b368ea7b0e0804a292aa0b9ed6
1 /*
2 Copyright © 1995-2009, The AROS Development Team. All rights reserved.
3 $Id$
5 POSIX function closedir().
6 */
8 #include <proto/dos.h>
9 #include <proto/exec.h>
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include <errno.h>
14 #include "__fdesc.h"
16 /*****************************************************************************
18 NAME */
19 #include <dirent.h>
21 int closedir(
23 /* SYNOPSIS */
24 DIR *dir)
26 /* FUNCTION
27 Closes a directory
29 INPUTS
30 dir - the directory stream pointing to the directory being closed
32 RESULT
33 The closedir() function returns 0 on success or -1 on
34 failure.
36 NOTES
38 EXAMPLE
40 BUGS
42 SEE ALSO
43 close(), opendir(), readdir(), rewinddir(), seekdir(),
44 telldir(), scandir()
46 INTERNALS
48 ******************************************************************************/
50 fdesc *desc;
52 if (!dir)
54 errno = EFAULT;
55 return -1;
58 desc = __getfdesc(dir->fd);
59 if (!desc)
61 errno = EBADF;
62 return -1;
65 if (--desc->fcb->opencount == 0)
67 UnLock(desc->fcb->fh);
68 FreeVec(desc->fcb);
70 __free_fdesc(desc);
71 __setfdesc(dir->fd, NULL);
73 FreeDosObject(DOS_FIB, dir->priv);
74 free(dir);
76 return 0;