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

NAME

6       explain_strdup - explain strdup(3) errors
7

SYNOPSIS

9       #include <libexplain/strdup.h>
10       const char *explain_strdup(const char *data);
11       const char *explain_errno_strdup(int errnum, const char *data);
12       void explain_message_strdup(char *message, int message_size, const char
13       *data);
14       void explain_message_errno_strdup(char *message, int message_size, int
15       errnum, const char *data);
16

DESCRIPTION

18       These  functions may be used to obtain explanations for errors returned
19       by the strdup(3) system call.
20
21   explain_strdup
22       const char *explain_strdup(const char *data);
23
24       The explain_strdup function is used to  obtain  an  explanation  of  an
25       error returned by the strdup(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       data    The original data, exactly as passed to  the  strdup(3)  system
33               call.
34
35       Returns:
36               The message explaining the error. This message buffer is shared
37               by all libexplain functions which do not  supply  a  buffer  in
38               their argument list.  This will be overwritten by the next call
39               to any libexplain function which shares this buffer,  including
40               other threads.
41
42       Note: This function is not thread safe, because it shares a return buf‐
43       fer across all threads, and many other functions in this library.
44
45       Example: This function is intended to be used in a fashion  similar  to
46       the following example:
47              char *result = strdup(data);
48              if (!result)
49              {
50                  fprintf(stderr, "%s\n", explain_strdup(data));
51                  exit(EXIT_FAILURE);
52              }
53
54       The   above   code   example   is   available   pre‐packaged   as   the
55       explain_strdup_or_die(3) function.
56
57   explain_errno_strdup
58       const char *explain_errno_strdup(int errnum, const char *data);
59
60       The explain_errno_strdup function is used to obtain an  explanation  of
61       an  error  returned by the strdup(3) system call. The least the message
62       will contain is the value of strerror(errno), but usually  it  will  do
63       much better, and indicate the underlying cause in more detail.
64
65       errnum  The  error value to be decoded, usually obtained from the errno
66               global variable just before this function is  called.  This  is
67               necessary  if you need to call any code between the system call
68               to be explained and this function, because many libc  functions
69               will alter the value of errno.
70
71       data    The  original  data,  exactly as passed to the strdup(3) system
72               call.
73
74       Returns:
75               The message explaining the error. This message buffer is shared
76               by  all  libexplain  functions  which do not supply a buffer in
77               their argument list.  This will be overwritten by the next call
78               to  any libexplain function which shares this buffer, including
79               other threads.
80
81       Note: This function is not thread safe, because it shares a return buf‐
82       fer across all threads, and many other functions in this library.
83
84       Example:  This  function is intended to be used in a fashion similar to
85       the following example:
86              char *result = strdup(data);
87              if (!result)
88              {
89                  int err = errno;
90                  fprintf(stderr, "%s\n", explain_errno_strdup(err, data));
91                  exit(EXIT_FAILURE);
92              }
93
94       The   above   code   example   is   available   pre‐packaged   as   the
95       explain_strdup_or_die(3) function.
96
97   explain_message_strdup
98       void explain_message_strdup(char *message, int message_size, const char
99       *data);
100
101       The explain_message_strdup function is used to obtain an explanation of
102       an  error  returned by the strdup(3) system call. The least the message
103       will contain is the value of strerror(errno), but usually  it  will  do
104       much better, and indicate the underlying cause in more detail.
105
106       The  errno global variable will be used to obtain the error value to be
107       decoded.
108
109       message The location in which to store the returned message. If a suit‐
110               able message return buffer is supplied, this function is thread
111               safe.
112
113       message_size
114               The size in bytes  of  the  location  in  which  to  store  the
115               returned message.
116
117       data    The  original  data,  exactly as passed to the strdup(3) system
118               call.
119
120       Example: This function is intended to be used in a fashion  similar  to
121       the following example:
122              char *result = strdup(data);
123              if (!result)
124              {
125                  char message[3000];
126                  explain_message_strdup(message, sizeof(message), data);
127                  fprintf(stderr, "%s\n", message);
128                  exit(EXIT_FAILURE);
129              }
130
131       The   above   code   example   is   available   pre‐packaged   as   the
132       explain_strdup_or_die(3) function.
133
134   explain_message_errno_strdup
135       void explain_message_errno_strdup(char *message, int message_size, int
136       errnum, const char *data);
137
138       The explain_message_errno_strdup function is used to obtain an explana‐
139       tion of an error returned by the strdup(3) system call. The  least  the
140       message  will  contain  is the value of strerror(errno), but usually it
141       will do much better, and indicate the underlying cause in more detail.
142
143       message The location in which to store the returned message. If a suit‐
144               able message return buffer is supplied, this function is thread
145               safe.
146
147       message_size
148               The size in bytes  of  the  location  in  which  to  store  the
149               returned message.
150
151       errnum  The  error value to be decoded, usually obtained from the errno
152               global variable just before this function is  called.  This  is
153               necessary  if you need to call any code between the system call
154               to be explained and this function, because many libc  functions
155               will alter the value of errno.
156
157       data    The  original  data,  exactly as passed to the strdup(3) system
158               call.
159
160       Example: This function is intended to be used in a fashion  similar  to
161       the following example:
162              char *result = strdup(data);
163              if (!result)
164              {
165                  int err = errno;
166                  char message[3000];
167                  explain_message_errno_strdup(message, sizeof(message), err,
168                  data);
169                  fprintf(stderr, "%s\n", message);
170                  exit(EXIT_FAILURE);
171              }
172
173       The   above   code   example   is   available   pre‐packaged   as   the
174       explain_strdup_or_die(3) function.
175

SEE ALSO

177       strdup(3)
178               duplicate a string
179
180       explain_strdup_or_die(3)
181               duplicate a string and report errors
182
184       libexplain version 0.40
185       Copyright (C) 2009 Peter Miller
186
187
188
189                                                             explain_strdup(3)
Impressum