Tizen 2.1 base
[platform/upstream/epson-inkjet-printer-escpr.git] / src / debug.c
1 /*
2  * Epson Inkjet Printer Driver (ESC/P-R) for Linux
3  * Copyright (C) 2002-2005 AVASYS CORPORATION.
4  * Copyright (C) Seiko Epson Corporation 2002-2012.
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #  include <config.h>
23 #endif
24
25 #if DEBUG
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <unistd.h>
29 #include <stdio.h>
30
31 #include "err.h"
32 #include "debug.h"
33
34 static char *debug_path = "/tmp/epson-escpr-wrapper-dump";
35 static FILE *debug_fp = NULL;
36
37 void
38 debug_init (void)
39 {
40         char path[255];
41         pid_t pid;
42         
43         pid = getpid ();
44         sprintf (path, "%s.%d", debug_path, pid);
45         
46         if (!debug_fp)
47         {
48                 debug_fp = fopen (path, "w");
49                 if (!debug_fp)
50                         err_msg (MSGTYPE_WARNING, "Can't open the dump file \"%s\".", path);
51         }
52
53         fchmod (fileno (debug_fp), 0644);
54         return;
55 }
56
57
58 void
59 debug_dump (const char *fmt, ...)
60 {
61         va_list ap;
62
63         if (!debug_fp)
64                 debug_init ();
65
66         va_start (ap, fmt);
67         vfprintf (debug_fp, fmt, ap);
68
69         va_end (ap);
70         return;
71 }
72
73
74 void
75 debug_end (void)
76 {
77         if (!debug_fp)
78                 fclose (debug_fp);
79
80         return;
81 }
82
83 #endif /* DEBUG */