home *** CD-ROM | disk | FTP | other *** search
-
- This code implements the Berkeley Unix "readdir" package. Readdir is an
- abstract interface for reading entries out of directories, and getting the
- names of the files (and directories, etc.) contained therein. Versions
- exist for all Unix systems, MS-DOS, Amiga, and no doubt others as well.
-
- This code was written by Rich $alz, <rsalz@bbn.com> in August, 1990, and
- has no copyright.
-
- #include <dirent.h>
- This header file must be included by any files that use any of the routines
- described here. You must also #include <descrip.h> first.
-
- DIR *
- opendir(name)
- char *name;
- NAME is a filespec that names a directory. It does not have to be in
- strict canonical form -- logicals such as "sys$login:" will be expanded.
- Once the directory has been opened, any of the other routines described
- here can be used on the handle that is returned.
-
-
- void
- vmsreaddirversions(dd, flag)
- DIR *dd;
- int flag;
- By default, READDIR() ignores file versions, and returns a file name once,
- no matter how many versions it has. This routine can be used to collect
- the version numbers in an that is returned with each file. The FLAG
- argument should be non-zero to collect version information, or zero to
- ignore it. This routine can be called any number of times while the
- directory is open.
-
-
- void
- closedir(dd)
- DIR *dd;
- Once you are finished reading the contents of a directory, the CLOSEDIR()
- routine frees up all the storage associated with it, and invalidates the
- handle.
-
-
- struct dirent *
- readdir(dd)
- DIR *dd;
- The READDIR() routine takes a handle returned by OPENDIR() and returns the
- name of the next file in the directory, or a NULL pointer when there are
- no more files. The STRUCT DIRENT returned by this routine will have the
- following fields that may be accessed by user code:
- d_name[] A C character string with the file name
- vms_verscount The number of versions the file has
- vms_versions[] An array of the version numbers; the number -1
- indicates a file-parsing error.
- Note that the fields starting with "vms_" are not part of the standard
- READDIR() library available on other systems, so strictly portable code
- should take care to avoid using them except on VMS machines.
-
- long
- telldir(dd)
- DIR *dd;
- This routine returns a "magic cookie" that can be used in a later
- SEEKDIR() call. This allows you to remember one or more spots while
- reading through a directory and return to them later.
-
-
- void
- seekdir(dd, pos)
- DIR *dd;
- long pos;
- The SEEKDIR() routine takes the "cookie" returned by a previous call to
- TELLDIR() and sets the internal state so that the next READDIR() call will
- return the file read just after the TELLDIR() call.
-
- void
- rewinddir(dd)
- DIR *dd;
- The REWINDDIR() routine resets the internal state of the DD handle so that
- READDIR() starts reading over from the beginning of the directory.
-
- Here is a sample routine showing how to use the package:
- main()
- {
- DIR *dd;
- struct dirent *dp;
- int i;
-
- if ((dd = opendir("sys$login")) == NULL) {
- perror(buff);
- continue;
- }
- vmsreaddirversions(dd, 1);
-
- while (dp = readdir(dd)) {
- printf("%s", dp->d_name);
- for (i = 0; i < dp->vms_verscount; i++)
- printf(" %d", dp->vms_versions[i]);
- printf("\n");
- }
- closedir(dd);
- exit(0);
- }
-