1 /* 2 * EchoGals/Echo24 BeOS Driver for Echo audio cards 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 <stdio.h> 36 #include <fcntl.h> 37 #include <unistd.h> 38 39 #include <directories.h> 40 #include <OS.h> 41 42 #include "debug.h" 43 44 45 #if DEBUG > 0 46 static const char *logfile = kSystemLogDirectory "/" DRIVER_NAME ".log"; 47 static sem_id loglock; 48 #endif 49 50 51 void debug_printf(const char *text,...); 52 void log_printf(const char *text,...); 53 54 55 void debug_printf(const char *text,...) 56 { 57 char buf[1024]; 58 va_list ap; 59 60 va_start(ap,text); 61 vsprintf(buf,text,ap); 62 va_end(ap); 63 64 dprintf(DRIVER_NAME ": %s",buf); 65 } 66 67 68 void log_create() 69 { 70 #if DEBUG > 0 71 int fd = open(logfile, O_WRONLY | O_CREAT | O_TRUNC, 0666); 72 const char *text = DRIVER_NAME ", " ECHO_VERSION "\n"; 73 loglock = create_sem(1,"logfile sem"); 74 write(fd,text,strlen(text)); 75 close(fd); 76 #endif 77 } 78 79 80 void log_printf(const char *text,...) 81 { 82 #if DEBUG > 0 83 int fd; 84 char buf[1024]; 85 va_list ap; 86 87 va_start(ap,text); 88 vsprintf(buf,text,ap); 89 va_end(ap); 90 91 dprintf(DRIVER_NAME ": %s",buf); 92 93 acquire_sem(loglock); 94 fd = open(logfile, O_WRONLY | O_APPEND); 95 write(fd,buf,strlen(buf)); 96 close(fd); 97 release_sem(loglock); 98 99 #if DEBUG > 1 100 snooze(150000); 101 #endif 102 #endif 103 } 104