xref: /haiku/src/add-ons/kernel/drivers/audio/ac97/auich/debug.c (revision d4e4909c6a3fe4290b78be2b78035c4774e3ff18)
1 /*
2  * Auich BeOS Driver for Intel Southbridge audio
3  *
4  * Copyright (c) 2003, Jerome Duval (jerome.duval@free.fr)
5  *
6  * Original code : BeOS Driver for Intel ICH AC'97 Link interface
7  * Copyright (c) 2002, Marcus Overhagen <marcus@overhagen.de>
8  *
9  * All rights reserved.
10  * Redistribution and use in source and binary forms, with or without modification,
11  * are permitted provided that the following conditions are met:
12  *
13  * - Redistributions of source code must retain the above copyright notice,
14  *   this list of conditions and the following disclaimer.
15  * - Redistributions in binary form must reproduce the above copyright notice,
16  *   this list of conditions and the following disclaimer in the documentation
17  *   and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
25  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  */
31 
32 
33 #include <KernelExport.h>
34 
35 #include <fcntl.h>
36 #include <stdio.h>
37 #include <string.h>
38 #include <unistd.h>
39 
40 #include <directories.h>
41 #include <OS.h>
42 
43 #include "debug.h"
44 #include "auich.h"
45 
46 
47 #if DEBUG > 0
48 static const char *logfile = kSystemLogDirectory "/auich.log";
49 static sem_id loglock;
50 #endif
51 
52 
53 void debug_printf(const char *text,...);
54 void log_printf(const char *text,...);
55 void log_create(void);
56 
57 
58 void debug_printf(const char *text,...)
59 {
60 	char buf[1024];
61 	va_list ap;
62 
63 	va_start(ap,text);
64 	vsprintf(buf,text,ap);
65 	va_end(ap);
66 
67 	dprintf(DRIVER_NAME ": %s",buf);
68 }
69 
70 
71 void log_create()
72 {
73 #if DEBUG > 0
74 	int fd = open(logfile, O_WRONLY | O_CREAT | O_TRUNC, 0666);
75 	const char *text = DRIVER_NAME ", " VERSION "\n";
76 	loglock = create_sem(1,"logfile sem");
77 	write(fd,text,strlen(text));
78 	close(fd);
79 #endif
80 }
81 
82 
83 void log_printf(const char *text,...)
84 {
85 #if DEBUG > 0
86 	int fd;
87 	char buf[1024];
88 	va_list ap;
89 
90 	va_start(ap,text);
91 	vsprintf(buf,text,ap);
92 	va_end(ap);
93 
94 	dprintf(DRIVER_NAME ": %s",buf);
95 
96 	acquire_sem(loglock);
97 	fd = open(logfile, O_WRONLY | O_APPEND);
98 	write(fd,buf,strlen(buf));
99 	close(fd);
100 	release_sem(loglock);
101 
102 	#if DEBUG > 1
103 		snooze(150000);
104 	#endif
105 #endif
106 }
107