And add a newline
[metastore.git] / utils.h
blobe3096c92c1b101946fc18d3cf222eeb475fa9c2b
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>
23 /* For ssize_t */
24 #include <unistd.h>
25 /* For FILE */
26 #include <stdio.h>
28 /* Adjusts the verbosity level for msg() */
29 void adjust_verbosity(int adj);
31 /* Verbosity levels using stdout */
32 #define MSG_NORMAL 0
33 #define MSG_DEBUG 1
34 #define MSG_QUIET -1
35 /* Verbosity levels using stderr */
36 #define MSG_ERROR -2
37 #define MSG_CRITICAL -3
39 /* Prints messages to console according to the current verbosity */
40 int msg(int level, const char *fmt, ...);
42 /* Malloc which either succeeds or exits */
43 void *xmalloc(size_t size);
45 /* Ditto for strdup */
46 char *xstrdup(const char *s);
48 /* Human-readable printout of binary data */
49 void binary_print(const char *s, ssize_t len);
51 /* Writes data to a file or exits on failure */
52 void xfwrite(const void *ptr, size_t size, FILE *stream);
54 /* Writes an int to a file, using len bytes, in bigendian order */
55 void write_int(uint64_t value, size_t len, FILE *to);
57 /* Writes a binary string to a file */
58 void write_binary_string(const char *string, size_t len, FILE *to);
60 /* Writes a normal C string to a file */
61 void write_string(const char *string, FILE *to);
63 /* Reads an int from a file, using len bytes, in bigendian order */
64 uint64_t read_int(char **from, size_t len, const char *max);
66 /* Reads a binary string from a file */
67 char *read_binary_string(char **from, size_t len, const char *max);
69 /* Reads a normal C string from a file */
70 char *read_string(char **from, const char *max);