-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.c
85 lines (68 loc) · 1.41 KB
/
util.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/******************************************************************************
*
* PROGRAM : util.c
* LANGUAGE : C
* REMARKS : Miscellaneous convenient functions
* AUTHOR : Hiroshi Nishida
*
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <stdarg.h>
#include <string.h>
#include <strings.h>
#include <signal.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/stat.h>
#define _UTIL_MAIN_
#include "util.h"
#undef _UTIL_MAIN_
#include "log.h"
/*****************************************************************************
Utility functions
*****************************************************************************/
/* Output error message and exit */
void
ErrorExit(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
exit(EXIT_FAILURE);
}
/* Put perror's message and exit */
void
PerrorExit(char *str)
{
perror(str);
exit(EXIT_FAILURE);
}
/* Output debug message */
void
DebugMsg(const char *fmt, ...)
{
va_list ap;
if (!Debug)
return;
fputs("DEBUG: ", stdout);
va_start(ap, fmt);
vfprintf(stdout, fmt, ap);
va_end(ap);
fflush(stdout);
}
/* Output verbose message */
void
VerboseMsg(const char *fmt, ...)
{
va_list ap;
if (!Verbose && !Debug)
return;
va_start(ap, fmt);
vfprintf(stdout, fmt, ap);
va_end(ap);
fflush(stdout);
}