@@@ much mess, mostly manpages
[mLib] / sys / env.3.in
CommitLineData
e19206c2 1.\" -*-nroff-*-
c4ccbbf9
MW
2.\"
3.\" Manual for environment variable table
4.\"
5.\" (c) 1999, 2001, 2005, 2009, 2024 Straylight/Edgeware
6.\"
7.
8.\"----- Licensing notice ---------------------------------------------------
9.\"
10.\" This file is part of the mLib utilities library.
11.\"
12.\" mLib is free software: you can redistribute it and/or modify it under
13.\" the terms of the GNU Library General Public License as published by
14.\" the Free Software Foundation; either version 2 of the License, or (at
15.\" your option) any later version.
16.\"
17.\" mLib is distributed in the hope that it will be useful, but WITHOUT
18.\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19.\" FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
20.\" License for more details.
21.\"
22.\" You should have received a copy of the GNU Library General Public
23.\" License along with mLib. If not, write to the Free Software
24.\" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
25.\" USA.
26.
27.\"--------------------------------------------------------------------------
28.so ../defs.man \" @@@PRE@@@
29.
30.\"--------------------------------------------------------------------------
31.TH env 3mLib "26 July 1999" "Straylight/Edgeware" "mLib utilities library"
e19206c2 32.\" @env_get
33.\" @env_put
34.\" @env_import
35.\" @env_export
36.\" @env_destroy
c4ccbbf9
MW
37.
38.\"--------------------------------------------------------------------------
39.SH "NAME"
40env \- efficient fiddling with environment variables
41.
42.\"--------------------------------------------------------------------------
e19206c2 43.SH "SYNOPSIS"
c4ccbbf9 44.
e19206c2 45.nf
46.B "#include <mLib/env.h>"
d056fbdf 47.PP
e19206c2 48.BI "char *env_get(sym_table *" t ", const char *" name );
f4d2cec8 49.BI "void env_put(sym_table *" t ,
e19206c2 50.BI " const char *" name ", const char *" value );
51.BI "void env_import(sym_table *" t ", char **" env );
52.BI "char **env_export(sym_table *" t );
53.fi
c4ccbbf9
MW
54.
55.\"--------------------------------------------------------------------------
e19206c2 56.SH "DESCRIPTION"
c4ccbbf9 57.
e19206c2 58The functions in the
59.B "<mLib/env.h>"
60header manipulate environment variables stored in a hash table.
61.PP
62The function
63.B env_import
64reads a standard Unix environment array and stores the variables in the
65symbol table. (A standard Unix environment array is an array of
66pointers to strings of the form
67.IB name = value
68terminated by a null pointer. This format is used for the global
69.B environ
70variable, and by the
71.BR execve (2)
72function.) The symbol table must have already been created (see
73.BR sym_create (3)).
74.PP
75The function
76.B env_export
77creates a Unix environment array from a symbol table. The environment
78array is one big block of memory allocated using
39e23af4 79.BR xmalloc (3);
e19206c2 80hence, one call to
39e23af4 81.BR xfree (3)
e19206c2 82releases all the memory used for the pointer array and the strings.
83.PP
84The
85.B env_get
86function looks up a variable in an environment symbol table. The
87returned result is the variable's value if it exists, or a null pointer
88if not.
89.PP
90The
91.B env_put
92function sets or deletes environment variables. If the
93.I name
94argument contains an
95.RB ` = '
96character, it is assumed to be of the form
97.IB n = v\fR;
98the
1f75302b 99.I value
100argument is ignored, and the variable
e19206c2 101.I n
102is assigned the value
103.IR v .
104Otherwise, if
105.I value
106is not a null pointer, the variable
107.I name
1f75302b 108is assigned
109.IR value .
e19206c2 110Finally, if
111.I value
112is null, the variable
113.I name
114is deleted.
115.PP
116The
117.B env_destroy
1f75302b 118function frees an environment symbol table, together with all of the
119environment variables.
c4ccbbf9
MW
120.
121.\"--------------------------------------------------------------------------
e19206c2 122.SH "SEE ALSO"
c4ccbbf9 123.
e19206c2 124.BR sym (3),
125.BR mLib (3).
c4ccbbf9
MW
126.
127.\"--------------------------------------------------------------------------
e19206c2 128.SH "AUTHOR"
c4ccbbf9 129.
9b5ac6ff 130Mark Wooding, <mdw@distorted.org.uk>
c4ccbbf9
MW
131.
132.\"----- That's all, folks --------------------------------------------------