freebsd-src/lib/libc/gen/config_open.3
Poul-Henning Kamp 2a7b3781fc Added routines to read the canonical UNIX configuration file. This will
later be applied to a number of programs (inetd for instance) to clean
out the bogus code doing the same thing, modulus all the bugs.

If you need to read a '#'-is-a-comment-file, please use these routines.

I realize that the shlib# should be bumped (for the non-US world:
increased by something), but will defer this until something significant
happens.
1994-11-13 20:47:44 +00:00

74 lines
1.9 KiB
Groff

.\" ----------------------------------------------------------------------------
.\" "THE BEER-WARE LICENSE" (Revision 42):
.\" <phk@login.dknet.dk> wrote this file. As long as you retain this notice you
.\" can do whatever you want with this stuff. If we meet some day, and you think
.\" this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
.\" ----------------------------------------------------------------------------
.\"
.\" $Id$
.\"
.Dd November 13, 1994
.Dt config_open 3
.Os FreeBSD
.Sh NAME
.Nm config_open ,
.Nm config_close ,
.Nm config_next ,
.Nm config_skip
.Nd read config files
.Sh SYNOPSIS
.Ft char *
.Fn config_open "const char *filename" "int contlines"
.Ft void
.Fn config_close
.Ft char *
.Fn config_next
.Ft char *
.Fn config_skip "char **string"
.Sh DESCRIPTION
These functions are used to read config files with the following syntax:
.Bl -bullet -compact
.It
All lines where the first
.Sq !isspace()
is '#' are comments which are discarded.
.It
If continuation-lines are enabled, any line starting with a
.Sq isspace()
character is joined to the preceeding line and blank lines are discarded.
.It
An entry starts at the first
.Sq !isspace()
character and ends at the first
.Sq Li \en
.Li .
.El
.Pp
.Fn config_open
will open the specified
.Fa filename
and read it into a private malloced area, and close the file again. If
.Fa contlines
is non-zero, continuation lines will be allowed.
In case of trouble, the name of the system-call causing the trouble will
be returned. If successful,
.Fn config_open
returns NULL.
.Pp
.Fn config_close
will free the malloced area.
.Pp
.Fn config_next
returns the next entry in the area. NULL is returned to indicate End-of-file.
The returned string is null-terminated.
.Pp
.Fn config_skip
returns the next word from the string
.Fa *string
.Li .
.Fa *string
will be advanced to point to the next word.
NULL is returned to indicate the end of the string.
.Sh AUTHOR
Poul-Henning Kamp <phk@login.dknet.dk>