X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fperror.c;h=af4b56cd406a27b5af33461e869b9b848a9c17a2;hb=50901279d8e42ea4bccc2eef0a6b11e7c3dde4cf;hp=2c13a8941ada66ff963cd8aaa5de9d450f609c4f;hpb=d60f3b0c6b0f93a601acd1cfd3923f94ca05abb0;p=gnulib.git diff --git a/lib/perror.c b/lib/perror.c index 2c13a8941..af4b56cd4 100644 --- a/lib/perror.c +++ b/lib/perror.c @@ -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); }