forked from rogueforge/rogomatic14
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebuglog.c
More file actions
91 lines (77 loc) · 1.98 KB
/
debuglog.c
File metadata and controls
91 lines (77 loc) · 1.98 KB
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
85
86
87
88
89
90
91
/*
* Rog-O-Matic
* Automatically exploring the dungeons of doom.
*
* Copyright (C) 2008 by Anthony Molinaro
*
* This file is part of Rog-O-Matic.
*
* Rog-O-Matic 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, either version 3 of the License, or
* (at your option) any later version.
*
* Rog-O-Matic 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 Rog-O-Matic. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include "types.h"
#define MAXLINE 4096
/* static declarations */
static FILE *debug = NULL;
static void err_doit(int errnoflag, int error, const char *fmt, va_list ap);
static void
err_doit(int errnoflag, int error, const char *fmt, va_list ap)
{
char buf[MAXLINE + 1]; /* +1 for paranoia */
memset(buf, 0, sizeof(buf)); /* paranoia */
vsnprintf(buf, MAXLINE, fmt, ap);
if (debug != NULL) {
fputs(buf, debug);
fflush (debug);
}
else {
fputs (buf, stderr);
fflush (stderr);
}
}
void
debuglog_open (const char *dir, const char *log)
{
char *path = NULL; /* path to open */
/* form full path */
path = form_path (dir, log);
/* open the log file */
debug = fopen (path, "w");
if (debug == NULL) {
quit (1, "ERROR: %s: failed to open for writing: %s: %s\n", __func__, path, strerror (errno));
not_reached ();
}
/* free memory */
if (path != NULL) {
free(path);
path = NULL;
}
}
void
debuglog_close (void)
{
fclose (debug);
}
void
debuglog (const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
err_doit (0, 0, fmt, ap);
va_end (ap);
}