1989-12-18 14:40:54 +00:00
|
|
|
/*
|
|
|
|
closedir -- close a directory stream
|
|
|
|
|
|
|
|
last edit: 11-Nov-1988 D A Gwyn
|
|
|
|
*/
|
|
|
|
|
2018-06-21 20:33:47 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <dirent.h>
|
1989-12-18 14:40:54 +00:00
|
|
|
|
2018-06-21 20:33:47 +00:00
|
|
|
typedef void* pointer; /* (void *) if you have it */
|
1989-12-18 14:40:54 +00:00
|
|
|
|
|
|
|
#ifndef NULL
|
2018-06-21 20:33:47 +00:00
|
|
|
#define NULL 0
|
1989-12-18 14:40:54 +00:00
|
|
|
#endif
|
|
|
|
|
1990-01-22 11:44:21 +00:00
|
|
|
int _close(int d);
|
1989-12-18 14:40:54 +00:00
|
|
|
|
2018-06-21 20:33:47 +00:00
|
|
|
int closedir(register DIR* dirp) /* stream from opendir */
|
1989-12-18 14:40:54 +00:00
|
|
|
{
|
2018-06-21 20:33:47 +00:00
|
|
|
register int fd;
|
1989-12-18 14:40:54 +00:00
|
|
|
|
2018-06-21 20:33:47 +00:00
|
|
|
if (dirp == NULL || dirp->dd_buf == NULL)
|
|
|
|
{
|
1989-12-18 14:40:54 +00:00
|
|
|
errno = EFAULT;
|
2018-06-21 20:33:47 +00:00
|
|
|
return -1; /* invalid pointer */
|
|
|
|
}
|
1989-12-18 14:40:54 +00:00
|
|
|
|
2018-06-21 20:33:47 +00:00
|
|
|
fd = dirp->dd_fd; /* bug fix thanks to R. Salz */
|
|
|
|
free((pointer)dirp->dd_buf);
|
|
|
|
free((pointer)dirp);
|
|
|
|
return _close(fd);
|
1989-12-18 14:40:54 +00:00
|
|
|
}
|