-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.h
76 lines (67 loc) · 2.63 KB
/
util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* util.h - generic utility data types ("bool_t" etc.) and functions
*
* Copyright (C) 2012, Greg Johnson
* Released under the terms of the GNU GPL v2.0.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* $Id: util.h,v 1.12 2012-02-22 19:27:23 greg Exp $
*/
#ifndef UTIL_H
#define UTIL_H
#include <math.h>
#include <stdio.h>
#include <sys/types.h>
/* used with tweak_db_vec - see comment there. */
#define UTIL_DB_VEC_MAX 16
extern int util_db_vec[UTIL_DB_VEC_MAX];
typedef unsigned char byte;
/* define boolean type and values */
typedef byte bool_t;
typedef enum {
false = 0,
true = 1,
} bool_value_t;
/* debugging array entry; the value of the debug entry, and a descriptive name
* for the entry.
*/
typedef struct {
char d;
char *str;
} char_str_t;
/* we use a function-pointer scheme for printing messages. sometimes
* we just want to print the message to an open stream, other times we
* want to send the message over the wire from an embedded box to a
* development box.
*/
typedef int ddprintf_t(FILE *f, const char *msg, ...);
extern int fprint(FILE *f, const char *msg, ...)
__attribute__((format(printf,2,3)));
extern void print_message(FILE *f, unsigned char *buf, int msg_len);
extern void print_select(FILE *f, char *title, fd_set *set, int select_result,
int max_fd);
extern void fn_print_message(ddprintf_t *fn, FILE *f, unsigned char *buf,
int msg_len);
extern int repeat_open(char *fname, int flags);
extern int tweak_db(char *arg, char_str_t *db);
extern void tweak_db_vec(char *arg, char_str_t *db);
extern void tweak_db_int(int arg, char_str_t *db);
extern bool_t file_exists(char *fname);
extern char *bool_string(bool_t bool);
extern long long timeval_diff(struct timeval *tv1, struct timeval *tv2);
extern char checked_gettimeofday(struct timeval *tv);
extern long long usec_diff(long sec1, long usec1, long sec2, long usec2);
extern void usec_add_msecs(long *sec, long *usec, int msec);
extern void update_time(long *out_sec, long *out_usec, long sec, long usec);
extern void util_print_time(FILE *f, struct timeval *tv);
extern void util_fn_print_time(ddprintf_t *fn, FILE *f, struct timeval *tv);
extern void read_all_available(int fd);
extern bool_t util_debug_print(bool_t b);
extern int skip_comment_line(FILE *f);
extern unsigned int hash_bytes(byte *bytes, int len);
extern void print_space(ddprintf_t *fn, FILE *f, int space);
extern void copy_string(char *dest, char *src, int len);
#endif