DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

defopen(S-osr5)


defopen, defread, defcntl -- reads default entries

Syntax

cc . . . -lc

#include <prototypes.h>

int defopen(filename) char *filename;

char *defread(pattern) char *pattern;

int defcntl(int req, int arg)

Description

These routines allow easy access to default definition files. The UNIX operating system is normally distributed in binary form; the use of default files allows OEMs or site administrators to customize utility defaults without having the source code.

defopen( ) opens the default file named by the pathname in filename. defopen( ) returns null if it is successful in opening the file, or the fopen failure code (errno) if the open fails.

defread( ) reads the previously opened file from the beginning until it encounters a line beginning with pattern. defread( ) then returns a pointer to the first character in the line after the initial pattern. If a trailing newline character is read it is replaced by a null byte.

defcntl( ) gets or sets the flags controlling how the defread( ) operation works. req can be set to either of the following:


DC_GETFLAGS (0)
Return current value of flags; ignore arg.

DC_SETFLAGS (1)
Set the current flags to the value of arg. The only flag currently used is DC_CASE (01) which, if set, specifies that the pattern is interpreted as case sensitive; otherwise, case is ignored, so that ``USER'', ``user,'' and ``User'' are all identical.

The return value is the previous value of the flags. Note that these flags are defined internally and not in a header file.

When all items of interest have been extracted from the opened file the program may call defopen with the name of another file to be searched, or it may call defopen with NULL, which closes the default file without opening another.

Files

The UNIX style convention is for a system program xyz to store its defaults (if any) in the file /etc/default/xyz.

Diagnostics

defopen( ) returns zero on success and nonzero if the open fails. The return value is the errno value set by fopen(S-osr5).

defread( ) returns NULL if a default file is not open, if the indicated pattern could not be found, or if it encounters any line in the file greater than the maximum length of 128 characters.

defcntl( ) returns the previous value of flags on success, or -1 on error.

Notes

The return value points to static data, whose contents are overwritten by each call.

See also

fopen(S-osr5)

Standards conformance

defopen( ), defread( ), and defcntl( ) are extensions of AT&T System V provided by the Santa Cruz Operation.
© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005