summaryrefslogtreecommitdiff
path: root/utils.h
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2007-05-19 17:14:12 +0200
committerDavid Härdeman <david@hardeman.nu>2007-05-19 17:14:12 +0200
commit5fed2f9169fdd0585cc83ff0fa8210d97da77cb2 (patch)
tree00bb9a4b2e260301516b137208edf0e270420e23 /utils.h
parent22fd68b59d5f792ff033120ad260581ac7fa72ee (diff)
80-col align code, add license headers
Diffstat (limited to 'utils.h')
-rw-r--r--utils.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/utils.h b/utils.h
index dac3bc4..76d6ca5 100644
--- a/utils.h
+++ b/utils.h
@@ -1,24 +1,67 @@
+/*
+ * Main functions of the program.
+ *
+ * Copyright (C) 2007 David Härdeman <david@hardeman.nu>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+/* For uint64_t */
#include <stdint.h>
+/* Controls the verbosity level for msg() */
extern int verbosity;
+
+/* Verbosity levels using stdout */
#define MSG_NORMAL 0
#define MSG_DEBUG 1
#define MSG_QUIET -1
+/* Verbosity levels using stderr */
#define MSG_ERROR -2
#define MSG_CRITICAL -3
+/* Prints messages to console according to the current verbosity */
int msg(int level, const char *fmt, ...);
+/* Malloc which either succeeds or exits */
void *xmalloc(size_t size);
+
+/* Ditto for strdup */
char *xstrdup(const char *s);
+
+/* Human-readable printout of binary data */
void binary_print(const char *s, ssize_t len);
+
+/* Writes data to a file or exits on failure */
void xfwrite(const void *ptr, size_t size, FILE *stream);
+/* Writes an int to a file, using len bytes, in bigendian order */
void write_int(uint64_t value, size_t len, FILE *to);
+
+/* Writes a binary string to a file */
void write_binary_string(const char *string, size_t len, FILE *to);
+
+/* Writes a normal C string to a file */
void write_string(const char *string, FILE *to);
+/* Reads an int from a file, using len bytes, in bigendian order */
uint64_t read_int(char **from, size_t len, const char *max);
+
+/* Reads a binary string from a file */
char *read_binary_string(char **from, size_t len, const char *max);
+
+/* Reads a normal C string from a file */
char *read_string(char **from, const char *max);