Rev 1693 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1693 | Rev 3065 | ||
---|---|---|---|
Line 13... | Line 13... | ||
13 | strerror |
13 | strerror |
Line 14... | Line 14... | ||
14 | 14 | ||
15 | ANSI_SYNOPSIS |
15 | ANSI_SYNOPSIS |
16 | #include |
16 | #include |
- | 17 | char *strerror(int <[errnum]>); |
|
- | 18 | char *_strerror_r(struct _reent <[ptr]>, int <[errnum]>, |
|
Line 17... | Line 19... | ||
17 | char *strerror(int <[errnum]>); |
19 | int <[internal]>, int *<[error]>); |
18 | 20 | ||
19 | TRAD_SYNOPSIS |
21 | TRAD_SYNOPSIS |
20 | #include |
22 | #include |
Line 29... | Line 31... | ||
29 | 31 | ||
30 | This implementation of < |
32 | This implementation of < |
Line 31... | Line 33... | ||
31 | for each of the values defined in `< |
33 | for each of the values defined in `< |
- | 34 | ||
- | 35 | o+ |
|
- | 36 | o 0 |
|
32 | 37 | Success |
|
33 | o+ |
38 | |
Line 34... | Line 39... | ||
34 | o E2BIG |
39 | o E2BIG |
35 | Arg list too long |
40 | Arg list too long |
Line 286... | Line 291... | ||
286 | o ESTRPIPE |
291 | o ESTRPIPE |
287 | Strings pipe error |
292 | Strings pipe error |
Line 288... | Line 293... | ||
288 | 293 | ||
Line -... | Line 294... | ||
- | 294 | o- |
|
- | 295 | ||
289 | o- |
296 | <<_strerror_r>> is a reentrant version of the above. |
290 | 297 | ||
291 | RETURNS |
298 | RETURNS |
Line 292... | Line 299... | ||
292 | This function returns a pointer to a string. Your application must |
299 | This function returns a pointer to a string. Your application must |
293 | not modify that string. |
300 | not modify that string. |
294 | 301 | ||
Line 295... | Line 302... | ||
295 | PORTABILITY |
302 | PORTABILITY |
- | 303 | ANSI C requires < |
|
- | 304 | for each error number. |
|
- | 305 | ||
- | 306 | Although this implementation of < |
|
296 | ANSI C requires < |
307 | on <<_user_strerror>>), ANSI C declares that subsequent calls to |
297 | for each error number. |
308 | < |
- | 309 | code cannot depend on the reentrancy of this subroutine. |
|
- | 310 | ||
- | 311 | Although this implementation of < |
|
- | 312 | result with a NUL-terminator, some implementations return < |
|
- | 313 | on failure. Although POSIX allows < |
|
- | 314 | to EINVAL on failure, this implementation does not do so (unless |
|
- | 315 | you provide <<_user_strerror>>). |
|
298 | 316 | ||
Line 299... | Line 317... | ||
299 | Although this implementation of < |
317 | POSIX recommends that unknown <[errnum]> result in a message |
300 | declares that subsequent calls to < |
318 | including that value, however it is not a requirement and this |
301 | result string; therefore portable code cannot depend on the reentrancy |
319 | implementation does not provide that information (unless you |
302 | of this subroutine. |
320 | provide <<_user_strerror>>). |
303 | 321 | ||
304 | This implementation of < |
322 | This implementation of < |
305 | extensibility. < |
- | |
- | 323 | extensibility. < |
|
- | 324 | used as a base for user-defined error values. If the user supplies a |
|
- | 325 | routine named <<_user_strerror>>, and <[errnum]> passed to |
|
- | 326 | < |
|
- | 327 | <<_user_strerror>> is called with three arguments. The first is of |
|
- | 328 | type <[int]>, and is the <[errnum]> value unknown to < |
|
306 | used as a base for user-defined error values. If the user supplies a |
329 | The second is of type <[int]>, and matches the <[internal]> argument |
- | 330 | of <<_strerror_r>>; this should be zero if called from < |
|
- | 331 | and non-zero if called from any other function; <<_user_strerror>> can |
|
- | 332 | use this information to satisfy the POSIX rule that no other |
|
307 | routine named <<_user_strerror>>, and <[errnum]> passed to |
333 | standardized function can overwrite a static buffer reused by |
- | 334 | < |
|
- | 335 | <[error]> argument of <<_strerror_r>>; if a non-zero value is stored |
|
308 | < |
336 | into that location (usually <[EINVAL]>), then < |
- | 337 | < |
|
- | 338 | return that value instead of zero or <[ERANGE]>. <<_user_strerror>> |
|
309 | <<_user_strerror>> is called with <[errnum]> as its argument. |
339 | returns a <[char *]> value; returning <[NULL]> implies that the user |
Line 310... | Line 340... | ||
310 | 340 | function did not choose to handle <[errnum]>. The default |
|
Line 311... | Line 341... | ||
311 | <<_user_strerror>> takes one argument of type <[int]>, and returns a |
341 | <<_user_strerror>> returns <[NULL]> for all input values. Note that |
312 | character pointer. If <[errnum]> is unknown to <<_user_strerror>>, |
342 | <<_user_sterror>> must be thread-safe, and only denote errors via the |
Line 321... | Line 351... | ||
321 | 351 | ||
322 | #include |
352 | #include |
Line 323... | Line 353... | ||
323 | #include |
353 | #include |
324 | 354 | ||
- | 355 | char * |
|
- | 356 | _DEFUN (_strerror_r, (ptr, errnum, internal, errptr), |
|
- | 357 | struct _reent *ptr _AND |
|
325 | char * |
358 | int errnum _AND |
326 | _DEFUN (strerror, (errnum), |
359 | int internal _AND |
327 | int errnum) |
360 | int *errptr) |
328 | { |
361 | { |
Line 329... | Line 362... | ||
329 | char *error; |
362 | char *error; |
330 | extern char *_user_strerror _PARAMS ((int)); |
363 | extern char *_user_strerror _PARAMS ((int, int, int *)); |
- | 364 | ||
- | 365 | switch (errnum) |
|
- | 366 | { |
|
331 | 367 | case 0: |
|
332 | switch (errnum) |
368 | error = "Success"; |
333 | { |
369 | break; |
334 | /* go32 defines EPERM as EACCES */ |
370 | /* go32 defines EPERM as EACCES */ |
335 | #if defined (EPERM) && (!defined (EACCES) || (EPERM != EACCES)) |
371 | #if defined (EPERM) && (!defined (EACCES) || (EPERM != EACCES)) |
Line 782... | Line 818... | ||
782 | case ETIMEDOUT: |
818 | case ETIMEDOUT: |
783 | error = "Connection timed out"; |
819 | error = "Connection timed out"; |
784 | break; |
820 | break; |
785 | #endif |
821 | #endif |
786 | default: |
822 | default: |
- | 823 | if (!errptr) |
|
- | 824 | errptr = &ptr->_errno; |
|
787 | if ((error = _user_strerror (errnum)) == 0) |
825 | if ((error = _user_strerror (errnum, internal, errptr)) == 0) |
788 | error = ""; |
826 | error = ""; |
789 | break; |
827 | break; |
790 | } |
828 | } |
Line 791... | Line 829... | ||
791 | 829 | ||
792 | return error; |
830 | return error; |
- | 831 | } |
|
- | 832 | ||
- | 833 | char * |
|
- | 834 | _DEFUN(strerror, (int), |
|
- | 835 | int errnum) |
|
- | 836 | { |
|
- | 837 | return _strerror_r (_REENT, errnum, 0, NULL); |