Mercurial > nomad > old-fuse
changeset 87:58f7ea854119
common: provide assfail and assfail3 on systems without it
We're assuming that if the system doesn't have these, it has C-style
__assert().
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Sat, 17 Oct 2015 08:45:04 -0400 |
parents | ee34323813e9 |
children | c81bc8ade080 |
files | cmake/config.cmake src/common/CMakeLists.txt src/common/assfail.c src/common/include/nomad/config.h.in |
diffstat | 4 files changed, 53 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/cmake/config.cmake Sat Oct 17 08:20:59 2015 -0400 +++ b/cmake/config.cmake Sat Oct 17 08:45:04 2015 -0400 @@ -24,6 +24,8 @@ check_function_exists(arc4random HAVE_ARC4RANDOM) check_function_exists(pthread_cond_reltimedwait_np HAVE_PTHREAD_COND_RELTIMEDWAIT_NP) +check_function_exists(assfail HAVE_ASSFAIL) +check_function_exists(assfail3 HAVE_ASSFAIL3) set(CMAKE_MODULE_PATH "${CMAKE_DIR}/Modules") find_package(umem)
--- a/src/common/CMakeLists.txt Sat Oct 17 08:20:59 2015 -0400 +++ b/src/common/CMakeLists.txt Sat Oct 17 08:45:04 2015 -0400 @@ -21,6 +21,7 @@ # add_library(nomad_common SHARED + assfail.c mutex.c node.c oid.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/common/assfail.c Sat Oct 17 08:45:04 2015 -0400 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2015 Josef 'Jeff' Sipek <jeffpc@josefsipek.net> + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include <stdio.h> +#include <inttypes.h> +#include <assert.h> + +#include <nomad/config.h> +#include <nomad/error.h> + +#ifndef HAVE_ASSFAIL +void assfail(const char *assertion, const char *file, int line) +{ + __assert(assertion, file, line); +} +#endif + +#ifndef HAVE_ASSFAIL3 +void assfail3(const char *assertion, uintmax_t lhs, const char *op, + uintmax_t rhs, const char *file, int line) +{ + char msg[512]; + + snprintf(msg, sizeof(msg), "%s (%#"PRIx64" %s %#"PRIx64")", + assertion, lhs, op, rhs); + + __assert(msg, file, line); +} +#endif
--- a/src/common/include/nomad/config.h.in Sat Oct 17 08:20:59 2015 -0400 +++ b/src/common/include/nomad/config.h.in Sat Oct 17 08:45:04 2015 -0400 @@ -25,5 +25,7 @@ #cmakedefine HAVE_ARC4RANDOM 1 #cmakedefine HAVE_PTHREAD_COND_RELTIMEDWAIT_NP 1 +#cmakedefine HAVE_ASSFAIL 1 +#cmakedefine HAVE_ASSFAIL3 1 #endif