SCCS-vsn: lib/libc/gen/closedir.c 5.7
SCCS-vsn: lib/libc/gen/directory.3 6.5
*/
#if defined(LIBC_SCCS) && !defined(lint)
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)closedir.c 5.6 (Berkeley) %G%";
+static char sccsid[] = "@(#)closedir.c 5.7 (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
#endif /* LIBC_SCCS and not lint */
#include <dirent.h>
/*
* close a directory.
*/
#include <dirent.h>
/*
* close a directory.
*/
closedir(dirp)
register DIR *dirp;
{
closedir(dirp)
register DIR *dirp;
{
dirp->dd_fd = -1;
dirp->dd_loc = 0;
dirp->dd_fd = -1;
dirp->dd_loc = 0;
- free(dirp->dd_buf);
- free((caddr_t)dirp);
+ (void)free((void *)dirp->dd_buf);
+ (void)free((void *)dirp);
+ return(close(fd));
.\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
.\" WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
.\"
.\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
.\" WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
.\"
-.\" @(#)directory.3 6.4 (Berkeley) %G%
+.\" @(#)directory.3 6.5 (Berkeley) %G%
.\"
.TH DIRECTORY 3 ""
.UC 5
.SH NAME
opendir, readdir, telldir, seekdir, rewinddir, closedir, dirfd \- directory operations
.SH SYNOPSIS
.\"
.TH DIRECTORY 3 ""
.UC 5
.SH NAME
opendir, readdir, telldir, seekdir, rewinddir, closedir, dirfd \- directory operations
.SH SYNOPSIS
-.B #include <sys/types.h>
-.br
-.B #include <sys/dir.h>
-.PP
-.SM
-.B DIR
-.B *opendir(filename)
-.br
-.B char *filename;
-.PP
-.B struct direct
-.B *readdir(dirp)
-.br
-.SM
-.B DIR
-.B *dirp;
-.PP
-.B long
-.B telldir(dirp)
-.br
-.SM
-.B DIR
-.B *dirp;
-.PP
-.B seekdir(dirp, loc)
-.br
-.SM
-.B DIR
-.B *dirp;
-.br
-.B long loc;
-.PP
-.B rewinddir(dirp)
-.br
-.SM
-.B DIR
-.B *dirp;
-.PP
-.B closedir(dirp)
-.br
-.SM
-.B DIR
-.B *dirp;
-.PP
-.B dirfd(dirp)
-.br
-.SM
-.B DIR
-.B *dirp;
+.nf
+.ft B
+#include <sys/types.h>
+#include <dirent.h>
+
+DIR *
+opendir(const char *filename);
+
+struct direct
+*readdir(DIR * dirp);
+
+long
+telldir(const DIR *dirp);
+
+void
+seekdir(DIR *dirp, long loc);
+
+void
+rewinddir(DIR *dirp);
+
+int
+closedir(DIR *dirp);
+
+int
+dirfd(DIR *dirp)
+.ft R
+.fi
.SH DESCRIPTION
.I Opendir
opens the directory named by
.SH DESCRIPTION
.I Opendir
opens the directory named by
.I Closedir
closes the named
.I directory stream
.I Closedir
closes the named
.I directory stream
-and frees the structure associated with the DIR pointer.
+and frees the structure associated with the DIR pointer,
+returning 0 on success.
+On failure, -1 is returned and errno is set to indicate the error.
.PP
.I Dirfd
returns the integer file descriptor associated with the named
.PP
.I Dirfd
returns the integer file descriptor associated with the named
.PP
Sample code which searchs a directory for entry ``name'' is:
.PP
.PP
Sample code which searchs a directory for entry ``name'' is:
.PP
-.br
- len = strlen(name);
-.br
- dirp = opendir(".");
-.br
- for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
-.br
- if (dp->d_namlen == len && !strcmp(dp->d_name, name)) {
-.br
- closedir(dirp);
-.br
- return FOUND;
-.br
- }
-.br
- closedir(dirp);
-.br
- return NOT_FOUND;
+.nf
+.RS
+len = strlen(name);
+dirp = opendir(".");
+for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
+ if (dp->d_namlen == len && !strcmp(dp->d_name, name)) {
+ (void)closedir(dirp);
+ return FOUND;
+ }
+(void)closedir(dirp);
+return NOT_FOUND;
+.RE
+.fi
-open(2),
-close(2),
-read(2),
-lseek(2),
-dir(5)
+open(2), close(2), read(2), lseek(2), dir(5)