Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ telldir(3X) — DG/UX 4.00

Media Vault

Software Library

Restoration Projects

Artifacts Sought



                                                            directory(3X)



        _________________________________________________________________
        directory: opendir, readdir, telldir, seekdir,         Subroutine
        rewinddir, closedir
        directory operations
        _________________________________________________________________


        SYNTAX

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

        DIR *opendir (filename)
        char *filename;

        struct dirent *readdir (dirp)
        DIR *dirp;

        long telldir (dirp)
        DIR *dirp;

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

        void rewinddir (dirp)
        DIR *dirp;

        int closedir(dirp)
        DIR *dirp;


           Alternate Syntax

        #include <sys/dir.h>
        struct direct *readdir (dirp)
        DIR *dirp;
        (All other function interfaces remain the same.)


        DESCRIPTION

        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 operations.  The
        pointer NULL is returned if filename cannot be accessed or is not
        a directory, or if it cannot allocate enough memory to hold a DIR
        structure or a buffer for the directory entries.

        Readdir returns a pointer to the next active directory entry.  No
        inactive entries are returned.  It returns NULL upon reaching the



        DG/UX 4.00                                                 Page 1
               Licensed material--property of copyright holder(s)





                                                            directory(3X)



        end of the directory or upon detecting an invalid location in the
        directory.

        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 operation from which
        loc was obtained was performed.  Values returned by telldir are
        good only if the directory has not changed due to compaction or
        expansion.  This is not a problem with System V, but it can be
        with DG/UX and some file system types.

        Rewinddir resets the position of the named directory stream to
        the beginning of the directory.

        Closedir closes the named directory stream and frees the DIR
        structure.

        The following errors can occur as a result of these operations.

        opendir:

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

        [EACCES]       A component of filename denies search permission.

        [EMFILE]       The maximum number of file descriptors are
                       currently open.

        [EFAULT]       Filename points outside the allocated address
                       space.


        readdir:

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

        [EBADF]        The file descriptor determined by the DIR stream
                       is no longer valid.  This results if the DIR
                       stream has been closed.


        telldir, seekdir, and closedir:

        [EBADF]        The file descriptor determined by the DIR stream
                       is no longer valid.  This results if the DIR
                       stream has been closed.




        DG/UX 4.00                                                 Page 2
               Licensed material--property of copyright holder(s)





                                                            directory(3X)



        EXAMPLE

        Sample code which searches a directory for entry name:

             dirp = opendir( "." );
             while ( (dp = readdir( dirp )) != NULL )
                  if ( strcmp( dp->dname, name ) == 0 )
                       {
                       closedir( dirp );
                       return FOUND;
                       }
             closedir( dirp );
             return NOTFOUND;



        SEE ALSO

        getdents(2), dirent(4).


        WARNINGS

        Rewinddir is implemented as a macro, so its function address
        cannot be taken.





























        DG/UX 4.00                                                 Page 3
               Licensed material--property of copyright holder(s)



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