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/>.
28 /* For struct passwd */
30 /* For struct group */
33 /* Adjusts the verbosity level for msg() */
34 void adjust_verbosity(int adj
);
36 /* Verbosity levels using stdout */
40 /* Verbosity levels using stderr */
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
);