Slightly reformat and modernize GPLv2 only license notices.
[metastore.git] / src / utils.h
blob332a315ac496120baae1742f08c511f7260df1b4
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; only version 2 of the License is applicable.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef UTILS_H
20 #define UTILS_H
22 /* For uint64_t */
23 #include <stdint.h>
24 /* For ssize_t */
25 #include <unistd.h>
26 /* For FILE */
27 #include <stdio.h>
28 /* For struct passwd */
29 #include <pwd.h>
30 /* For struct group */
31 #include <grp.h>
33 /* Adjusts the verbosity level for msg() */
34 void adjust_verbosity(int adj);
36 /* Verbosity levels using stdout */
37 #define MSG_NORMAL 0
38 #define MSG_DEBUG 1
39 #define MSG_QUIET -1
40 /* Verbosity levels using stderr */
41 #define MSG_ERROR -2
42 #define MSG_CRITICAL -3
44 /* Prints messages to console according to the current verbosity */
45 int msg(int level, const char *fmt, ...);
47 /* Malloc which either succeeds or exits */
48 void *xmalloc(size_t size);
50 /* Ditto for strdup */
51 char *xstrdup(const char *s);
53 /* Human-readable printout of binary data */
54 void binary_print(const char *s, ssize_t len);
56 /* Writes data to a file or exits on failure */
57 void xfwrite(const void *ptr, size_t size, FILE *stream);
59 /* Writes an int to a file, using len bytes, in little-endian order */
60 void write_int(uint64_t value, size_t len, FILE *to);
62 /* Writes a binary string to a file */
63 void write_binary_string(const char *string, size_t len, FILE *to);
65 /* Writes a normal C string to a file */
66 void write_string(const char *string, FILE *to);
68 /* Reads an int from a file, using len bytes, in little-endian order */
69 uint64_t read_int(char **from, size_t len, const char *max);
71 /* Reads a binary string from a file */
72 char *read_binary_string(char **from, size_t len, const char *max);
74 /* Reads a normal C string from a file */
75 char *read_string(char **from, const char *max);
77 /* Caching version of getgrnam */
78 struct group *xgetgrnam(const char *name);
80 /* Caching version of getgrgid */
81 struct group *xgetgrgid(gid_t gid);
83 /* Caching version of getpwnam */
84 struct passwd *xgetpwnam(const char *name);
86 /* Caching version of getpwuid */
87 struct passwd *xgetpwuid(uid_t uid);
89 #endif /* UTILS_H */