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