Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6557 | serge | 1 | /* GNU variant of strerror_r. */ |
2 | /* |
||
3 | FUNCTION |
||
4 | < |
||
5 | |||
6 | INDEX |
||
7 | strerror_r |
||
8 | |||
9 | ANSI_SYNOPSIS |
||
10 | #include |
||
11 | #ifdef _GNU_SOURCE |
||
12 | char *strerror_r(int <[errnum]>, char *<[buffer]>, size_t <[n]>); |
||
13 | #else |
||
14 | int strerror_r(int <[errnum]>, char *<[buffer]>, size_t <[n]>); |
||
15 | #endif |
||
16 | |||
17 | TRAD_SYNOPSIS |
||
18 | #include |
||
19 | char *strerror_r(<[errnum]>, <[buffer]>, <[n]>) |
||
20 | int <[errnum]>; |
||
21 | char *<[buffer]>; |
||
22 | size_t <[n]>; |
||
23 | |||
24 | DESCRIPTION |
||
25 | < |
||
26 | string and copies the result into the supplied <[buffer]> for |
||
27 | a length up to <[n]>, including the NUL terminator. The value of |
||
28 | <[errnum]> is usually a copy of < |
||
29 | error number, the result is the empty string. |
||
30 | |||
31 | See < |
||
32 | |||
33 | RETURNS |
||
34 | There are two variants: the GNU version always returns a NUL-terminated |
||
35 | string, which is <[buffer]> if all went well, but which is another |
||
36 | pointer if <[n]> was too small (leaving <[buffer]> untouched). If the |
||
37 | return is not <[buffer]>, your application must not modify that string. |
||
38 | The POSIX version returns 0 on success, <[EINVAL]> if < |
||
39 | recognized, and <[ERANGE]> if <[n]> was too small. The variant chosen |
||
40 | depends on macros that you define before inclusion of < |
||
41 | |||
42 | PORTABILITY |
||
43 | < |
||
44 | < |
||
45 | This function is compliant only if <<_user_strerror>> is not provided, |
||
46 | or if it is thread-safe and uses separate storage according to whether |
||
47 | the second argument of that function is non-zero. For more details |
||
48 | on <<_user_strerror>>, see the < |
||
49 | |||
50 | POSIX states that the contents of <[buf]> are unspecified on error, |
||
51 | although this implementation guarantees a NUL-terminated string for |
||
52 | all except <[n]> of 0. |
||
53 | |||
54 | POSIX recommends that unknown <[errnum]> result in a message including |
||
55 | that value, however it is not a requirement and this implementation |
||
56 | provides only an empty string (unless you provide <<_user_strerror>>). |
||
57 | POSIX also recommends that unknown <[errnum]> fail with EINVAL even |
||
58 | when providing such a message, however it is not a requirement and |
||
59 | this implementation will return success if <<_user_strerror>> provided |
||
60 | a non-empty alternate string without assigning into its third argument. |
||
61 | |||
62 | < |
||
63 | |||
64 | */ |
||
65 | |||
66 | #undef __STRICT_ANSI__ |
||
67 | #define _GNU_SOURCE |
||
68 | #include |
||
69 | #include |
||
70 | #undef strerror_r |
||
71 | |||
72 | /* For backwards-compatible linking, this must be the GNU signature; |
||
73 | see xpg_strerror_r.c for the POSIX version. */ |
||
74 | char * |
||
75 | _DEFUN (strerror_r, (errnum, buffer, n), |
||
76 | int errnum _AND |
||
77 | char *buffer _AND |
||
78 | size_t n) |
||
79 | { |
||
80 | char *error = _strerror_r (_REENT, errnum, 1, NULL); |
||
81 | |||
82 | if (strlen (error) >= n) |
||
83 | return error; |
||
84 | return strcpy (buffer, error); |
||
85 | } |