fix documentation of --compare
[metastore.git] / utils.h
bloba5f8b5498c2820a56518d5afcf7a6413e98c7084
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>
27 /* For struct passwd */
28 #include <pwd.h>
29 /* For struct group */
30 #include <grp.h>
32 /* Adjusts the verbosity level for msg() */
33 void adjust_verbosity(int adj);
35 /* Verbosity levels using stdout */
36 #define MSG_NORMAL 0
37 #define MSG_DEBUG 1
38 #define MSG_QUIET -1
39 /* Verbosity levels using stderr */
40 #define MSG_ERROR -2
41 #define MSG_CRITICAL -3
43 /* Prints messages to console according to the current verbosity */
44 int msg(int level, const char *fmt, ...);
46 /* Malloc which either succeeds or exits */
47 void *xmalloc(size_t size);
49 /* Ditto for strdup */
50 char *xstrdup(const char *s);
52 /* Human-readable printout of binary data */
53 void binary_print(const char *s, ssize_t len);
55 /* Writes data to a file or exits on failure */
56 void xfwrite(const void *ptr, size_t size, FILE *stream);
58 /* Writes an int to a file, using len bytes, in bigendian order */
59 void write_int(uint64_t value, size_t len, FILE *to);
61 /* Writes a binary string to a file */
62 void write_binary_string(const char *string, size_t len, FILE *to);
64 /* Writes a normal C string to a file */
65 void write_string(const char *string, FILE *to);
67 /* Reads an int from a file, using len bytes, in bigendian order */
68 uint64_t read_int(char **from, size_t len, const char *max);
70 /* Reads a binary string from a file */
71 char *read_binary_string(char **from, size_t len, const char *max);
73 /* Reads a normal C string from a file */
74 char *read_string(char **from, const char *max);
76 /* Caching version of getgrnam */
77 struct group *xgetgrnam(const char *name);
79 /* Caching version of getgrgid */
80 struct group *xgetgrgid(gid_t gid);
82 /* Caching version of getpwnam */
83 struct passwd *xgetpwnam(const char *name);
85 /* Caching version of getpwuid */
86 struct passwd *xgetpwuid(uid_t uid);