| 1 | /* |
| 2 | * fstrcmp - fuzzy string compare library |
| 3 | * Copyright (C) 2009 Peter Miller |
| 4 | * Written by Peter Miller <[email protected]> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU Lesser General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or (at |
| 9 | * your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #include <lib/ac/stddef.h> |
| 21 | #include <lib/ac/stdlib.h> |
| 22 | #include <lib/ac/string.h> |
| 23 | #include <lib/ac/stdio.h> |
| 24 | |
| 25 | #include <lib/gcc_attributes.h> |
| 26 | |
| 27 | |
| 28 | /* |
| 29 | * NAME |
| 30 | * strerror - string for error number |
| 31 | * |
| 32 | * SYNOPSIS |
| 33 | * char *strerror(int errnum); |
| 34 | * |
| 35 | * DESCRIPTION |
| 36 | * The strerror function maps the error number in errnum to an error |
| 37 | * message string. |
| 38 | * |
| 39 | * RETURNS |
| 40 | * The strerror function returns a pointer to the string, the contents of |
| 41 | * which are implementation-defined. The array pointed to shall not be |
| 42 | * modified by the program, but may be overwritten by a subsequent call to |
| 43 | * the strerror function. |
| 44 | * |
| 45 | * CAVEAT |
| 46 | * Unknown errors will be rendered in the form "Error %d", where %d will |
| 47 | * be replaced by a decimal representation of the error number. |
| 48 | */ |
| 49 | |
| 50 | #ifndef HAVE_STRERROR |
| 51 | |
| 52 | LINKAGE_HIDDEN |
| 53 | char * |
| 54 | strerror(int n) |
| 55 | { |
| 56 | extern int sys_nerr; |
| 57 | extern char *sys_errlist[]; |
| 58 | static char buffer[16]; |
| 59 | |
| 60 | if (n < 1 || n > sys_nerr) |
| 61 | { |
| 62 | sprintf(buffer, "Error %d", n); |
| 63 | return buffer; |
| 64 | } |
| 65 | return sys_errlist[n]; |
| 66 | } |
| 67 | |
| 68 | #endif /* !HAVE_STRERROR */ |