ucx/ucx.c

Sat, 05 Dec 2020 11:54:58 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 05 Dec 2020 11:54:58 +0100
changeset 162
18892c0a9adc
parent 157
0b33b9396851
permissions
-rw-r--r--

ucx update

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

mercurial