annotate th_util.h @ 727:b415b70254fa

Add set_bit/test_bit helpers.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 06 Jan 2022 13:12:16 +0200
parents 29e44a58bc73
children a557d1b2a356
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * Generic utility-functions, macros and defaults
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Programmed and designed by Matti 'ccr' Hamalainen
726
29e44a58bc73 Bump copyrights.
Matti Hamalainen <ccr@tnsp.org>
parents: 722
diff changeset
4 * (C) Copyright 2002-2022 Tecnic Software productions (TNSP)
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 *
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 * Please read file 'COPYING' for information on license and distribution.
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 */
622
6d99150a8f89 Some more slight Doxygenisation.
Matti Hamalainen <ccr@tnsp.org>
parents: 580
diff changeset
8 /// @file
6d99150a8f89 Some more slight Doxygenisation.
Matti Hamalainen <ccr@tnsp.org>
parents: 580
diff changeset
9 /// @brief Miscellaneous utility functions, memory allocation, error codes etc.
49
598609fb49b0 Change how "config.h" is included, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
10 #ifndef TH_UTIL_H
598609fb49b0 Change how "config.h" is included, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
11 #define TH_UTIL_H
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12
49
598609fb49b0 Change how "config.h" is included, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
13 #ifdef HAVE_CONFIG_H
598609fb49b0 Change how "config.h" is included, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
14 #include "config.h"
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 #endif
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 #include "th_types.h"
45
e031a062b731 Separate program "banner" printing from th_args_help() to th_print_banner().
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
18 #include <stdio.h>
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 #include <stdarg.h>
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 #include <stdlib.h>
75
cfb475e11b9f Add a missing include.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
21 #include <unistd.h>
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 #ifndef HAVE_NO_ASSERT
466
bdee04d21282 Preprocessor stuff indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 462
diff changeset
23 # include <assert.h>
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 #endif
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25
623
893b2deeb5be Get rid of some useless includes.
Matti Hamalainen <ccr@tnsp.org>
parents: 622
diff changeset
26 #if defined(HAVE_STRING_H)
466
bdee04d21282 Preprocessor stuff indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 462
diff changeset
27 # include <string.h>
623
893b2deeb5be Get rid of some useless includes.
Matti Hamalainen <ccr@tnsp.org>
parents: 622
diff changeset
28 #elif defined(HAVE_STRINGS_H)
893b2deeb5be Get rid of some useless includes.
Matti Hamalainen <ccr@tnsp.org>
parents: 622
diff changeset
29 # include <strings.h>
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 #endif
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 #ifdef HAVE_MEMORY_H
466
bdee04d21282 Preprocessor stuff indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 462
diff changeset
33 # include <memory.h>
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 #endif
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35
92
40568456eb5b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
36
49
598609fb49b0 Change how "config.h" is included, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
37 #ifdef __cplusplus
598609fb49b0 Change how "config.h" is included, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
38 extern "C" {
598609fb49b0 Change how "config.h" is included, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
39 #endif
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40
4
67f4a4233372 Move defaults to header file.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
41
580
4d12924f9544 Typofix a comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 577
diff changeset
42 // Kludge, as MinGW64 cross-compiler does not like certain printf() format specifiers
577
70d44ba005ac Define a helper macro for __attribute__ ((__format__ (__printf__, 2, 3)))
Matti Hamalainen <ccr@tnsp.org>
parents: 573
diff changeset
43 #if defined(__MINGW64__)
70d44ba005ac Define a helper macro for __attribute__ ((__format__ (__printf__, 2, 3)))
Matti Hamalainen <ccr@tnsp.org>
parents: 573
diff changeset
44 # define TH_ATTR_PRINTF_FMT(xstart, xend)
70d44ba005ac Define a helper macro for __attribute__ ((__format__ (__printf__, 2, 3)))
Matti Hamalainen <ccr@tnsp.org>
parents: 573
diff changeset
45 #else
70d44ba005ac Define a helper macro for __attribute__ ((__format__ (__printf__, 2, 3)))
Matti Hamalainen <ccr@tnsp.org>
parents: 573
diff changeset
46 # define TH_ATTR_PRINTF_FMT(xstart, xend) __attribute__ ((__format__ (__printf__, (xstart), (xend))))
70d44ba005ac Define a helper macro for __attribute__ ((__format__ (__printf__, 2, 3)))
Matti Hamalainen <ccr@tnsp.org>
parents: 573
diff changeset
47 #endif
70d44ba005ac Define a helper macro for __attribute__ ((__format__ (__printf__, 2, 3)))
Matti Hamalainen <ccr@tnsp.org>
parents: 573
diff changeset
48
70d44ba005ac Define a helper macro for __attribute__ ((__format__ (__printf__, 2, 3)))
Matti Hamalainen <ccr@tnsp.org>
parents: 573
diff changeset
49
95
d86ad68f326f Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
50 // Replacement for assert()
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 #ifdef HAVE_NO_ASSERT
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 # ifdef NDEBUG
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
53 # define assert(NEXPR) // stub
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 # else
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 # define assert(NEXPR) do { if (!(NEXPR)) { fprintf(stderr, "[%s:%d] assert(" # NEXPR ") failed!\n", __FILE__, __LINE__); abort(); } } while (0)
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 # endif
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 #endif
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58
96
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
59
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
60 /* Error codes
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
61 */
97
a285cdc05810 Add log level enums.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
62 enum
a285cdc05810 Add log level enums.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
63 {
96
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
64 // General error codes
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
65 THERR_OK = 0,
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
66 THERR_PROGRESS, // Status OK, but operation in progress
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
67
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
68 THERR_INTERNAL,
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
69
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
70 THERR_FOPEN,
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
71 THERR_FREAD,
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
72 THERR_FWRITE,
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
73 THERR_FSEEK,
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
74 THERR_NOT_FOUND, // Resource/data not found
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
75
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
76 THERR_INVALID_DATA, // Some data was invalid
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
77 THERR_MALLOC, // Memory allocation failure
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
78 THERR_ALREADY_INIT, // Resource has already been initialized
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
79 THERR_INIT_FAIL, // General initialization failure
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
80 THERR_INVALID_ARGS,
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
81
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
82 THERR_NULLPTR, // NULL pointer specified in critical argument
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
83 THERR_NOT_SUPPORTED,// Operation not supported
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
84 THERR_OUT_OF_DATA,
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
85 THERR_EXTRA_DATA,
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
86 THERR_BOUNDS,
163
44887a053df0 Add few error codes.
Matti Hamalainen <ccr@tnsp.org>
parents: 162
diff changeset
87
96
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
88 THERR_TIMED_OUT,
163
44887a053df0 Add few error codes.
Matti Hamalainen <ccr@tnsp.org>
parents: 162
diff changeset
89 THERR_BUSY,
44887a053df0 Add few error codes.
Matti Hamalainen <ccr@tnsp.org>
parents: 162
diff changeset
90 THERR_IO_ERROR,
96
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
91
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
92 // Network errors
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
93 THERR_AUTH_FAILED,
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
94 };
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
95
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
96 #define TH_SYSTEM_ERRORS 100000
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
97
378
5391cd557483 Add empty line.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
98
97
a285cdc05810 Add log level enums.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
99 /* Log levels
a285cdc05810 Add log level enums.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
100 */
a285cdc05810 Add log level enums.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
101 enum
a285cdc05810 Add log level enums.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
102 {
a285cdc05810 Add log level enums.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
103 THLOG_NONE = 0,
a285cdc05810 Add log level enums.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
104 THLOG_ERROR,
a285cdc05810 Add log level enums.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
105 THLOG_WARNING,
a285cdc05810 Add log level enums.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
106 THLOG_INFO,
a285cdc05810 Add log level enums.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
107 THLOG_DEBUG,
a285cdc05810 Add log level enums.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
108 };
a285cdc05810 Add log level enums.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
109
96
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
110
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 /* Global variables
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 */
469
fe5b803ae449 Rename the global variable th_verbosityLevel to th_verbosity.
Matti Hamalainen <ccr@tnsp.org>
parents: 468
diff changeset
113 extern int th_verbosity;
19
bbb243eba688 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
114 extern char *th_prog_name,
60
eef9c6312b88 Change some internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
115 *th_prog_desc,
19
bbb243eba688 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
116 *th_prog_version,
bbb243eba688 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
117 *th_prog_author,
bbb243eba688 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
118 *th_prog_license;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 /* Functions
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 */
60
eef9c6312b88 Change some internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
122 void th_init(char *name, char *desc, char *version,
eef9c6312b88 Change some internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
123 char *author, char *license);
eef9c6312b88 Change some internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
124 void th_print_banner(FILE *outFile, const char *binName, const char *usage);
489
41c1d786ff08 Add th_print_version().
Matti Hamalainen <ccr@tnsp.org>
parents: 483
diff changeset
125 void th_print_version(FILE *outFile);
45
e031a062b731 Separate program "banner" printing from th_args_help() to th_print_banner().
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
126
143
c878cdcfea9d Implement terminal width.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
127 int th_term_width();
c878cdcfea9d Implement terminal width.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
128 int th_term_height();
c878cdcfea9d Implement terminal width.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
129
101
a8f732601fdc Rename th_get_errno() to th_get_error(), it's more appropriate since it does
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
130 int th_get_error();
99
5819454a28a4 Add th_errno_to_error().
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
131 int th_errno_to_error(int error);
96
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
132 const char *th_error_str(int error);
3df6bec3c6b1 Add error handling stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
133
570
262411458cde Add __attribute__(__format__ ..) specifiers for functions that use printf() style format specifiers.
Matti Hamalainen <ccr@tnsp.org>
parents: 553
diff changeset
134 void THERR(const char *fmt, ...)
577
70d44ba005ac Define a helper macro for __attribute__ ((__format__ (__printf__, 2, 3)))
Matti Hamalainen <ccr@tnsp.org>
parents: 573
diff changeset
135 TH_ATTR_PRINTF_FMT(1, 2);
570
262411458cde Add __attribute__(__format__ ..) specifiers for functions that use printf() style format specifiers.
Matti Hamalainen <ccr@tnsp.org>
parents: 553
diff changeset
136 void THMSG(int level, const char *fmt, ...)
577
70d44ba005ac Define a helper macro for __attribute__ ((__format__ (__printf__, 2, 3)))
Matti Hamalainen <ccr@tnsp.org>
parents: 573
diff changeset
137 TH_ATTR_PRINTF_FMT(2, 3);
570
262411458cde Add __attribute__(__format__ ..) specifiers for functions that use printf() style format specifiers.
Matti Hamalainen <ccr@tnsp.org>
parents: 553
diff changeset
138 void THPRINT(int level, const char *fmt, ...)
577
70d44ba005ac Define a helper macro for __attribute__ ((__format__ (__printf__, 2, 3)))
Matti Hamalainen <ccr@tnsp.org>
parents: 573
diff changeset
139 TH_ATTR_PRINTF_FMT(2, 3);
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140
194
87dac812cac4 Define some argument identifiers in function prototypes and rename some arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 192
diff changeset
141 void THERR_V(const char *fmt, va_list ap);
87dac812cac4 Define some argument identifiers in function prototypes and rename some arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 192
diff changeset
142 void THMSG_V(int level, const char *fmt, va_list ap);
87dac812cac4 Define some argument identifiers in function prototypes and rename some arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 192
diff changeset
143 void THPRINT_V(int level, const char *fmt, va_list ap);
11
e467b3586e4d Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
144
462
a90fe2c4c636 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 454
diff changeset
145 void *th_malloc(size_t len);
a90fe2c4c636 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 454
diff changeset
146 void *th_malloc0(size_t len);
a90fe2c4c636 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 454
diff changeset
147 void *th_calloc(size_t n, size_t len);
a90fe2c4c636 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 454
diff changeset
148 void *th_realloc(void *ptr, size_t len);
194
87dac812cac4 Define some argument identifiers in function prototypes and rename some arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 192
diff changeset
149 void th_free(void *ptr);
197
88986d0b56ef Rename th_free_r() to th_free_r_real() and #define a macro wrapper for
Matti Hamalainen <ccr@tnsp.org>
parents: 194
diff changeset
150 void th_free_r_real(void **ptr);
88986d0b56ef Rename th_free_r() to th_free_r_real() and #define a macro wrapper for
Matti Hamalainen <ccr@tnsp.org>
parents: 194
diff changeset
151
88986d0b56ef Rename th_free_r() to th_free_r_real() and #define a macro wrapper for
Matti Hamalainen <ccr@tnsp.org>
parents: 194
diff changeset
152 #define th_free_r(ptr) th_free_r_real((void **) ptr)
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153
16
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
154
727
b415b70254fa Add set_bit/test_bit helpers.
Matti Hamalainen <ccr@tnsp.org>
parents: 726
diff changeset
155 #define th_test_bit(pdata, nbit) \
b415b70254fa Add set_bit/test_bit helpers.
Matti Hamalainen <ccr@tnsp.org>
parents: 726
diff changeset
156 (pdata[nbit >> 3] & (1 << (nbit & 7)))
b415b70254fa Add set_bit/test_bit helpers.
Matti Hamalainen <ccr@tnsp.org>
parents: 726
diff changeset
157
b415b70254fa Add set_bit/test_bit helpers.
Matti Hamalainen <ccr@tnsp.org>
parents: 726
diff changeset
158 static inline void th_set_bit(uint8_t *pdata, const size_t nbit, const int value)
b415b70254fa Add set_bit/test_bit helpers.
Matti Hamalainen <ccr@tnsp.org>
parents: 726
diff changeset
159 {
b415b70254fa Add set_bit/test_bit helpers.
Matti Hamalainen <ccr@tnsp.org>
parents: 726
diff changeset
160 if (value)
b415b70254fa Add set_bit/test_bit helpers.
Matti Hamalainen <ccr@tnsp.org>
parents: 726
diff changeset
161 pdata[nbit >> 3] |= (1 << (nbit & 7));
b415b70254fa Add set_bit/test_bit helpers.
Matti Hamalainen <ccr@tnsp.org>
parents: 726
diff changeset
162 else
b415b70254fa Add set_bit/test_bit helpers.
Matti Hamalainen <ccr@tnsp.org>
parents: 726
diff changeset
163 pdata[nbit >> 3] &= ~(1 << (nbit & 7));
b415b70254fa Add set_bit/test_bit helpers.
Matti Hamalainen <ccr@tnsp.org>
parents: 726
diff changeset
164 }
b415b70254fa Add set_bit/test_bit helpers.
Matti Hamalainen <ccr@tnsp.org>
parents: 726
diff changeset
165
b415b70254fa Add set_bit/test_bit helpers.
Matti Hamalainen <ccr@tnsp.org>
parents: 726
diff changeset
166
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 #ifdef __cplusplus
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 }
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 #endif
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
170 #endif // TH_UTIL_H