1 /*
2 * This file has been modified for the cdrkit suite.
3 *
4 * The behaviour and appearence of the program code below can differ to a major
5 * extent from the version distributed by the original author(s).
6 *
7 * For details, see Changelog file distributed with the cdrkit package. If you
8 * received this file from another source then ask the distributing person for
9 * a log of modifications.
10 *
11 */
12
13 /* $Id: util.c,v 1.3 2006/07/04 04:57:42 hpa Exp $ */
14 /* ----------------------------------------------------------------------- *
15 *
16 * Copyright 2001-2006 H. Peter Anvin - All Rights Reserved
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
21 * USA; either version 2 of the License, or (at your option) any later
22 * version; incorporated herein by reference.
23 *
24 * ----------------------------------------------------------------------- */
25
26 #include "mkzftree.h" /* Must be included first! */
27
28 #include <stdio.h>
29 #include <errno.h>
30 #include <stdlib.h>
31 #include <stdarg.h>
32 #include <string.h>
33
34 /* Convenience functions */
xmalloc(size_t size)35 void *xmalloc(size_t size)
36 {
37 void *p = malloc(size);
38
39 if ( !p ) {
40 perror(program);
41 exit(EX_OSERR);
42 }
43
44 return p;
45 }
46
xstrdup(const char * str)47 char *xstrdup(const char *str)
48 {
49 char *s = strdup(str);
50
51 if ( !s ) {
52 perror(program);
53 exit(EX_OSERR);
54 }
55
56 return s;
57 }
58
message(enum verbosity level,const char * format,...)59 void message(enum verbosity level, const char *format, ...)
60 {
61 va_list ap;
62
63 va_start(ap, format);
64 if ( opt.verbosity >= level )
65 vfprintf(stderr, format, ap);
66 va_end(ap);
67 }
68
69