From 3896b8c5fe0b0058310a8135660fb74822a89ede Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Wed, 30 Jan 2008 13:48:56 +0000 Subject: one more strerror_r fix ;) --- pidfile.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/pidfile.c b/pidfile.c index e153a4ed..a0b41579 100644 --- a/pidfile.c +++ b/pidfile.c @@ -39,6 +39,21 @@ #include #endif + +static char *rs_strerror_r(int errnum, char *buf, size_t buflen) { +#ifdef STRERROR_R_CHAR_P + char *p = strerror_r(errnum, buf, buflen); + if (p != buf) { + strncpy(buf, p, buflen); + buf[buflen - 1] = '\0'; + } +#else + strerror_r(errnum, buf, buflen); +#endif + return buf; +} + + /* read_pid * * Reads the specified pidfile and returns the read pid. @@ -120,7 +135,7 @@ int write_pid (char *pidfile) pid = getpid(); if (!fprintf(f,"%d\n", pid)) { char errStr[1024]; - strerror_r(errno, errStr, sizeof(errStr)); + rs_strerror_r(errno, errStr, sizeof(errStr)); printf("Can't write pid , %s.\n", errStr); close(fd); return 0; @@ -130,7 +145,7 @@ int write_pid (char *pidfile) #ifndef __sun if (flock(fd, LOCK_UN) == -1) { char errStr[1024]; - strerror_r(errno, errStr, sizeof(errStr)); + rs_strerror_r(errno, errStr, sizeof(errStr)); printf("Can't unlock pidfile %s, %s.\n", pidfile, errStr); close(fd); return 0; -- cgit