projects/libpws

view pws-internal.h @ 13:2bb1bbac1d0a

Added tag version-1.0.0 for changeset 1926dfc9feb0
author Guido Berhoerster <guido+libpws@berhoerster.name>
date Sun Aug 04 21:37:56 2019 +0200 (2019-08-04)
parents
children
line source
1 /*
2 * Copyright (C) 2015 Guido Berhoerster <guido+libpws@berhoerster.name>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
24 #ifndef PWS_INTERNAL_H
25 #define PWS_INTERNAL_H
27 #include <signal.h>
28 #ifdef HAVE_SYS_TREE_H
29 #include <sys/tree.h>
30 #endif /* HAVE_SYS_TREE_H */
31 #include <sys/types.h>
32 #include <unistd.h>
34 #include "include/pws.h"
36 #define MAX(x, y) (((x) > (y)) ? (x) : (y))
37 #define MIN(x, y) (((x) < (y)) ? (x) : (y))
38 #define CLAMP(x, min, max) (((x) > (max)) ? (max) : (((x) < (min)) ?\
39 (min) : (x)))
41 #ifdef NDEBUG
42 #include <signal.h>
43 #include <unistd.h>
44 #define PWS_ASSERT(cond) while (cond) {\
45 write(STDERR_FIELNO, "assertion failed: " #cond "\n", \
46 sizeof ("assertion failed: " #cond "\n"));\
47 raise(SIGKILL);\
48 }
49 #else
50 #include <assert.h>
51 #define PWS_ASSERT(cond) assert(cond)
52 #endif /* NDEBUG */
54 struct pws3_field {
55 int is_header;
56 uint8_t field_type;
57 size_t size;
58 union {
59 unsigned char *bytes;
60 unsigned char uuid[PWS3_UUID_SIZE];
61 char *text;
62 uint8_t uint8;
63 uint16_t uint16;
64 uint32_t uint32;
65 } value;
66 RB_ENTRY(pws3_field) tree_entry;
67 };
69 struct pws3_record {
70 struct pws3_field *fields[256];
71 RB_ENTRY(pws3_record) tree_entry;
72 };
74 extern void * (*pws_alloc)(size_t);
75 extern void * (*pws_realloc)(void *, size_t);
76 extern void (*pws_free)(void *, size_t);
77 extern void * (*pws_secure_alloc)(size_t);
78 extern void * (*pws_secure_realloc)(void *, size_t);
79 extern void (*pws_secure_free)(void *, size_t);
81 int pws_random_bytes(void *, size_t);
83 #endif /* PWS_INTERNAL_H */