Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ directory(3C) — HP-UX 6.20

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

close(2)

lseek(2)

open(2)

read(2)

DIRECTORY(3C)  —  HP-UX

NAME

opendir, readdir, telldir, seekdir, rewinddir, closedir − directory operations

SYNOPSIS

#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;

rewinddir(dirp)
DIR ∗dirp;

closedir(dirp)
DIR ∗dirp;

DESCRIPTION

The purpose of this library package is to provide functions that allow programs to read directory entries without having to know the actual directory format associated with the file system.  This allows programs to be ported from one file system to another.  Therefore, this is the recommended way to read directory entries. 

Opendir opens the directory named by filename and associates a directory stream with it.  Opendir returns a pointer that is used to identify the directory stream in subsequent operations.  The pointer NULL is returned if filename cannot be accessed, if filename is not a directory, or if sufficient memory cannot be allocated for a buffer of size DIRBLKSIZ blocks.  The opendir routine allocates memory using malloc(3C) or malloc(3X), depending on which is linked with the program.

Readdir returns a pointer to the next directory entry.  It returns NULL upon reaching the end of the directory or detecting an invalid seekdir operation. 

Telldir returns the current location, in bytes, associated with the named directory stream. 

Seekdir sets the position of the next readdir operation on the directory stream.  Loc is a byte offset within the directory file.  The new position reverts to the one associated with the directory stream when the telldir operation was performed.  Values returned by telldir are good only for the lifetime of the DIR pointer from which they are derived.  If the directory is closed and then re-opened, the telldir value may be invalidated due to undetected directory compaction.  It is safe to use a previous telldir value immediately after a call to opendir and before any calls to readdir. 

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

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

See /usr/include/ndir.h for a description of the fields available in a directory entry.  The preferred way to search the current directory for entry "name" is:

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;

WARNINGS

Readdir is the only way to access remote NFS directories.  Attempting to read a remote directory using read(2) will always return a value of zero. 

AUTHOR

Directory was developed by the University of California, Berkeley. 

FILES

/usr/include/ndir.h

SEE ALSO

close(2), lseek(2), open(2), read(2). 

Hewlett-Packard Company  —  May 11, 2021

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