xref: /haiku/src/add-ons/kernel/drivers/audio/ac97/es1370/debug.c (revision b028e77473189065f2baefc6f5e10d451cf591e2)
1 /*
2  * ES1370 Haiku Driver for ES1370 audio
3  *
4  * Copyright 2002-2007, Haiku, Inc.
5  * Distributed under the terms of the MIT License.
6  *
7  * Authors:
8  *		Marcus Overhagen, marcus@overhagen.de
9  *		Jerome Duval, jerome.duval@free.fr
10  */
11 #include <KernelExport.h>
12 #include <stdio.h>
13 #include <string.h>
14 #include <fcntl.h>
15 #include <unistd.h>
16 #include <OS.h>
17 #include "debug.h"
18 #include "es1370.h"
19 
20 #if DEBUG > 0
21 static const char * logfile="/boot/home/es1370.log";
22 static sem_id loglock;
23 #endif
24 
25 void debug_printf(const char *text,...);
26 void log_printf(const char *text,...);
27 void log_create(void);
28 
29 void debug_printf(const char *text,...)
30 {
31 	char buf[1024];
32 	va_list ap;
33 
34 	va_start(ap,text);
35 	vsprintf(buf,text,ap);
36 	va_end(ap);
37 
38 	dprintf(DRIVER_NAME ": %s",buf);
39 }
40 
41 void log_create()
42 {
43 #if DEBUG > 0
44 	int fd = open(logfile, O_WRONLY | O_CREAT | O_TRUNC, 0666);
45 	const char *text = DRIVER_NAME ", " VERSION "\n";
46 	loglock = create_sem(1,"logfile sem");
47 	write(fd,text,strlen(text));
48 	close(fd);
49 #endif
50 }
51 
52 void log_printf(const char *text,...)
53 {
54 #if DEBUG > 0
55 	int fd;
56 	char buf[1024];
57 	va_list ap;
58 
59 	va_start(ap,text);
60 	vsprintf(buf,text,ap);
61 	va_end(ap);
62 
63 	dprintf(DRIVER_NAME ": %s",buf);
64 
65 	acquire_sem(loglock);
66 	fd = open(logfile, O_WRONLY | O_APPEND);
67 	write(fd,buf,strlen(buf));
68 	close(fd);
69 	release_sem(loglock);
70 
71 	#if DEBUG > 1
72 		snooze(150000);
73 	#endif
74 #endif
75 }
76 
77