man(1) Manual page archive

     DIRECTORY(3)                (3/1/82)                 DIRECTORY(3)

          opendir, readdir, telldir, seekdir, closedir - directory

          #include <sys/types.h>
          #include <ndir.h>

          DIR *opendir(filename)
          char *filename;

          struct direct *readdir(dirp)
          DIR *dirp;

          long telldir(dirp)
          DIR *dirp;

          seekdir(dirp, loc)
          DIR *dirp;
          long loc;

          DIR *dirp;

          Opendir opens the directory named by filename and associates
          a `directory stream' with it.  Opendir returns a pointer to
          be used to identify the directory stream in subsequent oper-
          ations.  The pointer value 0 is returned if filename cananot
          be accessed or is not a directory.

          Readdir returns a pointer to the next directory entry.  It
          returns 0 upon reaching the end of the directory or detect-
          ing an invalid seekdir operation.

          Telldir returns the current location associated with the
          named directory stream.

          Seekdir sets the position of the next readdir operation on
          the directory stream.  The new position reverts to the one
          associated with the directory stream when the telldir opera-
          tion was performed.  Values returned by telldir are good
          only for the lifetime of the DIR pointer from which they are

          Closedir causes the named directory stream to be closed, and
          the structure associated with the DIR pointer to be freed.

          The preferred way to search the current directory is:
               len = strlen(name);

     DIRECTORY(3)                (3/1/82)                 DIRECTORY(3)

               dirp = opendir(".");
               for (dp = readdir(dirp); dp != NULL; dp = readdir(dir))
                    if (dp->d_namlen == len && !strcmp(dp->d_name,
          name)) {
                         return FOUND;
               return NOT_FOUND;

          dir(5), open(2), close(2), read(2), lseek(2)