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