Tue, 23 Jul 2013 12:54:45 +0200
added ssize_t typedef for windows
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2013 Olaf Wintermann. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28 /**
29 * Main UCX Header providing most common definitions.
30 *
31 * @file ucx.h
32 * @author Mike Becker
33 * @author Olaf Wintermann
34 */
36 #ifndef UCX_H
37 #define UCX_H
39 #include <stdlib.h>
41 #ifdef _WIN32
42 #ifndef __ssize_t_defined
43 #include <BaseTsd.h>
44 typedef SSIZE_T ssize_t;
45 #define __ssize_t_defined
46 #endif /* __ssize_t_defined */
47 #else /* !_WIN32 */
48 #include <sys/types.h>
49 #endif /* _WIN32 */
51 #ifdef __cplusplus
52 #ifndef _Bool
53 #define _Bool bool
54 #define restrict
55 #endif
56 extern "C" {
57 #endif
59 /**
60 * Function pointer to a compare function.
61 *
62 * The compare function shall take three arguments: the two values that shall be
63 * compared and optional additional data.
64 * The function shall then return -1 if the first argument is less than the
65 * second argument, 1 if the first argument is greater than the second argument
66 * and 0 if both arguments are equal. If the third argument is
67 * <code>NULL</code>, it shall be ignored.
68 */
69 typedef int(*cmp_func)(void*,void*,void*);
71 /**
72 * Function pointer to a copy function.
73 *
74 * The copy function shall create a copy of the first argument and may use
75 * additional data provided by the second argument. If the second argument is
76 * <code>NULL</code>, it shall be ignored.
78 * <b>Attention:</b> if pointers returned by functions of this type may be
79 * passed to <code>free()</code> depends on the implementation of the
80 * respective <code>copy_func</code>.
81 */
82 typedef void*(*copy_func)(void*,void*);
84 /**
85 * Function pointer to a write function.
86 *
87 * The signature of the write function shall be compatible to the signature
88 * of standard <code>fwrite</code>, though it may use arbitrary data types for
89 * source and destination.
90 *
91 * The arguments shall contain (in ascending order): a pointer to the source,
92 * the length of one element, the element count and a pointer to the
93 * destination.
94 */
95 typedef size_t(*write_func)(const void*, size_t, size_t, void*);
97 /**
98 * Function pointer to a read function.
99 *
100 * The signature of the read function shall be compatible to the signature
101 * of standard <code>fread</code>, though it may use arbitrary data types for
102 * source and destination.
103 *
104 * The arguments shall contain (in ascending order): a pointer to the
105 * destination, the length of one element, the element count and a pointer to
106 * the source.
107 */
108 typedef size_t(*read_func)(void*, size_t, size_t, void*);
110 #ifdef __cplusplus
111 }
112 #endif
114 #endif /* UCX_H */