ucx/utils.h

Sat, 20 Jul 2013 11:13:26 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 20 Jul 2013 11:13:26 +0200
changeset 120
8170f658f017
parent 103
08018864fb91
child 135
a0aa1c15f46b
permissions
-rw-r--r--

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
olaf@120 29 #ifndef UCX_UTILS_H
olaf@120 30 #define UCX_UTILS_H
universe@89 31
universe@89 32 #ifdef __cplusplus
universe@89 33 extern "C" {
universe@89 34 #endif
universe@89 35
universe@89 36 #include "ucx.h"
universe@89 37 #include <string.h>
universe@89 38
universe@89 39 /**
universe@94 40 * Copies a string.
universe@94 41 * @param s the string to copy
universe@94 42 * @param data omitted
universe@94 43 * @return a pointer to a copy of s1 that can be passed to free(void*)
universe@94 44 */
universe@94 45 void *ucx_strcpy(void *s, void *data);
universe@94 46
universe@94 47 /**
universe@94 48 * Copies a memory area.
universe@94 49 * @param m a pointer to the memory area
universe@94 50 * @param n a pointer to the size_t containing the size of the memory area
universe@94 51 * @return a pointer to a copy of the specified memory area that can
universe@94 52 * be passed to free(void*)
universe@94 53 */
universe@94 54 void *ucx_memcpy(void *m, void *n);
universe@94 55
universe@94 56 /**
universe@89 57 * Wraps the strcmp function.
universe@89 58 * @param s1 string one
universe@89 59 * @param s2 string two
universe@89 60 * @param data omitted
universe@89 61 * @return the result of strcmp(s1, s2)
universe@89 62 */
universe@89 63 int ucx_strcmp(void *s1, void *s2, void *data);
universe@89 64
universe@89 65 /**
universe@89 66 * Wraps the strncmp function.
universe@89 67 * @param s1 string one
universe@89 68 * @param s2 string two
universe@89 69 * @param n a pointer to the size_t containing the third strncmp parameter
universe@89 70 * @return the result of strncmp(s1, s2, *n)
universe@89 71 */
universe@89 72 int ucx_strncmp(void *s1, void *s2, void *n);
universe@89 73
universe@89 74 /**
universe@89 75 * Compares two integers of type int.
universe@89 76 * @param i1 pointer to integer one
universe@89 77 * @param i2 pointer to integer two
universe@89 78 * @param data omitted
universe@89 79 * @return -1, if *i1 is less than *i2, 0 if both are equal,
universe@89 80 * 1 if *i1 is greater than *i2
universe@89 81 */
universe@89 82
universe@89 83 int ucx_intcmp(void *i1, void *i2, void *data);
universe@89 84
universe@89 85 /**
universe@92 86 * Compares two real numbers of type float.
universe@92 87 * @param f1 pointer to float one
universe@92 88 * @param f2 pointer to float two
universe@92 89 * @param if provided: a pointer to precision (default: 1e-6f)
universe@92 90 * @return -1, if *f1 is less than *f2, 0 if both are equal,
universe@92 91 * 1 if *f1 is greater than *f2
universe@92 92 */
universe@92 93
universe@92 94 int ucx_floatcmp(void *f1, void *f2, void *data);
universe@92 95
universe@92 96 /**
universe@92 97 * Compares two real numbers of type double.
universe@92 98 * @param f1 pointer to double one
universe@92 99 * @param f2 pointer to double two
universe@92 100 * @param if provided: a pointer to precision (default: 1e-14)
universe@92 101 * @return -1, if *d1 is less than *d2, 0 if both are equal,
universe@92 102 * 1 if *d1 is greater than *d2
universe@92 103 */
universe@92 104
universe@92 105 int ucx_doublecmp(void *d1, void *d2, void *data);
universe@92 106
universe@92 107 /**
universe@89 108 * Compares two pointers.
universe@89 109 * @param ptr1 pointer one
universe@89 110 * @param ptr2 pointer two
universe@89 111 * @param data omitted
universe@89 112 * @return -1 if ptr1 is less than ptr2, 0 if both are equal,
universe@89 113 * 1 if ptr1 is greater than ptr2
universe@89 114 */
universe@89 115 int ucx_ptrcmp(void *ptr1, void *ptr2, void *data);
universe@89 116
universe@91 117 /**
universe@91 118 * Compares two memory areas.
universe@91 119 * @param ptr1 pointer one
universe@91 120 * @param ptr2 pointer two
universe@91 121 * @param n a pointer to the size_t containing the third parameter for memcmp
universe@91 122 * @return the result of memcmp(ptr1, ptr2, *n)
universe@91 123 */
universe@91 124 int ucx_memcmp(void *ptr1, void *ptr2, void *n);
universe@91 125
universe@89 126 #ifdef __cplusplus
universe@89 127 }
universe@89 128 #endif
universe@89 129
olaf@120 130 #endif /* UCX_UTILS_H */
universe@89 131

mercurial