Tue, 13 Aug 2013 13:51:00 +0200
added some error messages
/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 2013 Olaf Wintermann. 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 HOLDER 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. */ /** * @file utils.h * * Common utilities like compare and copy functions. * * @author Mike Becker * @author Olaf Wintermann */ #ifndef UCX_UTILS_H #define UCX_UTILS_H #ifdef __cplusplus extern "C" { #endif #include "ucx.h" #include <string.h> /** * Copies a string. * @param s the string to copy * @param data omitted * @return a pointer to a copy of s1 that can be passed to free(void*) */ void *ucx_strcpy(void *s, void *data); /** * Copies a memory area. * @param m a pointer to the memory area * @param n a pointer to the size_t containing the size of the memory area * @return a pointer to a copy of the specified memory area that can * be passed to free(void*) */ void *ucx_memcpy(void *m, void *n); /** * Wraps the strcmp function. * @param s1 string one * @param s2 string two * @param data omitted * @return the result of strcmp(s1, s2) */ int ucx_strcmp(void *s1, void *s2, void *data); /** * Wraps the strncmp function. * @param s1 string one * @param s2 string two * @param n a pointer to the size_t containing the third strncmp parameter * @return the result of strncmp(s1, s2, *n) */ int ucx_strncmp(void *s1, void *s2, void *n); /** * Compares two integers of type int. * @param i1 pointer to integer one * @param i2 pointer to integer two * @param data omitted * @return -1, if *i1 is less than *i2, 0 if both are equal, * 1 if *i1 is greater than *i2 */ int ucx_intcmp(void *i1, void *i2, void *data); /** * Compares two real numbers of type float. * @param f1 pointer to float one * @param f2 pointer to float two * @param if provided: a pointer to precision (default: 1e-6f) * @return -1, if *f1 is less than *f2, 0 if both are equal, * 1 if *f1 is greater than *f2 */ int ucx_floatcmp(void *f1, void *f2, void *data); /** * Compares two real numbers of type double. * @param f1 pointer to double one * @param f2 pointer to double two * @param if provided: a pointer to precision (default: 1e-14) * @return -1, if *d1 is less than *d2, 0 if both are equal, * 1 if *d1 is greater than *d2 */ int ucx_doublecmp(void *d1, void *d2, void *data); /** * Compares two pointers. * @param ptr1 pointer one * @param ptr2 pointer two * @param data omitted * @return -1 if ptr1 is less than ptr2, 0 if both are equal, * 1 if ptr1 is greater than ptr2 */ int ucx_ptrcmp(void *ptr1, void *ptr2, void *data); /** * Compares two memory areas. * @param ptr1 pointer one * @param ptr2 pointer two * @param n a pointer to the size_t containing the third parameter for memcmp * @return the result of memcmp(ptr1, ptr2, *n) */ int ucx_memcmp(void *ptr1, void *ptr2, void *n); #ifdef __cplusplus } #endif #endif /* UCX_UTILS_H */