From ca35976927190883368ef3bd32bbf9f174575bd6 Mon Sep 17 00:00:00 2001 From: ajs Date: Fri, 19 Nov 2004 23:40:16 +0000 Subject: 2004-11-19 David Young * log.c: (safe_strerror) New function: safe wrapper for strerror. --- lib/ChangeLog | 4 ++++ lib/log.c | 8 ++++++++ lib/log.h | 3 +++ 3 files changed, 15 insertions(+) (limited to 'lib') diff --git a/lib/ChangeLog b/lib/ChangeLog index 06b46258..75cf8449 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,7 @@ +2004-11-19 David Young + + * log.c: (safe_strerror) New function: safe wrapper for strerror. + 2004-11-19 Andrew J. Schorr * sockopt.c: (setsockopt_so_recvbuf) Stop error message from being diff --git a/lib/log.c b/lib/log.c index 375730f2..b24dacd8 100644 --- a/lib/log.c +++ b/lib/log.c @@ -498,3 +498,11 @@ mes_lookup (struct message *meslist, int max, int index) } return meslist[index].str; } + +/* Wrapper around strerror to handle case where it returns NULL. */ +const char * +safe_strerror(int errnum) +{ + const char *s = strerror(errnum); + return (s != NULL) ? s : "Unknown error"; +} diff --git a/lib/log.h b/lib/log.h index 9f6ec3be..b5dbdfe1 100644 --- a/lib/log.h +++ b/lib/log.h @@ -126,4 +126,7 @@ const char *mes_lookup (struct message *meslist, int max, int index); extern const char *zlog_priority[]; +/* Safe version of strerror -- never returns NULL. */ +extern const char *safe_strerror(int errnum); + #endif /* _ZEBRA_LOG_H */ -- cgit v1.2.1