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