"Fossies" - the Fresh Open Source Software Archive 
Member "mozplugger-2.1.6/debug.c" (17 Apr 2014, 4025 Bytes) of package /linux/www/old/mozplugger-2.1.6.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 /**
2 * This file is part of mozplugger a fork of plugger, for list of developers
3 * see the README file.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
18 */
19
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include <unistd.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <stdarg.h>
28
29 #include "debug.h"
30
31 #ifdef DEBUG
32
33 static int debug_on = 1;
34 static FILE * debug_output = NULL;
35 static char * debug_path = "";
36
37 /**
38 * Open the debug file for appending to
39 *
40 * @return The FILE pointer, or NULL if problem
41 */
42 static FILE *getout(void)
43 {
44 char debug_filename[128];
45 char *tmpdir;
46
47 if (debug_output)
48 {
49 return debug_output;
50 }
51
52 if(!debug_on)
53 {
54 return NULL;
55 }
56
57 tmpdir = getenv("MOZPLUGGER_TMP");
58 if(tmpdir == NULL)
59 {
60 tmpdir = getenv("TMPDIR");
61 debug_path = "$MOZPLUGGER_TMP";
62 snprintf(debug_filename, sizeof(debug_filename),
63 "%s/%s", tmpdir, DEBUG_FILENAME);
64 }
65
66 if(tmpdir == NULL)
67 {
68 /* If (as on default Fedora 7 install) the environment variable
69 * TMPDIR is not defined, just assume $HOME/tmp */
70 char * homedir = getenv("HOME");
71 if(homedir == NULL)
72 {
73 fprintf(stderr, "Failed to open debug file - "
74 "neither HOME or TMPDIR defined\n");
75 return NULL;
76 }
77 debug_path = "$HOME/tmp"; /* For display purposes */
78 snprintf(debug_filename, sizeof(debug_filename),
79 "%s/tmp/%s", homedir, DEBUG_FILENAME);
80 }
81 else
82 {
83 debug_path = "$TMDIR"; /* For display purposes */
84 snprintf(debug_filename, sizeof(debug_filename),
85 "%s/%s", tmpdir, DEBUG_FILENAME);
86 }
87
88 debug_output = fopen(debug_filename,"a+");
89 if (debug_output == NULL)
90 {
91 fprintf(stderr,"Failed to open debug file \'%s'\n", debug_filename);
92 debug_on = 0;
93 return NULL;
94 }
95 else
96 {
97 fprintf(stderr,"Opened debug file \'%s\'\n", debug_filename);
98 }
99
100 fprintf(debug_output, "------------\n");
101 return debug_output;
102 }
103
104 /**
105 * Close debug file
106 */
107 void close_debug(void)
108 {
109 FILE * f = getout();
110
111 if(f)
112 {
113 fclose(f);
114 }
115 debug_output = NULL;
116 }
117
118 /**
119 * Take the standard printf type arguments and write the output to the debug
120 * file
121 *
122 * @param[in] fmt The printf format args
123 * @param[in] ... The printf style arguments
124 */
125 void D(char *fmt, ...)
126 {
127 char buffer[9999];
128 va_list ap;
129 FILE * f = getout();
130
131 if(f)
132 {
133 va_start(ap,fmt);
134 vsnprintf(buffer,sizeof(buffer),fmt,ap);
135 va_end(ap);
136
137 fprintf(f,"PID%4d: %s",(int) getpid(), buffer);
138 fflush(f);
139 }
140 }
141
142 /**
143 * Get path to the debug file (for display purposes only!)
144 *
145 * @return String containing debug path name
146 */
147 char * get_debug_path(void)
148 {
149 if(debug_path[0] == '\0')
150 {
151 getout();
152 }
153
154 return debug_path;
155 }
156
157 int is_debugging(void)
158 {
159 return 1;
160 }
161
162 #else
163
164 void D(char *fmt, ...)
165 {
166 }
167
168 void close_debug(void)
169 {
170 }
171
172 char * get_debug_path(void)
173 {
174 return NULL;
175 };
176
177 int is_debugging(void)
178 {
179 return 0;
180 }
181 #endif
182