mount_setattr.2: Further tweaks after feedback from Christian Brauner
[man-pages.git] / man3 / setaliasent.3
blob9ddf21f188a47a97a15c11c5f1c5010d3833f45d
1 .\" Copyright 2003 Walter Harms (walter.harms@informatik.uni-oldenburg.de)
2 .\"
3 .\" %%%LICENSE_START(GPL_NOVERSION_ONELINE)
4 .\" Distributed under GPL
5 .\" %%%LICENSE_END
6 .\"
7 .\" Polished a bit, added a little, aeb
8 .\"
9 .TH SETALIASENT 3 2021-03-22 "GNU" "Linux Programmer's Manual"
10 .SH NAME
11 setaliasent, endaliasent, getaliasent, getaliasent_r,
12 getaliasbyname, getaliasbyname_r \- read an alias entry
13 .SH SYNOPSIS
14 .nf
15 .B #include <aliases.h>
16 .PP
17 .B "void setaliasent(void);"
18 .B "void endaliasent(void);"
19 .PP
20 .B "struct aliasent *getaliasent(void);"
21 .BI "int getaliasent_r(struct aliasent *restrict " result ,
22 .BI "                     char *restrict " buffer ", size_t " buflen ,
23 .BI "                     struct aliasent **restrict " res );
24 .PP
25 .BI "struct aliasent *getaliasbyname(const char *" name );
26 .BI "int getaliasbyname_r(const char *restrict " name ,
27 .BI "                     struct aliasent *restrict " result ,
28 .BI "                     char *restrict " buffer ", size_t " buflen ,
29 .BI "                     struct aliasent **restrict " res );
30 .fi
31 .SH DESCRIPTION
32 One of the databases available with the Name Service Switch (NSS)
33 is the aliases database, that contains mail aliases.
34 (To find out which databases are supported, try
35 .IR "getent \-\-help" .)
36 Six functions are provided to access the aliases database.
37 .PP
38 The
39 .BR getaliasent ()
40 function returns a pointer to a structure containing
41 the group information from the aliases database.
42 The first time it is called it returns the first entry;
43 thereafter, it returns successive entries.
44 .PP
45 The
46 .BR setaliasent ()
47 function rewinds the file pointer to the beginning of the
48 aliases database.
49 .PP
50 The
51 .BR endaliasent ()
52 function closes the aliases database.
53 .PP
54 .BR getaliasent_r ()
55 is the reentrant version of the previous function.
56 The requested structure
57 is stored via the first argument but the programmer needs to fill the other
58 arguments also.
59 Not providing enough space causes the function to fail.
60 .PP
61 The function
62 .BR getaliasbyname ()
63 takes the name argument and searches the aliases database.
64 The entry is returned as a pointer to a
65 .IR "struct aliasent" .
66 .PP
67 .BR getaliasbyname_r ()
68 is the reentrant version of the previous function.
69 The requested structure
70 is stored via the second argument but the programmer needs to fill the other
71 arguments also.
72 Not providing enough space causes the function to fail.
73 .PP
74 The
75 .I "struct aliasent"
76 is defined in
77 .IR <aliases.h> :
78 .PP
79 .in +4n
80 .EX
81 struct aliasent {
82     char    *alias_name;             /* alias name */
83     size_t   alias_members_len;
84     char   **alias_members;          /* alias name list */
85     int      alias_local;
87 .EE
88 .in
89 .SH RETURN VALUE
90 The functions
91 .BR getaliasent_r ()
92 and
93 .BR getaliasbyname_r ()
94 return a nonzero value on error.
95 .SH FILES
96 The default alias database is the file
97 .IR /etc/aliases .
98 This can be changed in the
99 .I /etc/nsswitch.conf
100 file.
101 .SH ATTRIBUTES
102 For an explanation of the terms used in this section, see
103 .BR attributes (7).
104 .ad l
107 allbox;
108 lbx lb lb
109 l l l.
110 Interface       Attribute       Value
112 .BR setaliasent (),
113 .BR endaliasent (),
114 .BR getaliasent_r (),
115 .BR getaliasbyname_r ()
116 T}      Thread safety   MT-Safe locale
118 .BR getaliasent (),
119 .BR getaliasbyname ()
120 T}      Thread safety   MT-Unsafe
124 .sp 1
125 .SH CONFORMING TO
126 These routines are glibc-specific.
127 The NeXT system has similar routines:
129 .in +4n
131 #include <aliasdb.h>
133 void alias_setent(void);
134 void alias_endent(void);
135 alias_ent *alias_getent(void);
136 alias_ent *alias_getbyname(char *name);
139 .SH EXAMPLES
140 The following example compiles with
141 .IR "gcc example.c \-o example" .
142 It will dump all names in the alias database.
145 #include <aliases.h>
146 #include <stdio.h>
147 #include <stdlib.h>
148 #include <errno.h>
151 main(void)
153     struct aliasent *al;
154     setaliasent();
155     for (;;) {
156         al = getaliasent();
157         if (al == NULL)
158             break;
159         printf("Name: %s\en", al\->alias_name);
160     }
161     if (errno) {
162         perror("reading alias");
163         exit(EXIT_FAILURE);
164     }
165     endaliasent();
166     exit(EXIT_SUCCESS);
169 .SH SEE ALSO
170 .BR getgrent (3),
171 .BR getpwent (3),
172 .BR getspent (3),
173 .BR aliases (5)
175 .\" /etc/sendmail/aliases
176 .\" Yellow Pages
177 .\" newaliases, postalias