1explain_fdopen(3) Library Functions Manual explain_fdopen(3)
2
3
4
6 explain_fdopen - explain fdopen(3) errors
7
9 #include <libexplain/fdopen.h>
10 const char *explain_fdopen(int fildes, const char *flags);
11 const char *explain_errno_fdopen(int errnum, int fildes, const char
12 *flags);
13 void explain_message_fdopen(char *message, int message_size, int
14 fildes, const char *flags);
15 void explain_message_errno_fdopen(char *message, int message_size, int
16 errnum, int fildes, const char *flags);
17
19 These functions may be used to obtain explanations for errors returned
20 by the fdopen(3) system call.
21
22 explain_fdopen
23 const char *explain_fdopen(int fildes, const char *flags);
24
25 The explain_fdopen function is used to obtain an explanation of an
26 error returned by the fdopen(3) 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 FILE *fp = fdopen(fildes, flags);
36 if (!fp)
37 {
38 fprintf(stderr, "%s\n", explain_fdopen(fildes, flags));
39 exit(EXIT_FAILURE);
40 }
41
42 The above code example is available pre‐packaged as the
43 explain_fdopen_or_die(3) function.
44
45 fildes The original fildes, exactly as passed to the fdopen(3) system
46 call.
47
48 flags The original flags, exactly as passed to the fdopen(3) system
49 call.
50
51 Returns:
52 The message explaining the error. This message buffer is
53 shared by all libexplain functions which do not supply a buffer
54 in their argument list. This will be overwritten by the next
55 call to any libexplain function which shares this buffer,
56 including 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_fdopen
62 const char *explain_errno_fdopen(int errnum, int fildes, const char
63 *flags);
64
65 The explain_errno_fdopen function is used to obtain an explanation of
66 an error returned by the fdopen(3) system call. The least the message
67 will contain is the value of strerror(errnum), but usually it will do
68 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 FILE *fp = fdopen(fildes, flags);
73 if (!fp)
74 {
75 int err = errno;
76 fprintf(stderr, "%s\n", explain_errno_fdopen(err, fildes, flags));
77 exit(EXIT_FAILURE);
78 }
79
80 The above code example is available pre‐packaged as the
81 explain_fdopen_or_die(3) function.
82
83 errnum The error value to be decoded, usually obtained from the errno
84 global variable just before this function is called. This is
85 necessary if you need to call any code between the system call
86 to be explained and this function, because many libc functions
87 will alter the value of errno.
88
89 fildes The original fildes, exactly as passed to the fdopen(3) system
90 call.
91
92 flags The original flags, exactly as passed to the fdopen(3) system
93 call.
94
95 Returns:
96 The message explaining the error. This message buffer is
97 shared by all libexplain functions which do not supply a buffer
98 in their argument list. This will be overwritten by the next
99 call to any libexplain function which shares this buffer,
100 including 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_fdopen
106 void explain_message_fdopen(char *message, int message_size, int
107 fildes, const char *flags);
108
109 The explain_message_fdopen function may be used to obtain an explana‐
110 tion of an error returned by the fdopen(3) system call. The least the
111 message will contain is the value of strerror(errno), but usually it
112 will do much better, and indicate the underlying cause in more detail.
113
114 The errno global variable will be used to obtain the error value to be
115 decoded.
116
117 This function is intended to be used in a fashion similar to the fol‐
118 lowing example:
119 FILE *fp = fdopen(fildes, flags);
120 if (!fp)
121 {
122 char message[3000];
123 explain_message_fdopen(message, sizeof(message), fildes, flags);
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_fdopen_or_die(3) function.
130
131 message The location in which to store the returned message. If a
132 suitable message return buffer is supplied, this function is
133 thread safe.
134
135 message_size
136 The size in bytes of the location in which to store the
137 returned message.
138
139 fildes The original fildes, exactly as passed to the fdopen(3) system
140 call.
141
142 flags The original flags, exactly as passed to the fdopen(3) system
143 call.
144
145 explain_message_errno_fdopen
146 void explain_message_errno_fdopen(char *message, int message_size, int
147 errnum, int fildes, const char *flags);
148
149 The explain_message_errno_fdopen function may be used to obtain an
150 explanation of an error returned by the fdopen(3) system call. The
151 least the message will contain is the value of strerror(errnum), but
152 usually it will do much better, and indicate the underlying cause in
153 more detail.
154
155 This function is intended to be used in a fashion similar to the fol‐
156 lowing example:
157 FILE *fp = fdopen(fildes, flags);
158 if (!fp)
159
160 {
161 int err = errno;
162 char message[3000];
163 explain_message_errno_fdopen(message, sizeof(message),
164 err, fildes, flags);
165 fprintf(stderr, "%s\n", message);
166 exit(EXIT_FAILURE);
167 }
168
169 The above code example is available pre‐packaged as the
170 explain_fdopen_or_die(3) function.
171
172 message The location in which to store the returned message. If a
173 suitable message return buffer is supplied, this function is
174 thread safe.
175
176 message_size
177 The size in bytes of the location in which to store the
178 returned message.
179
180 errnum The error value to be decoded, usually obtained from the errno
181 global variable just before this function is called. This is
182 necessary if you need to call any code between the system call
183 to be explained and this function, because many libc functions
184 will alter the value of errno.
185
186 fildes The original fildes, exactly as passed to the fdopen(3) system
187 call.
188
189 flags The original flags, exactly as passed to the fdopen(3) system
190 call.
191
193 fdopen(3)
194 stream open functions
195
196 explain_fdopen_or_die(3)
197 stream open functions and report errors
198
200 libexplain version 1.4
201 Copyright (C) 2008 Peter Miller
202
203
204
205 explain_fdopen(3)