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