[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tyndur-devel] [PATCH] strerror



Am Freitag, 11. Februar 2011, um 17:48:13 schrieb Arne Hasselbring:
> + strerror gibt jetzt nicht mehr "Unbekannter Fehler" zurück, sondern die
> zu errno gehörenden Fehlermeldungen
> 
> Signed-off-by: Arne Hasselbring <arne.hasselbring@xxxxxxxxxxxxxx>
> ---
>  src/modules/lib/posix/strerror.c |   67
> +++++++++++++++++++++++++++++++++++-- 1 files changed, 63 insertions(+), 4
> deletions(-)
> 
> diff --git a/src/modules/lib/posix/strerror.c
> b/src/modules/lib/posix/strerror.c index e08f3e0..ac3d84e 100644
> --- a/src/modules/lib/posix/strerror.c
> +++ b/src/modules/lib/posix/strerror.c
> @@ -38,11 +38,70 @@
>   *
>   * @return Pointer auf internen Buffer mit Fehlermeldung
>   */
> +
> +char *errno_messages[51] = {
Hier wäre ein MAX_ERRORS-Makro in der Header schöner

> +    "Result too large.",
> +    "Invalid argument.",
> +    "Not enough space.",
> +    "Interrupted function.",
> +    "No such file or directory.",
> +    "File exists.",
> +    "Bad file descriptor.",
> +    "Operation not permitted.",
> +    "I/O error.",
> +    "Cross-device link.",
> +    "Bad address.",
> +    "Argument list too long."
> +    "Not a directory.",
> +    "Permission denied.",
> +    "Too many open files.",
> +    "Executable file format error.",
> +    "No child processes.",
> +    "Resource unavailable, try again.",
> +    "Too many files open in system.",
> +    "Is a directory.",
> +    "No such device.",
> +    "Inappropriate I/O control operation.",
> +    "Mathematics argument out of domain of function.",
> +    "No such device or address.",
> +    "No such process.",
> +    "Broken pipe.",
> +    "Illegal byte sequence.",
> +
> +
> +    "Address family not supported.",
> +    "Connection timed out.",
> +    "Protocol wrong type for socket.",
> +    "Connection refused.",
> +    "The socket is not connected.",
> +    "Connection reset.",
> +    "Operation in progress.",
> +    "Connection already in progress.",
> +    "Socket is connected.",
> +
> +
> +    "Operation not supported on socket.",
> +    "Read-only file system.",
> +    "No space left on device.",
> +    "Device or resource busy.",
> +    "Value too large to be stored in data type.",
> +    "File too large.",
> +    "Resource deadlock would occur.",
> +    "Address not available.",
> +    "Function not supported.",
> +    "Filename too long.",
> +    "Invalid seek.",
> +    "Too many links.",
> +    "Directory not empty.",
> +
> +
> +    "Host is unreachable.",
> +    "Message too large.",
> +    "Protocol error.",
Würde ich lieber als
...
[EBLABLA] = "BlaBla",
...
machen, das hält besser.

> +};
> +
>  char* strerror(int error_code)
>  {
> -    static char error_message[64];
> -    snprintf(error_message, sizeof(error_message),
> -        "Unbekannter Fehler %d", error_code);
> -    return error_message;
> +    return errno_messages[error_code - 1];
Und hier dann die -1 entfernen

>  }