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