site: end of line message, adesklets is not dead.
[adesklets.git] / src / error.c
blob9d0973d8ad59114da9caa0632af3adc9e9e7cccb
1 /*--- error.c ----------------------------------------------------------------
2 Copyright (C) 2004, 2005, 2006 Sylvain Fourmanoit <syfou@users.sourceforge.net>
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to
6 deal in the Software without restriction, including without limitation the
7 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 sell copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in
12 all copies of the Software and its documentation and acknowledgment shall be
13 given in the documentation and software packages that this Software was
14 used.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 ------------------------------------------------------------------------------*/
23 /* Debugging-related functions
26 /*----------------------------------------------------------------------------*/
27 #include "error.h" /* Error header */
30 /*----------------------------------------------------------------------------*/
31 int errno_bis;
33 #ifdef DEBUG
34 FILE * stdebug = NULL;
36 /*----------------------------------------------------------------------------*/
37 /* This initialize debugging correctly: all debug outputs are redirected
38 on stderr by default, unless the ADESKLETS_LOG environment variable
39 is giving a filename adesklets could open for writing. Called from
40 adesklets_init()
42 void
43 debug_init(void)
45 char file[256];
46 if (getenv("ADESKLETS_LOG")) {
47 snprintf(file,255,"%s.pid%u",getenv("ADESKLETS_LOG"),getpid());
48 file[255]=(char)0;
50 if ((stdebug=fopen(file,"w")))
51 setvbuf(stdebug, (char *)NULL, _IOLBF, 0);
54 if (!stdebug)
55 stdebug=stderr;
58 /*----------------------------------------------------------------------------*/
59 int
60 debug(const char * format, ...)
62 int result;
63 va_list ap;
64 va_start(ap,format);
65 result=vfprintf(stdebug,format,ap);
66 va_end(ap);
67 return result;
70 /*----------------------------------------------------------------------------*/
71 int
72 vdebug(const char * format, va_list ap)
74 int result;
75 va_list apcopy;
76 va_copy(apcopy,ap);
77 result=vfprintf(stdebug,format,apcopy);
78 va_end(apcopy);
79 return result;
82 /*----------------------------------------------------------------------------*/
83 int
84 debug_on_stderr(void)
86 return stderr==stdebug;
89 /*----------------------------------------------------------------------------*/
90 #endif