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 12 13#include <KernelExport.h> 14 15#include <stdio.h> 16#include <string.h> 17#include <fcntl.h> 18#include <unistd.h> 19 20#include <directories.h> 21#include <OS.h> 22 23#include "debug.h" 24#include "es1370.h" 25 26 27#if DEBUG > 0 28static const char *logfile = kSystemLogDirectory "/es1370.log"; 29static sem_id loglock; 30#endif 31 32 33void debug_printf(const char *text,...); 34void log_printf(const char *text,...); 35void log_create(void); 36 37 38void debug_printf(const char *text,...) 39{ 40 char buf[1024]; 41 va_list ap; 42 43 va_start(ap,text); 44 vsprintf(buf,text,ap); 45 va_end(ap); 46 47 dprintf(DRIVER_NAME ": %s",buf); 48} 49 50 51void log_create() 52{ 53#if DEBUG > 0 54 int fd = open(logfile, O_WRONLY | O_CREAT | O_TRUNC, 0666); 55 const char *text = DRIVER_NAME ", " VERSION "\n"; 56 loglock = create_sem(1,"logfile sem"); 57 write(fd,text,strlen(text)); 58 close(fd); 59#endif 60} 61 62 63void log_printf(const char *text,...) 64{ 65#if DEBUG > 0 66 int fd; 67 char buf[1024]; 68 va_list ap; 69 70 va_start(ap,text); 71 vsprintf(buf,text,ap); 72 va_end(ap); 73 74 dprintf(DRIVER_NAME ": %s",buf); 75 76 acquire_sem(loglock); 77 fd = open(logfile, O_WRONLY | O_APPEND); 78 write(fd,buf,strlen(buf)); 79 close(fd); 80 release_sem(loglock); 81 82 #if DEBUG > 1 83 snooze(150000); 84 #endif 85#endif 86} 87