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

NAME

6       explain_gethostname - explain gethostname(2) errors
7

SYNOPSIS

9       #include <libexplain/gethostname.h>
10       const char *explain_gethostname(char *data, size_t data_size);
11       const  char  *explain_errno_gethostname(int  errnum, char *data, size_t
12       data_size);
13       void explain_message_gethostname(char *message, int message_size,  char
14       *data, size_t data_size);
15       void explain_message_errno_gethostname(char *message, int message_size,
16       int errnum, char *data, size_t data_size);
17

DESCRIPTION

19       These functions may be used to obtain explanations for errors  returned
20       by the gethostname(2) system call.
21
22   explain_gethostname
23       const char *explain_gethostname(char *data, size_t data_size);
24
25       The explain_gethostname function is used to obtain an explanation of an
26       error returned by the gethostname(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 (gethostname(data, data_size) < 0)
36              {
37                  fprintf(stderr, "%s\n", explain_gethostname(data, data_size));
38                  exit(EXIT_FAILURE);
39              }
40
41       The above code example is available pre‐packaged as  the  explain_geth‐
42       ostname_or_die(3) function.
43
44       data    The original data, exactly as passed to the gethostname(2) sys‐
45               tem call.
46
47       data_size
48               The original data_size, exactly as passed to the gethostname(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_gethostname
62       const char *explain_errno_gethostname(int errnum,  char  *data,  size_t
63       data_size);
64
65       The explain_errno_gethostname function is used to obtain an explanation
66       of an error returned by the gethostname(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 (gethostname(data, data_size) < 0)
73              {
74                  int err = errno;
75                  fprintf(stderr, "%s\n", explain_errno_gethostname(err, data, data_size));
76                  exit(EXIT_FAILURE);
77              }
78
79       The  above  code example is available pre‐packaged as the explain_geth‐
80       ostname_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       data    The original data, exactly as passed to the gethostname(2) sys‐
89               tem call.
90
91       data_size
92               The original data_size, exactly as passed to the gethostname(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_gethostname
106       void  explain_message_gethostname(char *message, int message_size, char
107       *data, size_t data_size);
108
109       The explain_message_gethostname function is used to obtain an  explana‐
110       tion of an error returned by the gethostname(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 (gethostname(data, data_size) < 0)
121              {
122                  char message[3000];
123                  explain_message_gethostname(message, sizeof(message), data, data_size);
124                  fprintf(stderr, "%s\n", message);
125                  exit(EXIT_FAILURE);
126              }
127
128       The above code example is available pre‐packaged as  the  explain_geth‐
129       ostname_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       data    The original data, exactly as passed to the gethostname(2) sys‐
140               tem call.
141
142       data_size
143               The original data_size, exactly as passed to the gethostname(2)
144               system call.
145
146   explain_message_errno_gethostname
147       void explain_message_errno_gethostname(char *message, int message_size,
148       int errnum, char *data, size_t data_size);
149
150       The  explain_message_errno_gethostname  function  is  used to obtain an
151       explanation of an error returned by  the  gethostname(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 (gethostname(data, data_size) < 0)
159              {
160                  int err = errno;
161                  char message[3000];
162                  explain_message_errno_gethostname(message, sizeof(message), err, data,
163                      data_size);
164                  fprintf(stderr, "%s\n", message);
165                  exit(EXIT_FAILURE);
166              }
167
168       The above code example is available pre‐packaged as  the  explain_geth‐
169       ostname_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       data    The original data, exactly as passed to the gethostname(2) sys‐
186               tem call.
187
188       data_size
189               The original data_size, exactly as passed to the gethostname(2)
190               system call.
191

SEE ALSO

193       gethostname(2)
194               get/set hostname
195
196       explain_gethostname_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_gethostname(3)
Impressum