1explain_nanosleep(3) Library Functions Manual explain_nanosleep(3)
2
3
4
6 explain_nanosleep - explain nanosleep(2) errors
7
9 #include <libexplain/nanosleep.h>
10 const char *explain_nanosleep(const struct timespec *req, struct time‐
11 spec *rem);
12 const char *explain_errno_nanosleep(int errnum, const struct timespec
13 *req, struct timespec *rem);
14 void explain_message_nanosleep(char *message, int message_size, const
15 struct timespec *req, struct timespec *rem);
16 void explain_message_errno_nanosleep(char *message, int message_size,
17 int errnum, const struct timespec *req, struct timespec *rem);
18
20 These functions may be used to obtain explanations for errors returned
21 by the nanosleep(2) system call.
22
23 explain_nanosleep
24 const char *explain_nanosleep(const struct timespec *req, struct time‐
25 spec *rem);
26
27 The explain_nanosleep function is used to obtain an explanation of an
28 error returned by the nanosleep(2) system call. The least the message
29 will contain is the value of strerror(errno), but usually it will do
30 much better, and indicate the underlying cause in more detail.
31
32 The errno global variable will be used to obtain the error value to be
33 decoded.
34
35 req The original req, exactly as passed to the nanosleep(2) system
36 call.
37
38 rem The original rem, exactly as passed to the nanosleep(2) system
39 call.
40
41 Returns:
42 The message explaining the error. This message buffer is shared
43 by all libexplain functions which do not supply a buffer in
44 their argument list. This will be overwritten by the next call
45 to any libexplain function which shares this buffer, including
46 other threads.
47
48 Note: This function is not thread safe, because it shares a return buf‐
49 fer across all threads, and many other functions in this library.
50
51 Example: This function is intended to be used in a fashion similar to
52 the following example:
53 if (nanosleep(req, rem) < 0)
54 {
55 fprintf(stderr, "%s\n", explain_nanosleep(req, rem));
56 exit(EXIT_FAILURE);
57 }
58
59 The above code example is available pre-packaged as the
60 explain_nanosleep_or_die(3) function.
61
62 explain_errno_nanosleep
63 const char *explain_errno_nanosleep(int errnum, const struct timespec
64 *req, struct timespec *rem);
65
66 The explain_errno_nanosleep function is used to obtain an explanation
67 of an error returned by the nanosleep(2) system call. The least the
68 message will contain is the value of strerror(errno), but usually it
69 will do 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 req The original req, exactly as passed to the nanosleep(2) system
78 call.
79
80 rem The original rem, exactly as passed to the nanosleep(2) system
81 call.
82
83 Returns:
84 The message explaining the error. This message buffer is shared
85 by all libexplain functions which do not supply a buffer in
86 their argument list. This will be overwritten by the next call
87 to any libexplain function which shares this buffer, including
88 other threads.
89
90 Note: This function is not thread safe, because it shares a return buf‐
91 fer across all threads, and many other functions in this library.
92
93 Example: This function is intended to be used in a fashion similar to
94 the following example:
95 if (nanosleep(req, rem) < 0)
96 {
97 int err = errno;
98 fprintf(stderr, "%s\n", explain_errno_nanosleep(err, req,
99 rem));
100 exit(EXIT_FAILURE);
101 }
102
103 The above code example is available pre-packaged as the
104 explain_nanosleep_or_die(3) function.
105
106 explain_message_nanosleep
107 void explain_message_nanosleep(char *message, int message_size, const
108 struct timespec *req, struct timespec *rem);
109
110 The explain_message_nanosleep function is used to obtain an explanation
111 of an error returned by the nanosleep(2) system call. The least the
112 message will contain is the value of strerror(errno), but usually it
113 will do 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 req The original req, exactly as passed to the nanosleep(2) system
127 call.
128
129 rem The original rem, exactly as passed to the nanosleep(2) system
130 call.
131
132 Example: This function is intended to be used in a fashion similar to
133 the following example:
134 if (nanosleep(req, rem) < 0)
135 {
136 char message[3000];
137 explain_message_nanosleep(message, sizeof(message), req,
138 rem);
139 fprintf(stderr, "%s\n", message);
140 exit(EXIT_FAILURE);
141 }
142
143 The above code example is available pre-packaged as the
144 explain_nanosleep_or_die(3) function.
145
146 explain_message_errno_nanosleep
147 void explain_message_errno_nanosleep(char *message, int message_size,
148 int errnum, const struct timespec *req, struct timespec *rem);
149
150 The explain_message_errno_nanosleep function is used to obtain an
151 explanation of an error returned by the nanosleep(2) system call. The
152 least the message will contain is the value of strerror(errno), but
153 usually it will do much better, and indicate the underlying cause in
154 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 req The original req, exactly as passed to the nanosleep(2) system
171 call.
172
173 rem The original rem, exactly as passed to the nanosleep(2) system
174 call.
175
176 Example: This function is intended to be used in a fashion similar to
177 the following example:
178 if (nanosleep(req, rem) < 0)
179 {
180 int err = errno;
181 char message[3000];
182 explain_message_errno_nanosleep(message, sizeof(message),
183 err, req, rem);
184 fprintf(stderr, "%s\n", message);
185 exit(EXIT_FAILURE);
186 }
187
188 The above code example is available pre-packaged as the
189 explain_nanosleep_or_die(3) function.
190
192 nanosleep(2)
193 high‐resolution sleep
194
195 explain_nanosleep_or_die(3)
196 high‐resolution sleep and report errors
197
199 libexplain version 1.4
200 Copyright (C) 2013 Peter Miller
201
202
203
204 explain_nanosleep(3)