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