Annotation of researchv10dc/man/adm/man3/directory.3, revision 1.1.1.1

1.1       root        1: .TH DIRECTORY 3  
                      2: .CT 2 dirs
                      3: .SH NAME
                      4: opendir, readdir, telldir, seekdir, closedir \(mi directory operations
                      5: .SH SYNOPSIS
                      6: .nf
                      7: .B #include <sys/types.h>
                      8: .B #include <ndir.h>
                      9: .PP
                     10: .B DIR *opendir(filename)
                     11: .B char *filename;
                     12: .PP
                     13: .B struct direct *readdir(dirp)
                     14: .B DIR *dirp;
                     15: .PP
                     16: .B long telldir(dirp)
                     17: .B DIR *dirp;
                     18: .PP
                     19: .B seekdir(dirp, loc)
                     20: .B DIR *dirp;
                     21: .B long loc;
                     22: .PP
                     23: .B closedir(dirp)
                     24: .B DIR *dirp;
                     25: .fi
                     26: .SH DESCRIPTION
                     27: .I Opendir
                     28: opens the directory named by
                     29: .I filename
                     30: and associates a `directory stream'
                     31: with it.
                     32: .I Opendir
                     33: returns a pointer to be used to identify the
                     34: directory stream
                     35: in subsequent operations.
                     36: The pointer value 0
                     37: is returned if
                     38: .I filename
                     39: cannot be accessed or is not a directory.
                     40: .PP
                     41: .I Readdir
                     42: returns a pointer to the next directory entry.
                     43: It returns 0
                     44: upon reaching the end of the directory or detecting
                     45: an invalid
                     46: .I seekdir
                     47: operation.
                     48: .PP
                     49: .I Telldir
                     50: returns the current location associated with the named
                     51: directory stream.
                     52: .PP
                     53: .I Seekdir
                     54: sets the position of the next
                     55: .I readdir
                     56: operation on the
                     57: directory stream.
                     58: The new position reverts to the one associated with the
                     59: directory stream
                     60: when the
                     61: .I telldir
                     62: operation was performed.
                     63: Values returned by
                     64: .I telldir
                     65: are good only for the lifetime of the 
                     66: .B DIR
                     67: pointer from
                     68: which they are derived.
                     69: .PP
                     70: .I Closedir
                     71: causes the named
                     72: directory stream
                     73: to be closed,
                     74: and the structure associated with the 
                     75: .B DIR
                     76: pointer to be freed.
                     77: .LP
                     78: .nf
                     79: .ftL
                     80: .ta \w'struct\ 'u +\w'direct\ 'u +\w'd_name[MAXNAMLEN+1];\ 'u
                     81: struct direct  {
                     82:        \fLu_long       d_ino;\fR       inode for the entry
                     83:        \fLshort        d_reclen;\fP    don't use
                     84:        \fLshort        d_namlen;\fP    equivalent to \fLstrlen(d_name)\fP
                     85:        \fLchar d_name[MAXNAMLEN+1];\fP null-terminated entry name
                     86: \fL};\fR
                     87: .fi
                     88: .PP
                     89: The preferred way to search the current directory is:
                     90: .ft L
                     91: .nf
                     92: .ta 8n +8n +8n +8n
                     93:        DIR *dirp;
                     94:        dirp = opendir(".");
                     95:        for(dp = readdir(dirp); dp != 0; dp = readdir(dir))
                     96:                if(strcmp(dp->d_name, name) == 0)
                     97:                        break;
                     98:        closedir(dirp);
                     99:        /* found name if dp != 0 */
                    100: .fi
                    101: .ft P
                    102: .SH "SEE ALSO"
                    103: .IR dir (5),
                    104: .IR open (2),
                    105: .IR dirread (2),
                    106: .IR read (2),
                    107: .IR lseek (2),
                    108: .IR ftw (3)
                    109: .SH BUGS
                    110: The return values point to static data whose content is overwritten by each call.

unix.superglobalmegacorp.com

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