Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

getdents(2)

close(2)

lseek(2)

open(2)

creat(2)

read(2)

opendir(3)

readv(2)

dirent(4)



  opendir(3)                          CLIX                          opendir(3)



  NAME

    opendir, readdir, telldir, seekdir, rewinddir, closedir - Performs
    operations on directories

  LIBRARY

    Standard C Library (libc.a)

  SYNOPSIS

    #include <sys/types.h>

    #include <dirent.h>

    DIR *opendir(
      char *directoryname );

    struct dirent *readdir(
      DIR *directorypointer );

    long telldir(
      DIR *directorypointer );

    void seekdir(
      DIR *directorypointer ,
      long location );

    void rewinddir(
      DIR *directorypointer );

    void closedir(
      DIR *directorypointer );

  PARAMETERS

    directoryname      Names the directory.

    directorypointer   Points to the DIR structure of an open directory.

    location           Specifies the number of an entry, relative to the start
                       of the directory.

  DESCRIPTION

    The opendir() function opens the directory designated by the directoryname
    parameter and associates a directory stream with it.

    An open directory must always be closed with the closedir() function to
    ensure that the next attempt to open that directory is successful.




  2/94 - Intergraph Corporation                                              1






  opendir(3)                          CLIX                          opendir(3)



    The opendir() function also returns a pointer to identify the directory
    stream in subsequent operations.  The NULL pointer is returned when the
    directory named by the directoryname parameter cannot be accessed or when
    not enough memory is available to hold the entire stream.

    The readdir() function returns a pointer to the next directory entry.  The
    readdir() function does not return directory entries containing empty
    names.  If entries for . and .. exist, one entry is returned for . and one
    entry is returned for ..; otherwise, they are not returned.  When it
    reaches the end of the directory, or when it detects an invalid seekdir()
    operation, the readdir() function returns the NULL value.

    The telldir() function returns the current location associated with the
    specified directory stream.

    The seekdir() function sets the position of the next readdir() function
    operation on the directory stream.  The position should be that returned
    by a previous telldir() function call.

    The rewinddir() function resets the position of the specified directory
    stream to the beginning of the directory.

    The closedir() function closes a directory stream and frees the structure
    associated with the directorypointer parameter.

  EXAMPLES

    To search a directory for the name entry:

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


  CAUTIONS

    The rewinddir() function is implemented as a macro.  Thus, its function
    address cannot be taken.

  RETURN VALUES

    The opendir() function returns a pointer to the directory stream or the
    NULL pointer when the directory cannot be accessed or when not enough
    memory is available to hold the entire stream.




  2                                              Intergraph Corporation - 2/94






  opendir(3)                          CLIX                          opendir(3)



    The readdir() function returns a pointer to the next directory entry or
    the NULL value when the end of the directory is reached or an invalid
    seekdir() operation is detected.

    The telldir() function returns the current location associated with the
    specified directory stream.

  ERRORS

    If any of the following conditions occur, the opendir() function will
    return a value of NULL and set errno to the corresponding value:

    [EACCES]
           Search permission is denied for any component of directoryname or
           read permission is denied for directoryname.

    [ENAMETOOLONG]
           The length of the directoryname argument exceeds PATH_MAX, or a
           pathname component is longer than NAME_MAX while _POSIX_NO_TRUNC is
           in effect.

    [ENOENT]
           The named directory does not exist.

    [ENOTDIR]
           A component of directoryname is not a directory.

    [EFAULT]
           The directory name points outside the allocated address space.

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

    If any of the following conditions occur, the readdir() function will
    return a value of NULL and set errno to the corresponding value:

    [ENOENT]   The current file pointer for the directory is not located at a
               valid entry.

    [EBADF]    The directorypointer argument does not refer to an open
               directory stream.

    If any of the following conditions occur, the telldir(), seekdir(), and
    closedir() functions will set errno to the corresponding value:

    [EBADF]   The directorypointer argument does not refer to an open
              directory stream.

  RELATED INFORMATION

    Functions: getdents(2), close(2), lseek(2), open(2), creat(2), read(2),



  2/94 - Intergraph Corporation                                              3






  opendir(3)                          CLIX                          opendir(3)



    readv(2)

    Files: dirent(4)



















































  4                                              Intergraph Corporation - 2/94




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