Pristine Ack-5.5
[Ack-5.5.git] / lang / cem / libcc.ansi / misc / closedir.c
1 /*
2         closedir -- close a directory stream
3
4         last edit:      11-Nov-1988     D A Gwyn
5 */
6
7 #include        <errno.h>
8 #include        <stdlib.h>
9 #include        <sys/errno.h>
10 #include        <sys/types.h>
11 #include        <dirent.h>
12
13 typedef void    *pointer;               /* (void *) if you have it */
14
15 #ifndef NULL
16 #define NULL    0
17 #endif
18
19 int _close(int d);
20
21 int
22 closedir(register DIR *dirp)            /* stream from opendir */
23 {
24         register int    fd;
25
26         if ( dirp == NULL || dirp->dd_buf == NULL )
27                 {
28                 errno = EFAULT;
29                 return -1;              /* invalid pointer */
30                 }
31
32         fd = dirp->dd_fd;               /* bug fix thanks to R. Salz */
33         free( (pointer)dirp->dd_buf );
34         free( (pointer)dirp );
35         return _close( fd );
36 }