summaryrefslogtreecommitdiff
path: root/src/debug.c
blob: 2c6e3bc88f4e341b2f3e23cef87da0db588709cf (plain)
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

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#if DEBUG
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>

#include "err.h"
#include "debug.h"

static char *debug_path = "/tmp/epson-escpr-wrapper-dump";
static FILE *debug_fp = NULL;

void
debug_init (void)
{
	char path[255];
	pid_t pid;
	
	pid = getpid ();
	sprintf (path, "%s.%d", debug_path, pid);
	
	if (!debug_fp)
	{
		debug_fp = fopen (path, "w");
		if (!debug_fp)
			err_msg (MSGTYPE_WARNING, "Can't open the dump file \"%s\".", path);
	}

	fchmod (fileno (debug_fp), 0644);
	return;
}


void
debug_dump (const char *fmt, ...)
{
	va_list ap;

	if (!debug_fp)
		debug_init ();

	va_start (ap, fmt);
	vfprintf (debug_fp, fmt, ap);

	va_end (ap);
	return;
}


void
debug_end (void)
{
	if (!debug_fp)
		fclose (debug_fp);

	return;
}

#endif /* DEBUG */