Annotation of cci/usr/src/man/man3/directory.3, revision 1.1.1.1

1.1       root        1: .TH DIRECTORY 3 "25 February 1983"
                      2: .UC 4
                      3: .SH NAME
                      4: opendir, readdir, telldir, seekdir, rewinddir, closedir \- directory operations
                      5: .SH SYNOPSIS
                      6: .B #include <sys/dir.h>
                      7: .PP
                      8: .SM
                      9: .B DIR
                     10: .B *opendir(filename)
                     11: .br
                     12: .B char *filename;
                     13: .PP
                     14: .B struct direct
                     15: .B *readdir(dirp)
                     16: .br
                     17: .SM
                     18: .B DIR
                     19: .B *dirp;
                     20: .PP
                     21: .B long
                     22: .B telldir(dirp)
                     23: .br
                     24: .SM
                     25: .B DIR
                     26: .B *dirp;
                     27: .PP
                     28: .B seekdir(dirp, loc)
                     29: .br
                     30: .SM
                     31: .B DIR
                     32: .B *dirp;
                     33: .br
                     34: .B long loc;
                     35: .PP
                     36: .B rewinddir(dirp)
                     37: .br
                     38: .SM
                     39: .B DIR
                     40: .B *dirp;
                     41: .PP
                     42: .B closedir(dirp)
                     43: .br
                     44: .SM
                     45: .B DIR
                     46: .B *dirp;
                     47: .SH DESCRIPTION
                     48: .I Opendir
                     49: opens the directory named by
                     50: .I filename
                     51: and associates a
                     52: .I directory stream
                     53: with it.
                     54: .I Opendir
                     55: returns a pointer to be used to identify the
                     56: .I directory stream
                     57: in subsequent operations.  The pointer
                     58: .SM
                     59: .B NULL
                     60: is returned if
                     61: .I filename
                     62: cannot be accessed, or if it cannot
                     63: .IR malloc (3)
                     64: enough memory to hold the whole thing.
                     65: .PP
                     66: .I Readdir
                     67: returns a pointer to the next directory entry.  It returns
                     68: .B NULL
                     69: upon reaching the end of the directory or detecting an invalid
                     70: .I seekdir
                     71: operation.
                     72: .PP
                     73: .I Telldir
                     74: returns the current location associated with the named
                     75: .I directory stream.
                     76: .PP
                     77: .I Seekdir
                     78: sets the position of the next
                     79: .I readdir
                     80: operation on the
                     81: .I directory stream.
                     82: The new position reverts to the one associated with the
                     83: .I directory stream
                     84: when the
                     85: .I telldir
                     86: operation was performed.  Values returned by
                     87: .I telldir
                     88: are good only for the lifetime of the DIR pointer from which they are derived.
                     89: If the directory is closed and then reopened, the 
                     90: .I telldir
                     91: value may be invalidated due to undetected directory compaction.
                     92: It is safe to use a previous
                     93: .I telldir
                     94: value immediately after a call to
                     95: .I opendir
                     96: and before any calls to
                     97: .I readdir.
                     98: .PP
                     99: .I Rewinddir
                    100: resets the position of the named
                    101: .I directory stream
                    102: to the beginning of the directory.
                    103: .PP
                    104: .I Closedir
                    105: closes the named
                    106: .I directory stream
                    107: and frees the structure associated with the DIR pointer.
                    108: .PP
                    109: Sample code which searchs a directory for entry ``name'' is:
                    110: .PP
                    111: .br
                    112:        len = strlen(name);
                    113: .br
                    114:        dirp = opendir(".");
                    115: .br
                    116:        for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
                    117: .br
                    118:                if (dp->d_namlen == len && !strcmp(dp->d_name, name)) {
                    119: .br
                    120:                        closedir(dirp);
                    121: .br
                    122:                        return FOUND;
                    123: .br
                    124:                }
                    125: .br
                    126:        closedir(dirp);
                    127: .br
                    128:        return NOT_FOUND;
                    129: .SH "SEE ALSO"
                    130: open(2),
                    131: close(2),
                    132: read(2),
                    133: lseek(2),
                    134: dir(5)

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.