Enclose O_ROOTCRED in _KERNEL_STRUCTURES. This is needed for the upcoming
[dragonfly.git] / usr.bin / dc / mem.c
blob4574266a873b99e550d2cbecceb0e626b726d983
1 /*
2 * $OpenBSD: mem.c,v 1.4 2004/07/11 06:41:48 otto Exp $
3 * $DragonFly: src/usr.bin/dc/mem.c,v 1.1 2004/09/20 04:20:39 dillon Exp $
4 */
6 /*
7 * Copyright (c) 2003, Otto Moerbeek <otto@drijf.net>
9 * Permission to use, copy, modify, and distribute this software for any
10 * purpose with or without fee is hereby granted, provided that the above
11 * copyright notice and this permission notice appear in all copies.
13 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 #include <openssl/err.h>
24 #include <err.h>
25 #include <stdlib.h>
26 #include <string.h>
28 #include "extern.h"
30 struct number *
31 new_number(void)
33 struct number *n;
35 n = bmalloc(sizeof(*n));
36 n->scale = 0;
37 n->number = BN_new();
38 if (n->number == NULL)
39 err(1, NULL);
40 return n;
43 void
44 free_number(struct number *n)
46 BN_free(n->number);
47 free(n);
50 struct number *
51 dup_number(const struct number *a)
53 struct number *n;
55 n = bmalloc(sizeof(*n));
56 n->scale = a->scale;
57 n->number = BN_dup(a->number);
58 bn_checkp(n->number);
59 return n;
62 void *
63 bmalloc(size_t sz)
65 void *p;
67 p = malloc(sz);
68 if (p == NULL)
69 err(1, NULL);
70 return p;
73 void *
74 brealloc(void *p, size_t sz)
76 void *q;
78 q = realloc(p, sz);
79 if (q == NULL)
80 err(1, NULL);
81 return q;
84 char *
85 bstrdup(const char *p)
87 char *q;
89 q = strdup(p);
90 if (q == NULL)
91 err(1, NULL);
92 return q;
95 void
96 bn_check(int x) \
98 if (x == 0)
99 err(1, "big number failure %lx", ERR_get_error());
102 void
103 bn_checkp(const void *p) \
105 if (p == NULL)
106 err(1, "allocation failure %lx", ERR_get_error());