src/ucx/ucx.c

Sat, 16 Apr 2022 14:36:08 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 16 Apr 2022 14:36:08 +0200
branch
webdav
changeset 288
7dd45173f68a
parent 254
4784c14aa639
permissions
-rw-r--r--

create pg test data

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

mercurial