utils.h revision 1.9 1 1.9 elric /* $NetBSD: utils.h,v 1.9 2008/05/11 03:15:21 elric Exp $ */
2 1.1 elric
3 1.1 elric /*-
4 1.2 elric * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
5 1.1 elric * All rights reserved.
6 1.1 elric *
7 1.1 elric * This code is derived from software contributed to The NetBSD Foundation
8 1.1 elric * by Roland C. Dowdeswell.
9 1.1 elric *
10 1.1 elric * Redistribution and use in source and binary forms, with or without
11 1.1 elric * modification, are permitted provided that the following conditions
12 1.1 elric * are met:
13 1.1 elric * 1. Redistributions of source code must retain the above copyright
14 1.1 elric * notice, this list of conditions and the following disclaimer.
15 1.1 elric * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 elric * notice, this list of conditions and the following disclaimer in the
17 1.1 elric * documentation and/or other materials provided with the distribution.
18 1.1 elric *
19 1.1 elric * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 elric * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 elric * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 elric * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 elric * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 elric * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 elric * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 elric * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 elric * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 elric * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 elric * POSSIBILITY OF SUCH DAMAGE.
30 1.1 elric */
31 1.1 elric
32 1.2 elric #ifndef CGDUTILS_H
33 1.2 elric #define CGDUTILS_H
34 1.1 elric
35 1.2 elric #include <stdio.h>
36 1.1 elric
37 1.1 elric #define BITS2BYTES(n) (((n) + 7) / 8)
38 1.2 elric
39 1.2 elric struct string;
40 1.2 elric typedef struct string string_t;
41 1.2 elric
42 1.2 elric struct bits;
43 1.2 elric typedef struct bits bits_t;
44 1.2 elric
45 1.2 elric __BEGIN_DECLS
46 1.2 elric char **words(const char *, int *);
47 1.2 elric void words_free(char **, int);
48 1.2 elric
49 1.2 elric void memxor(void *, const void *, size_t);
50 1.2 elric
51 1.2 elric void free_notnull(void *);
52 1.2 elric
53 1.9 elric string_t *string_zero(void);
54 1.7 christos string_t *string_new(const char *, size_t);
55 1.2 elric string_t *string_dup(const string_t *);
56 1.2 elric void string_assign(string_t **, string_t *);
57 1.2 elric void string_free(string_t *);
58 1.2 elric string_t *string_add(const string_t *, const string_t *);
59 1.2 elric string_t *string_add_d(string_t *, string_t *);
60 1.2 elric string_t *string_fromcharstar(const char *);
61 1.2 elric const char *string_tocharstar(const string_t *);
62 1.2 elric string_t *string_fromint(int);
63 1.2 elric
64 1.2 elric void string_fprint(FILE *, const string_t *);
65 1.2 elric
66 1.7 christos bits_t *bits_new(const void *, size_t);
67 1.2 elric bits_t *bits_dup(const bits_t *);
68 1.2 elric void bits_assign(bits_t **, bits_t *);
69 1.2 elric void bits_free(bits_t *);
70 1.2 elric const void *bits_getbuf(bits_t *);
71 1.7 christos size_t bits_len(bits_t *);
72 1.3 cb int bits_match(const bits_t *, const bits_t *);
73 1.2 elric
74 1.2 elric bits_t *bits_xor(const bits_t *, const bits_t *);
75 1.2 elric bits_t *bits_xor_d(bits_t *, bits_t *);
76 1.2 elric
77 1.2 elric bits_t *bits_decode(const string_t *);
78 1.2 elric bits_t *bits_decode_d(string_t *);
79 1.2 elric string_t *bits_encode(const bits_t *);
80 1.2 elric string_t *bits_encode_d(bits_t *);
81 1.2 elric
82 1.7 christos bits_t *bits_cget(const char *, size_t);
83 1.7 christos bits_t *bits_fget(FILE *, size_t);
84 1.7 christos bits_t *bits_getrandombits(size_t, int);
85 1.2 elric
86 1.2 elric void bits_fprint(FILE *, const bits_t *);
87 1.2 elric __END_DECLS
88 1.2 elric
89 1.2 elric #endif
90