From b7cd97981cd4d5534cd0437d27564899047f0ac7 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sun, 10 Mar 2013 22:12:07 +0100 Subject: [PATCH] Moved sdb_strerror() from utils/string.h to utils/error.h. --- src/Makefile.am | 4 +- src/backend/collectd.c | 1 - src/backend/mk-livestatus.c | 1 - src/backend/puppet-storeconfigs.c | 1 - src/core/plugin.c | 1 - src/core/store.c | 1 - src/daemon/sysdbd.c | 1 - src/include/utils/error.h | 10 +++++ src/include/utils/string.h | 47 ----------------------- src/utils/error.c | 25 ++++++++++++ src/utils/string.c | 63 ------------------------------- src/utils/time.c | 1 - src/utils/unixsock.c | 1 - 13 files changed, 36 insertions(+), 121 deletions(-) delete mode 100644 src/include/utils/string.h delete mode 100644 src/utils/string.c diff --git a/src/Makefile.am b/src/Makefile.am index 9de8dd0..8b438f6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -13,8 +13,7 @@ pkgcoreinclude_HEADERS = \ include/core/plugin.h pkgutilsincludedir = $(pkgincludedir)/utils pkgutilsinclude_HEADERS = \ - include/utils/llist.h \ - include/utils/string.h + include/utils/llist.h lib_LTLIBRARIES = libsysdb.la @@ -26,7 +25,6 @@ libsysdb_la_SOURCES = \ include/utils/data.h \ utils/error.c include/utils/error.h \ utils/llist.c include/utils/llist.h \ - utils/string.c include/utils/string.h \ utils/time.c include/utils/time.h \ utils/unixsock.c include/utils/unixsock.h libsysdb_la_CFLAGS = $(AM_CFLAGS) diff --git a/src/backend/collectd.c b/src/backend/collectd.c index 312d7ac..2ace8e1 100644 --- a/src/backend/collectd.c +++ b/src/backend/collectd.c @@ -29,7 +29,6 @@ #include "core/plugin.h" #include "core/store.h" #include "utils/error.h" -#include "utils/string.h" #include "utils/unixsock.h" #include "liboconfig/utils.h" diff --git a/src/backend/mk-livestatus.c b/src/backend/mk-livestatus.c index 5d8c377..87c44de 100644 --- a/src/backend/mk-livestatus.c +++ b/src/backend/mk-livestatus.c @@ -29,7 +29,6 @@ #include "core/plugin.h" #include "core/store.h" #include "utils/error.h" -#include "utils/string.h" #include "utils/unixsock.h" #include "liboconfig/utils.h" diff --git a/src/backend/puppet-storeconfigs.c b/src/backend/puppet-storeconfigs.c index d55b764..5549f77 100644 --- a/src/backend/puppet-storeconfigs.c +++ b/src/backend/puppet-storeconfigs.c @@ -30,7 +30,6 @@ #include "core/store.h" #include "utils/error.h" #include "utils/dbi.h" -#include "utils/string.h" #include "liboconfig/utils.h" diff --git a/src/core/plugin.c b/src/core/plugin.c index 99f07cb..306f5e9 100644 --- a/src/core/plugin.c +++ b/src/core/plugin.c @@ -29,7 +29,6 @@ #include "core/plugin.h" #include "utils/error.h" #include "utils/llist.h" -#include "utils/string.h" #include "utils/time.h" #include diff --git a/src/core/store.c b/src/core/store.c index 3901ba4..0496810 100644 --- a/src/core/store.c +++ b/src/core/store.c @@ -29,7 +29,6 @@ #include "core/store.h" #include "utils/error.h" #include "utils/llist.h" -#include "utils/string.h" #include diff --git a/src/daemon/sysdbd.c b/src/daemon/sysdbd.c index 5a901a2..fa31490 100644 --- a/src/daemon/sysdbd.c +++ b/src/daemon/sysdbd.c @@ -33,7 +33,6 @@ #include "core/plugin.h" #include "core/store.h" #include "utils/error.h" -#include "utils/string.h" #include "daemon/config.h" diff --git a/src/include/utils/error.h b/src/include/utils/error.h index 73b48ba..487b6e4 100644 --- a/src/include/utils/error.h +++ b/src/include/utils/error.h @@ -39,6 +39,8 @@ #ifndef SDB_UTILS_ERROR_H #define SDB_UTILS_ERROR_H 1 +#include + #ifdef __cplusplus extern "C" { #endif @@ -114,6 +116,14 @@ sdb_error_get(void); int sdb_error_get_prio(void); +/* + * sdb_strerror: + * This is a wrapper around the system's strerror function which ensures that + * a pointer to the formatted error message is returned. + */ +char * +sdb_strerror(int errnum, char *strerrbuf, size_t buflen); + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/src/include/utils/string.h b/src/include/utils/string.h deleted file mode 100644 index 7f0a7a3..0000000 --- a/src/include/utils/string.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * SysDB - src/include/utils/string.h - * Copyright (C) 2012 Sebastian 'tokkee' Harl - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SDB_UTILS_STRING_H -#define SDB_UTILS_STRING_H 1 - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -char * -sdb_strerror(int errnum, char *strerrbuf, size_t buflen); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* ! SDB_UTILS_STRING_H */ - -/* vim: set tw=78 sw=4 ts=4 noexpandtab : */ - diff --git a/src/utils/error.c b/src/utils/error.c index 7eef712..6bb17d5 100644 --- a/src/utils/error.c +++ b/src/utils/error.c @@ -243,5 +243,30 @@ sdb_error_get_prio(void) return ctx->prio; } /* sdb_error_get_prio */ +char * +sdb_strerror(int errnum, char *strerrbuf, size_t buflen) +{ +#if STRERROR_R_CHAR_P + { + char *tmp = strerror_r(errnum, strerrbuf, buflen); + if (*strerrbuf = '\0') { + if (tmp && (tmp != strerrbuf) && (*tmp != '\0')) + strncpy(strerrbuf, tmp, buflen); + else + snprintf(strerrbuf, buflen, "unknown error #%i " + "(strerror_r(3) did not return an error message)", + errnum); + } + } +#else + if (strerror_r(errnum, strerrbuf, buflen)) + snprintf(strerrbuf, buflen, "unknown error #%i " + "(strerror_r(3) failed)", errnum); +#endif + + strerrbuf[buflen - 1] = '\0'; + return strerrbuf; +} /* sdb_strerror */ + /* vim: set tw=78 sw=4 ts=4 noexpandtab : */ diff --git a/src/utils/string.c b/src/utils/string.c deleted file mode 100644 index 4fa9def..0000000 --- a/src/utils/string.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SysDB - src/utils/string.c - * Copyright (C) 2012 Sebastian 'tokkee' Harl - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "utils/string.h" - -#include -#include - -/* - * public API - */ - -char * -sdb_strerror(int errnum, char *strerrbuf, size_t buflen) -{ -#if STRERROR_R_CHAR_P - { - char *tmp = strerror_r(errnum, strerrbuf, buflen); - if (*strerrbuf = '\0') { - if (tmp && (tmp != strerrbuf) && (*tmp != '\0')) - strncpy(strerrbuf, tmp, buflen); - else - snprintf(strerrbuf, buflen, "unknown error #%i " - "(strerror_r(3) did not return an error message)", - errnum); - } - } -#else - if (strerror_r(errnum, strerrbuf, buflen)) - snprintf(strerrbuf, buflen, "unknown error #%i " - "(strerror_r(3) failed)", errnum); -#endif - - strerrbuf[buflen - 1] = '\0'; - return strerrbuf; -} /* sdb_strerror */ - -/* vim: set tw=78 sw=4 ts=4 noexpandtab : */ - diff --git a/src/utils/time.c b/src/utils/time.c index e3aa5c1..4823205 100644 --- a/src/utils/time.c +++ b/src/utils/time.c @@ -26,7 +26,6 @@ */ #include "utils/time.h" -#include "utils/string.h" #include diff --git a/src/utils/unixsock.c b/src/utils/unixsock.c index 08233f8..bc9806c 100644 --- a/src/utils/unixsock.c +++ b/src/utils/unixsock.c @@ -27,7 +27,6 @@ #include "utils/unixsock.h" #include "utils/error.h" -#include "utils/string.h" #include #include -- 2.30.2