closedir now returns value (POSIX); some manual page restructuring
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Sat, 26 May 1990 08:54:44 +0000 (00:54 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Sat, 26 May 1990 08:54:44 +0000 (00:54 -0800)
SCCS-vsn: lib/libc/gen/closedir.c 5.7
SCCS-vsn: lib/libc/gen/directory.3 6.5

usr/src/lib/libc/gen/closedir.c
usr/src/lib/libc/gen/directory.3

index 1b4d67d..43d54b3 100644 (file)
  */
 
 #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 <sys/param.h>
+#include <sys/types.h>
 #include <dirent.h>
 
 /*
  * close a directory.
  */
 #include <dirent.h>
 
 /*
  * close a directory.
  */
-void
 closedir(dirp)
        register DIR *dirp;
 {
 closedir(dirp)
        register DIR *dirp;
 {
+       int fd;
 
 
-       close(dirp->dd_fd);
+       fd = dirp->dd_fd;
        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));
 }
 }
index 2c7e4e4..7e5ecd2 100644 (file)
 .\" 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
@@ -129,7 +107,9 @@ to the beginning of the directory.
 .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
@@ -138,27 +118,18 @@ see open(2).
 .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
 .SH "SEE ALSO"
 .SH "SEE ALSO"
-open(2),
-close(2),
-read(2),
-lseek(2),
-dir(5)
+open(2), close(2), read(2), lseek(2), dir(5)