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