Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ directory(3) — AIX PS/2 1.2.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

close, closex

lseek

open, openx, creat

read, readv, readx

scandir

dir



DIRECTORY(3,L)              AIX Technical Reference              DIRECTORY(3,L)



-------------------------------------------------------------------------------
directory: opendir, readdir, telldir, seekdir, rewinddir, closedir



PURPOSE

Performs operations on directories.

LIBRARY

Standard C Library (libc.a)

SYNTAX

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




                DIR *opendir (dirname)      void seekdir (dirp, loc)
                char *dirname;              DIR *dirp;
                                            long loc;
                struct dirent *readdir (dirp)
                DIR *dirp;                  void rewinddir (dirp)
                                            DIR *dirp;
                long telldir (dirp)
                DIR *dirp;                  int closedir (dirp)
                                            DIR *dirp;



DESCRIPTION

The opendir subroutine opens the directory designated by the dirname parameter
and associates a directory stream with it.  The closedir subroutine terminates
a directory stream and closes the underlying file descriptor.

The opendir subroutine returns a pointer to the DIR structure of the directory
stream.  NULL is returned when dirname cannot be accessed, or when not enough
memory is available to hold the whole stream.  If dirname is not a directory,
NULL is returned and errno is set to ENOTDIR.

The readdir subroutine returns a pointer to the next directory entry.  When it
reaches the end of the directory, or when it detects an invalid seekdir
operation, readdir returns NULL.  The telldir subroutine returns the current
location associated with the specified directory stream.

The seekdir subroutine sets the position of the next readdir operation on the
directory stream.




Processed November 7, 1990      DIRECTORY(3,L)                                1





DIRECTORY(3,L)              AIX Technical Reference              DIRECTORY(3,L)



Note:  Values from telldir are valid only for the duration of the opendir
       operation from which the DIR pointer was derived.  If a directory is
       closed and reopened, the position of the directory stream is reset.
       Therefore, if you want to continue reading from the location of the
       directory prior to close, you should save the value of a telldir made
       before closing the directory.  After reopening the directory, use
       seekdir to determine the previous value of telldir.

The rewinddir subroutine resets the position of the specified directory stream
to the beginning of the directory.

A -1 is returned if dirp does not refer to an open directory stream;
otherwise, 0 is returned.

Warning:  It is recommended that these subroutines be used to access a
directory rather than using the open and read system calls.  See ulimit and
read for a description of the special AIX behavior of the read system call on
directories.

EXAMPLES

The following code illustrates a search of a directory for entry name:

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

ERROR CONDITIONS

The opendir, readdir, and closedir subroutines fail if one or more of the
following are true:

EACCES    Search permission is denied for any component of dirname or read
          permission is denied for dirname.

ENAMETOOLONG
          The length of the dirname string exceeds PATH_MAX, or a pathname
          component is longer than NAME_MAX.

ENOENT    The dirname argument points to the name of a file which does not
          exist.

ENOTDIR   A component of dirname is not a directory.

EMFILE    Too many file descriptors are currently open for the process.




Processed November 7, 1990      DIRECTORY(3,L)                                2





DIRECTORY(3,L)              AIX Technical Reference              DIRECTORY(3,L)



ENFILE    Too many files are currently open in the system.

ENOENT    The dirname argument points to an empty string.

EBADF     The dirp argument does not refer to an open directory stream.

RELATED INFORMATION

In this book:  "close, closex,"  "lseek,"  "open, openx, creat," "read, readv,
readx," "scandir," and "dir."













































Processed November 7, 1990      DIRECTORY(3,L)                                3



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026