2 * This file is part of the aMule Project.
4 * Copyright (c) 2011 aMule Team ( admin@amule.org / http://www.amule.org )
6 * Any parts of this program derived from the xMule, lMule or eMule project,
7 * or contributed by third-party developers are copyrighted by their
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 # define _XOPEN_SOURCE 600
31 #include <string.h> /* Needed for strerror_r() and size_t */
34 # include <errno.h> /* Needed for errno */
37 #ifndef HAVE_STRERROR_R
40 /* Replacement strerror_r() function for systems that don't have any.
41 Note that this replacement function is NOT thread-safe! */
42 int mule_strerror_r(int errnum
, char *buf
, size_t buflen
)
45 if ((buf
== NULL
) || (buflen
== 0)) {
49 tmp
= strerror(errnum
);
54 strncpy(buf
, tmp
, buflen
- 1);
55 buf
[buflen
- 1] = '\0';
56 if (strlen(tmp
) >= buflen
) {
66 /* No way to get error description */
70 errno
= ENOSYS
; /* not implemented */
77 # ifdef STRERROR_R_CHAR_P
79 /* Replacement strerror_r() function for systems that return a char*. */
80 int mule_strerror_r(int errnum
, char *buf
, size_t buflen
)
82 char *tmp
= strerror_r(errnum
, buf
, buflen
);
86 } else if (tmp
!= buf
) {
87 if ((buf
== NULL
) || (buflen
== 0)) {
91 strncpy(buf
, tmp
, buflen
- 1);
92 buf
[buflen
- 1] = '\0';
93 if (strlen(tmp
) >= buflen
) {
104 /* Nothing to do, library strerror_r() is XSI-compliant. */
105 int mule_strerror_r(int errnum
, char *buf
, size_t buflen
)
107 return strerror_r(errnum
, buf
, buflen
);