src/ucx.c

Mon, 14 May 2018 18:12:14 +0200

author
Mike Becker <universe@uap-core.de>
date
Mon, 14 May 2018 18:12:14 +0200
changeset 308
d6f580621512
parent 273
9c1591b3c4a4
child 331
3b985a4eb05b
permissions
-rw-r--r--

renames ucx_strcmp() to ucx_cmp_str()

114
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /**
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * @mainpage UAP Common Extensions
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 * Library with common and useful functions, macros and data structures.
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * <p>
259
2f5dea574a75 modules documentation
Mike Becker <universe@uap-core.de>
parents: 251
diff changeset
5 * Latest available source:<br>
2f5dea574a75 modules documentation
Mike Becker <universe@uap-core.de>
parents: 251
diff changeset
6 * <a href="https://sourceforge.net/projects/ucx/files/">
2f5dea574a75 modules documentation
Mike Becker <universe@uap-core.de>
parents: 251
diff changeset
7 * https://sourceforge.net/projects/ucx/files/</a>
2f5dea574a75 modules documentation
Mike Becker <universe@uap-core.de>
parents: 251
diff changeset
8 * </p>
2f5dea574a75 modules documentation
Mike Becker <universe@uap-core.de>
parents: 251
diff changeset
9 *
2f5dea574a75 modules documentation
Mike Becker <universe@uap-core.de>
parents: 251
diff changeset
10 * <p>
2f5dea574a75 modules documentation
Mike Becker <universe@uap-core.de>
parents: 251
diff changeset
11 * Repositories:<br>
263
3ff0abc49ed5 fixes sourceforge link in doxygen doc
Mike Becker <universe@uap-core.de>
parents: 262
diff changeset
12 * <a href="https://sourceforge.net/p/ucx/code">
3ff0abc49ed5 fixes sourceforge link in doxygen doc
Mike Becker <universe@uap-core.de>
parents: 262
diff changeset
13 * https://sourceforge.net/p/ucx/code</a>
259
2f5dea574a75 modules documentation
Mike Becker <universe@uap-core.de>
parents: 251
diff changeset
14 * -&nbsp;or&nbsp;-
114
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 * <a href="https://develop.uap-core.de/hg/ucx">
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * https://develop.uap-core.de/hg/ucx</a>
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * </p>
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 *
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * <h2>LICENCE</h2>
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 *
259
2f5dea574a75 modules documentation
Mike Becker <universe@uap-core.de>
parents: 251
diff changeset
21 * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved.
114
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 *
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * Redistribution and use in source and binary forms, with or without
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 * modification, are permitted provided that the following conditions are met:
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 *
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 * 1. Redistributions of source code must retain the above copyright
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 * notice, this list of conditions and the following disclaimer.
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28 *
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 * 2. Redistributions in binary form must reproduce the above copyright
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30 * notice, this list of conditions and the following disclaimer in the
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31 * documentation and/or other materials provided with the distribution.
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32 *
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
42 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
43 * POSSIBILITY OF SUCH DAMAGE.
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
44 */
5a0859739b76 added doxyfile and documentation for ucx.h
Mike Becker <universe@uap-core.de>
parents:
diff changeset
45
251
fae240d633fc changes source directory structure in preperation for autotools rollout
Mike Becker <universe@uap-core.de>
parents: 250
diff changeset
46 #include "ucx/ucx.h"
270
3d80d425543b adds integer overflow checks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 263
diff changeset
47
3d80d425543b adds integer overflow checks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 263
diff changeset
48 #ifndef UCX_MUL_BUILTIN
3d80d425543b adds integer overflow checks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 263
diff changeset
49 int ucx_szmul(size_t a, size_t b, size_t *result) {
3d80d425543b adds integer overflow checks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 263
diff changeset
50 if(a == 0 || b == 0) {
3d80d425543b adds integer overflow checks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 263
diff changeset
51 *result = 0;
273
9c1591b3c4a4 fixes return value for multiplication with zero in ucx_szmul
Mike Becker <universe@uap-core.de>
parents: 270
diff changeset
52 return 0;
270
3d80d425543b adds integer overflow checks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 263
diff changeset
53 }
3d80d425543b adds integer overflow checks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 263
diff changeset
54 size_t r = a * b;
3d80d425543b adds integer overflow checks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 263
diff changeset
55 if(r / b == a) {
3d80d425543b adds integer overflow checks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 263
diff changeset
56 *result = r;
3d80d425543b adds integer overflow checks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 263
diff changeset
57 return 0;
3d80d425543b adds integer overflow checks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 263
diff changeset
58 } else {
3d80d425543b adds integer overflow checks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 263
diff changeset
59 *result = 0;
3d80d425543b adds integer overflow checks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 263
diff changeset
60 return 1;
3d80d425543b adds integer overflow checks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 263
diff changeset
61 }
3d80d425543b adds integer overflow checks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 263
diff changeset
62 }
3d80d425543b adds integer overflow checks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 263
diff changeset
63 #endif
273
9c1591b3c4a4 fixes return value for multiplication with zero in ucx_szmul
Mike Becker <universe@uap-core.de>
parents: 270
diff changeset
64

mercurial