Oberon || Library || Module Index || Search Engine || Definition || Module


Ulm's Oberon Library:
UnixDirectories


NAME

UnixDirectories - read UNIX directory entries

SYNOPSIS

CONST dirsize = 255; (* BSD file system *)
CONST namelength = dirsize+1;
TYPE FileName = ARRAY namelength OF CHAR;
TYPE Inode = LONGINT;
TYPE Entry =
   RECORD
      inode: Inode;
      name: FileName;
   END;
TYPE Stream = POINTER TO StreamRec;
TYPE StreamRec = RECORD (Streams.StreamRec) END;
PROCEDURE Open(VAR dir: Streams.Stream; dirname: ARRAY OF CHAR;
               errors: RelatedEvents.Object) : BOOLEAN;

DESCRIPTION

UnixDirectories is an interface for reading directory entries. Open opens directory dirname for reading (dirname must be 0X-terminated). The stream is unbuffered and positions in the sense of Streams.Seek and Streams.Tell are not necessarily byte positions. Thus, only positions returned by Streams.Tell are valid parameters of Streams.Seek. Open returns FALSE if dirname cannot be opened or if dirname is not a directory (some implementations check for this). The stream returns records of type Entry.

EXAMPLE

Following example prints all the filenames of the given directory:
PROCEDURE ListFiles(dirname: ARRAY OF CHAR);
   VAR
      dir: Streams.Stream;
      entry: UnixDirectories.Entry;
BEGIN
   IF UnixDirectories.Open(dir, dirname, NIL) THEN
      WHILE Streams.Read(dir, entry) DO
	 Write.Line(entry.name);
      END;
      Streams.Release(dir);
   ELSE
      (* cannot open dirname *)
   END;
END ListFiles;

DIAGNOSTICS

Errors during the access of the stream are converted into events of RelatedEvents. By default, these events are being queued.

During the initialization time, UnixDirectories checks several internal conversion formats of SysConversions against record sizes as computed by the compiler.

SEE ALSO

RelatedEvents
handling of error events
ScanDir
scan directory by use of wildcards
Streams
stream operations

BUGS

Not every implementation of Open checks dirname for being a directory.

The constant dirsize and the field components of Entry with the exception of name depend on the UNIX version.


Edited by: borchert, last change: 2003/07/10, revision: 1.2.2.8, converted to HTML: 2003/07/10

Oberon || Library || Module Index || Search Engine || Definition || Module