1explain_sethostname(3)     Library Functions Manual     explain_sethostname(3)
2
3
4

NAME

6       explain_sethostname - explain sethostname(2) errors
7

SYNOPSIS

9       #include <libexplain/sethostname.h>
10       const char *explain_sethostname(const char *name, size_t name_size);
11       const  char  *explain_errno_sethostname(int  errnum,  const char *name,
12       size_t name_size);
13       void explain_message_sethostname(char *message, int message_size, const
14       char *name, size_t name_size);
15       void explain_message_errno_sethostname(char *message, int message_size,
16       int errnum, const char *name, size_t name_size);
17

DESCRIPTION

19       These functions may be used to obtain explanations for errors  returned
20       by the sethostname(2) system call.
21
22   explain_sethostname
23       const char *explain_sethostname(const char *name, size_t name_size);
24
25       The explain_sethostname function is used to obtain an explanation of an
26       error returned by the sethostname(2) system call. The least the message
27       will  contain  is  the value of strerror(errno), but usually it will do
28       much better, and indicate the underlying cause in more detail.
29
30       The errno global variable will be used to obtain the error value to  be
31       decoded.
32
33       This  function  is intended to be used in a fashion similar to the fol‐
34       lowing example:
35              if (sethostname(name, name_size) < 0)
36              {
37                  fprintf(stderr, "%s\n", explain_sethostname(name, name_size));
38                  exit(EXIT_FAILURE);
39              }
40
41       The   above   code   example   is   available   pre‐packaged   as   the
42       explain_sethostname_or_die(3) function.
43
44       name    The original name, exactly as passed to the sethostname(2) sys‐
45               tem call.
46
47       name_size
48               The original name_size, exactly as passed to the sethostname(2)
49               system call.
50
51       Returns:
52               The message explaining the error. This message buffer is shared
53               by all libexplain functions which do not  supply  a  buffer  in
54               their argument list.  This will be overwritten by the next call
55               to any libexplain function which shares this buffer,  including
56               other threads.
57
58       Note: This function is not thread safe, because it shares a return buf‐
59       fer across all threads, and many other functions in this library.
60
61   explain_errno_sethostname
62       const char *explain_errno_sethostname(int  errnum,  const  char  *name,
63       size_t name_size);
64
65       The explain_errno_sethostname function is used to obtain an explanation
66       of an error returned by the sethostname(2) system call.  The least  the
67       message  will  contain  is the value of strerror(errno), but usually it
68       will do much better, and indicate the underlying cause in more detail.
69
70       This function is intended to be used in a fashion similar to  the  fol‐
71       lowing example:
72              if (sethostname(name, name_size) < 0)
73              {
74                  int err = errno;
75                  fprintf(stderr, "%s\n", explain_errno_sethostname(err, name, name_size));
76                  exit(EXIT_FAILURE);
77              }
78
79       The   above   code   example   is   available   pre‐packaged   as   the
80       explain_sethostname_or_die(3) function.
81
82       errnum  The error value to be decoded, usually obtained from the  errno
83               global  variable  just  before this function is called. This is
84               necessary if you need to call any code between the system  call
85               to  be explained and this function, because many libc functions
86               will alter the value of errno.
87
88       name    The original name, exactly as passed to the sethostname(2) sys‐
89               tem call.
90
91       name_size
92               The original name_size, exactly as passed to the sethostname(2)
93               system call.
94
95       Returns:
96               The message explaining the error. This message buffer is shared
97               by  all  libexplain  functions  which do not supply a buffer in
98               their argument list.  This will be overwritten by the next call
99               to  any libexplain function which shares this buffer, including
100               other threads.
101
102       Note: This function is not thread safe, because it shares a return buf‐
103       fer across all threads, and many other functions in this library.
104
105   explain_message_sethostname
106       void explain_message_sethostname(char *message, int message_size, const
107       char *name, size_t name_size);
108
109       The explain_message_sethostname function is used to obtain an  explana‐
110       tion of an error returned by the sethostname(2) system call.  The least
111       the message will contain is the value of strerror(errno),  but  usually
112       it  will  do  much  better,  and  indicate the underlying cause in more
113       detail.
114
115       The errno global variable will be used to obtain the error value to  be
116       decoded.
117
118       This  function  is intended to be used in a fashion similar to the fol‐
119       lowing example:
120              if (sethostname(name, name_size) < 0)
121              {
122                  char message[3000];
123                  explain_message_sethostname(message, sizeof(message), name, name_size);
124                  fprintf(stderr, "%s\n", message);
125                  exit(EXIT_FAILURE);
126              }
127
128       The   above   code   example   is   available   pre‐packaged   as   the
129       explain_sethostname_or_die(3) function.
130
131       message The location in which to store the returned message. If a suit‐
132               able message return buffer is supplied, this function is thread
133               safe.
134
135       message_size
136               The  size  in  bytes  of  the  location  in  which to store the
137               returned message.
138
139       name    The original name, exactly as passed to the sethostname(2) sys‐
140               tem call.
141
142       name_size
143               The original name_size, exactly as passed to the sethostname(2)
144               system call.
145
146   explain_message_errno_sethostname
147       void explain_message_errno_sethostname(char *message, int message_size,
148       int errnum, const char *name, size_t name_size);
149
150       The  explain_message_errno_sethostname  function  is  used to obtain an
151       explanation of an error returned by  the  sethostname(2)  system  call.
152       The least the message will contain is the value of strerror(errno), but
153       usually it will do much better, and indicate the  underlying  cause  in
154       more detail.
155
156       This  function  is intended to be used in a fashion similar to the fol‐
157       lowing example:
158              if (sethostname(name, name_size) < 0)
159              {
160                  int err = errno;
161                  char message[3000];
162                  explain_message_errno_sethostname(message, sizeof(message), err, name,
163                      name_size);
164                  fprintf(stderr, "%s\n", message);
165                  exit(EXIT_FAILURE);
166              }
167
168       The   above   code   example   is   available   pre‐packaged   as   the
169       explain_sethostname_or_die(3) function.
170
171       message The location in which to store the returned message. If a suit‐
172               able message return buffer is supplied, this function is thread
173               safe.
174
175       message_size
176               The  size  in  bytes  of  the  location  in  which to store the
177               returned message.
178
179       errnum  The error value to be decoded, usually obtained from the  errno
180               global  variable  just  before this function is called. This is
181               necessary if you need to call any code between the system  call
182               to  be explained and this function, because many libc functions
183               will alter the value of errno.
184
185       name    The original name, exactly as passed to the sethostname(2) sys‐
186               tem call.
187
188       name_size
189               The original name_size, exactly as passed to the sethostname(2)
190               system call.
191

SEE ALSO

193       sethostname(2)
194               get/set hostname
195
196       explain_sethostname_or_die(3)
197               get/set hostname and report errors
198
200       libexplain version 1.4
201       Copyright (C) 2009 Peter Miller
202
203
204
205                                                        explain_sethostname(3)
Impressum