Fri, 09 Aug 2013 14:36:54 +0200
documented mempool + some fixes
universe@103 | 1 | /* |
universe@103 | 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
universe@103 | 3 | * |
universe@103 | 4 | * Copyright 2013 Olaf Wintermann. All rights reserved. |
universe@103 | 5 | * |
universe@103 | 6 | * Redistribution and use in source and binary forms, with or without |
universe@103 | 7 | * modification, are permitted provided that the following conditions are met: |
universe@103 | 8 | * |
universe@103 | 9 | * 1. Redistributions of source code must retain the above copyright |
universe@103 | 10 | * notice, this list of conditions and the following disclaimer. |
universe@103 | 11 | * |
universe@103 | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
universe@103 | 13 | * notice, this list of conditions and the following disclaimer in the |
universe@103 | 14 | * documentation and/or other materials provided with the distribution. |
universe@103 | 15 | * |
universe@103 | 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
universe@103 | 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
universe@103 | 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
universe@103 | 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
universe@103 | 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
universe@103 | 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
universe@103 | 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
universe@103 | 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
universe@103 | 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
universe@103 | 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
universe@103 | 26 | * POSSIBILITY OF SUCH DAMAGE. |
universe@103 | 27 | */ |
universe@103 | 28 | |
universe@135 | 29 | /** |
universe@135 | 30 | * @file utils.h |
universe@135 | 31 | * |
universe@135 | 32 | * Common utilities like compare and copy functions. |
universe@135 | 33 | * |
universe@135 | 34 | * @author Mike Becker |
universe@135 | 35 | * @author Olaf Wintermann |
universe@135 | 36 | */ |
universe@135 | 37 | |
olaf@120 | 38 | #ifndef UCX_UTILS_H |
olaf@120 | 39 | #define UCX_UTILS_H |
universe@89 | 40 | |
universe@89 | 41 | #ifdef __cplusplus |
universe@89 | 42 | extern "C" { |
universe@89 | 43 | #endif |
universe@89 | 44 | |
universe@89 | 45 | #include "ucx.h" |
universe@89 | 46 | #include <string.h> |
universe@89 | 47 | |
universe@89 | 48 | /** |
universe@94 | 49 | * Copies a string. |
universe@94 | 50 | * @param s the string to copy |
universe@94 | 51 | * @param data omitted |
universe@94 | 52 | * @return a pointer to a copy of s1 that can be passed to free(void*) |
universe@94 | 53 | */ |
universe@94 | 54 | void *ucx_strcpy(void *s, void *data); |
universe@94 | 55 | |
universe@94 | 56 | /** |
universe@94 | 57 | * Copies a memory area. |
universe@94 | 58 | * @param m a pointer to the memory area |
universe@94 | 59 | * @param n a pointer to the size_t containing the size of the memory area |
universe@94 | 60 | * @return a pointer to a copy of the specified memory area that can |
universe@94 | 61 | * be passed to free(void*) |
universe@94 | 62 | */ |
universe@94 | 63 | void *ucx_memcpy(void *m, void *n); |
universe@94 | 64 | |
universe@94 | 65 | /** |
universe@89 | 66 | * Wraps the strcmp function. |
universe@89 | 67 | * @param s1 string one |
universe@89 | 68 | * @param s2 string two |
universe@89 | 69 | * @param data omitted |
universe@89 | 70 | * @return the result of strcmp(s1, s2) |
universe@89 | 71 | */ |
universe@89 | 72 | int ucx_strcmp(void *s1, void *s2, void *data); |
universe@89 | 73 | |
universe@89 | 74 | /** |
universe@89 | 75 | * Wraps the strncmp function. |
universe@89 | 76 | * @param s1 string one |
universe@89 | 77 | * @param s2 string two |
universe@89 | 78 | * @param n a pointer to the size_t containing the third strncmp parameter |
universe@89 | 79 | * @return the result of strncmp(s1, s2, *n) |
universe@89 | 80 | */ |
universe@89 | 81 | int ucx_strncmp(void *s1, void *s2, void *n); |
universe@89 | 82 | |
universe@89 | 83 | /** |
universe@89 | 84 | * Compares two integers of type int. |
universe@89 | 85 | * @param i1 pointer to integer one |
universe@89 | 86 | * @param i2 pointer to integer two |
universe@89 | 87 | * @param data omitted |
universe@89 | 88 | * @return -1, if *i1 is less than *i2, 0 if both are equal, |
universe@89 | 89 | * 1 if *i1 is greater than *i2 |
universe@89 | 90 | */ |
universe@89 | 91 | |
universe@89 | 92 | int ucx_intcmp(void *i1, void *i2, void *data); |
universe@89 | 93 | |
universe@89 | 94 | /** |
universe@92 | 95 | * Compares two real numbers of type float. |
universe@92 | 96 | * @param f1 pointer to float one |
universe@92 | 97 | * @param f2 pointer to float two |
universe@92 | 98 | * @param if provided: a pointer to precision (default: 1e-6f) |
universe@92 | 99 | * @return -1, if *f1 is less than *f2, 0 if both are equal, |
universe@92 | 100 | * 1 if *f1 is greater than *f2 |
universe@92 | 101 | */ |
universe@92 | 102 | |
universe@92 | 103 | int ucx_floatcmp(void *f1, void *f2, void *data); |
universe@92 | 104 | |
universe@92 | 105 | /** |
universe@92 | 106 | * Compares two real numbers of type double. |
universe@92 | 107 | * @param f1 pointer to double one |
universe@92 | 108 | * @param f2 pointer to double two |
universe@92 | 109 | * @param if provided: a pointer to precision (default: 1e-14) |
universe@92 | 110 | * @return -1, if *d1 is less than *d2, 0 if both are equal, |
universe@92 | 111 | * 1 if *d1 is greater than *d2 |
universe@92 | 112 | */ |
universe@92 | 113 | |
universe@92 | 114 | int ucx_doublecmp(void *d1, void *d2, void *data); |
universe@92 | 115 | |
universe@92 | 116 | /** |
universe@89 | 117 | * Compares two pointers. |
universe@89 | 118 | * @param ptr1 pointer one |
universe@89 | 119 | * @param ptr2 pointer two |
universe@89 | 120 | * @param data omitted |
universe@89 | 121 | * @return -1 if ptr1 is less than ptr2, 0 if both are equal, |
universe@89 | 122 | * 1 if ptr1 is greater than ptr2 |
universe@89 | 123 | */ |
universe@89 | 124 | int ucx_ptrcmp(void *ptr1, void *ptr2, void *data); |
universe@89 | 125 | |
universe@91 | 126 | /** |
universe@91 | 127 | * Compares two memory areas. |
universe@91 | 128 | * @param ptr1 pointer one |
universe@91 | 129 | * @param ptr2 pointer two |
universe@91 | 130 | * @param n a pointer to the size_t containing the third parameter for memcmp |
universe@91 | 131 | * @return the result of memcmp(ptr1, ptr2, *n) |
universe@91 | 132 | */ |
universe@91 | 133 | int ucx_memcmp(void *ptr1, void *ptr2, void *n); |
universe@91 | 134 | |
universe@89 | 135 | #ifdef __cplusplus |
universe@89 | 136 | } |
universe@89 | 137 | #endif |
universe@89 | 138 | |
olaf@120 | 139 | #endif /* UCX_UTILS_H */ |
universe@89 | 140 |