Modula-2 || Compiler & Tools || Library || Search Engine
TYPE MemberList = POINTER TO Member; TYPE Member = RECORD logname: ARRAY [0..7] OF CHAR; nextmem: MemberList; END; TYPE Grent = RECORD grname: ARRAY [0..7] OF CHAR; password: ARRAY [0..15] OF CHAR; gid: CARDINAL; members: MemberList; END;
PROCEDURE OpenGr(filename: ARRAY OF CHAR): BOOLEAN; PROCEDURE GetGrent(VAR grent: Grent): BOOLEAN; PROCEDURE GetGrgid(gid: CARDINAL; VAR grent: Grent): BOOLEAN; PROCEDURE GetGrnam(grn: ARRAY OF CHAR; VAR grent: Grent): BOOLEAN; PROCEDURE ReopenGr(): BOOLEAN; PROCEDURE CloseGr(): BOOLEAN; PROCEDURE FetchGrgid(gid: CARDINAL; VAR grent: Grent): BOOLEAN; PROCEDURE FetchGrnam(grn: ARRAY OF CHAR; VAR grent: Grent): BOOLEAN;
Between
OpenGr
and
CloseGr,
any (using
GetGrent) or the next entry whose gid cf. grname field matches
gid
cf.
grn
(using
GetGrgid
cf.
GetGrnam) that has not yet been read
will be written into the
grent
record.
At end of file, the
GetXXX
functions return
FALSE
and the data in
grent
is not valid.
ReopenGr
restarts reading the file from the top
if it is seekable,
otherwise reports an error.
Opening the file "/etc/group", searching for a single group ID cf. group name and closing the file again, can all be done at once using FetchGrgid cf. FetchGrnam. This is useful for mapping numerical group IDs to group names, e.g., which is the main purpose of this module.
Modula-2 || Compiler & Tools || Library || Search Engine