xref: /original-bsd/lib/libc/gen/closedir.c (revision 62b63144)
1 /*
2  * Copyright (c) 1983, 1993
3  *	Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #if defined(LIBC_SCCS) && !defined(lint)
9 static char sccsid[] = "@(#)closedir.c	8.1 (Berkeley) 06/10/93";
10 #endif /* LIBC_SCCS and not lint */
11 
12 #include <sys/types.h>
13 #include <dirent.h>
14 #include <stdlib.h>
15 #include <unistd.h>
16 
17 /*
18  * close a directory.
19  */
20 int
21 closedir(dirp)
22 	register DIR *dirp;
23 {
24 	int fd;
25 
26 	seekdir(dirp, dirp->dd_rewind);	/* free seekdir storage */
27 	fd = dirp->dd_fd;
28 	dirp->dd_fd = -1;
29 	dirp->dd_loc = 0;
30 	(void)free((void *)dirp->dd_buf);
31 	(void)free((void *)dirp);
32 	return(close(fd));
33 }
34