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
30 # define _XOPEN_SOURCE 600
33 #include <string.h> // Needed for strerror_r() and size_t
36 # include <errno.h> // Needed for errno
39 #ifndef HAVE_STRERROR_R
42 /* Replacement strerror_r() function for systems that don't have any.
43 Note that this replacement function is NOT thread-safe! */
44 int mule_strerror_r(int errnum
, char *buf
, size_t buflen
)
47 if ((buf
== NULL
) || (buflen
== 0)) {
51 tmp
= strerror(errnum
);
56 strncpy(buf
, tmp
, buflen
- 1);
57 buf
[buflen
- 1] = '\0';
58 if (strlen(tmp
) >= buflen
) {
68 /* No way to get error description */
72 errno
= ENOSYS
; /* not implemented */
79 # ifdef STRERROR_R_CHAR_P
81 /* Replacement strerror_r() function for systems that return a char*. */
82 int mule_strerror_r(int errnum
, char *buf
, size_t buflen
)
84 char *tmp
= strerror_r(errnum
, buf
, buflen
);
88 } else if (tmp
!= buf
) {
89 if ((buf
== NULL
) || (buflen
== 0)) {
93 strncpy(buf
, tmp
, buflen
- 1);
94 buf
[buflen
- 1] = '\0';
95 if (strlen(tmp
) >= buflen
) {
106 /* Nothing to do, library strerror_r() is XSI-compliant. */
107 int mule_strerror_r(int errnum
, char *buf
, size_t buflen
)
109 return strerror_r(errnum
, buf
, buflen
);