Remove the need for a global variable (do_mtime)
[metastore.git] / utils.h
blob76d6ca5178be83c4d648c83f0471979cc1787cfb
1 /*
2 * Main functions of the program.
4 * Copyright (C) 2007 David Härdeman <david@hardeman.nu>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 /* For uint64_t */
22 #include <stdint.h>
24 /* Controls the verbosity level for msg() */
25 extern int verbosity;
27 /* Verbosity levels using stdout */
28 #define MSG_NORMAL 0
29 #define MSG_DEBUG 1
30 #define MSG_QUIET -1
31 /* Verbosity levels using stderr */
32 #define MSG_ERROR -2
33 #define MSG_CRITICAL -3
35 /* Prints messages to console according to the current verbosity */
36 int msg(int level, const char *fmt, ...);
38 /* Malloc which either succeeds or exits */
39 void *xmalloc(size_t size);
41 /* Ditto for strdup */
42 char *xstrdup(const char *s);
44 /* Human-readable printout of binary data */
45 void binary_print(const char *s, ssize_t len);
47 /* Writes data to a file or exits on failure */
48 void xfwrite(const void *ptr, size_t size, FILE *stream);
50 /* Writes an int to a file, using len bytes, in bigendian order */
51 void write_int(uint64_t value, size_t len, FILE *to);
53 /* Writes a binary string to a file */
54 void write_binary_string(const char *string, size_t len, FILE *to);
56 /* Writes a normal C string to a file */
57 void write_string(const char *string, FILE *to);
59 /* Reads an int from a file, using len bytes, in bigendian order */
60 uint64_t read_int(char **from, size_t len, const char *max);
62 /* Reads a binary string from a file */
63 char *read_binary_string(char **from, size_t len, const char *max);
65 /* Reads a normal C string from a file */
66 char *read_string(char **from, const char *max);