X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fperror.c;h=af4b56cd406a27b5af33461e869b9b848a9c17a2;hb=6e33eaed1cd5ddcdfc48476059012fed68f71f8e;hp=80cdeffb75a7bacf36516657ab12a6944f3f5991;hpb=3030c5b5e0a5199e16b05927da72c43c42f211c3;p=gnulib.git diff --git a/lib/perror.c b/lib/perror.c index 80cdeffb7..af4b56cd4 100644 --- a/lib/perror.c +++ b/lib/perror.c @@ -1,5 +1,5 @@ /* Print a message describing error code. - Copyright (C) 2008, 2009 Free Software Foundation, Inc. + Copyright (C) 2008-2011 Free Software Foundation, Inc. Written by Bruno Haible and Simon Josefsson. This program is free software: you can redistribute it and/or modify @@ -21,15 +21,29 @@ #include #include +#include #include +#include "strerror-override.h" + +/* Use the system functions, not the gnulib overrides in this file. */ +#undef fprintf + void perror (const char *string) { - const char *errno_description = strerror (errno); + char stackbuf[STACKBUF_LEN]; + int ret; + + /* Our implementation guarantees that this will be a non-empty + string, even if it returns EINVAL; and stackbuf should be sized + large enough to avoid ERANGE. */ + ret = strerror_r (errno, stackbuf, sizeof stackbuf); + if (ret == ERANGE) + abort (); if (string != NULL && *string != '\0') - fprintf (stderr, "%s: %s\n", string, errno_description); + fprintf (stderr, "%s: %s\n", string, stackbuf); else - fprintf (stderr, "%s\n", errno_description); + fprintf (stderr, "%s\n", stackbuf); }