1explain_popen(3) Library Functions Manual explain_popen(3)
2
3
4
6 explain_popen - explain popen(3) errors
7
9 #include <libexplain/popen.h>
10 const char *explain_popen(const char *command, const char *flags);
11 const char *explain_errno_popen(int errnum, const char *command, const
12 char *flags);
13 void explain_message_popen(char *message, int message_size, const char
14 *command, const char *flags);
15 void explain_message_errno_popen(char *message, int message_size, int
16 errnum, const char *command, const char *flags);
17
19 These functions may be used to obtain explanations for errors returned
20 by the popen(3) system call.
21
22 explain_popen
23 const char *explain_popen(const char *command, const char *flags);
24
25 The explain_popen function is used to obtain an explanation of an error
26 returned by the popen(3) system call. The least the message will con‐
27 tain is the value of strerror(errno), but usually it will do much bet‐
28 ter, 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 = popen(command, flags);
36 if (!fp)
37 {
38 fprintf(stderr, "%s\n", explain_popen(command, flags));
39 exit(EXIT_FAILURE);
40 }
41
42 The above code example is available pre‐packaged as the
43 explain_popen_or_die(3) function.
44
45 command The original command, exactly as passed to the popen(3) system
46 call.
47
48 flags The original flags, exactly as passed to the popen(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_popen
62 const char *explain_errno_popen(int errnum, const char *command, const
63 char *flags);
64
65 The explain_errno_popen function is used to obtain an explanation of an
66 error returned by the popen(3) system call. The least the message will
67 contain is the value of strerror(errnum), but usually it will do much
68 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 = popen(command, flags);
73 if (!fp)
74 {
75 int err = errno;
76 fprintf(stderr, "%s\n", explain_errno_popen(err, command, flags));
77 exit(EXIT_FAILURE);
78 }
79
80 The above code example is available pre‐packaged as the
81 explain_popen_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 command The original command, exactly as passed to the popen(3) system
90 call.
91
92 flags The original flags, exactly as passed to the popen(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_popen
106 void explain_message_popen(char *message, int message_size, const char
107 *command, const char *flags);
108
109 The explain_message_popen function may be used to obtain an explana‐
110 tion of an error returned by the popen(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 = popen(command, flags);
120 if (!fp)
121 {
122 char message[3000];
123 explain_message_popen(message, sizeof(message), command, 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_popen_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 command The original command, exactly as passed to the popen(3) system
140 call.
141
142 flags The original flags, exactly as passed to the popen(3) system
143 call.
144
145 explain_message_errno_popen
146 void explain_message_errno_popen(char *message, int message_size, int
147 errnum, const char *command, const char *flags);
148
149 The explain_message_errno_popen function may be used to obtain an
150 explanation of an error returned by the popen(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 = popen(command, flags);
158 if (!fp)
159 {
160 int err = errno;
161 char message[3000];
162 explain_message_errno_popen(message, sizeof(message),
163 err, command, flags);
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_popen_or_die(3) function.
170
171 message The location in which to store the returned message. If a
172 suitable message return buffer is supplied, this function is
173 thread 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 command The original command, exactly as passed to the popen(3) system
186 call.
187
188 flags The original flags, exactly as passed to the popen(3) system
189 call.
190
192 popen(3)
193 process I/O
194
195 explain_popen_or_die(3)
196 process I/O and report errors
197
199 libexplain version 1.4
200 Copyright (C) 2009 Peter Miller
201
202
203
204 explain_popen(3)