/******************************************************** * log_msg -- Write a message to the log file. * ********************************************************/ #include #include #include #include #include #include "log_msg.h" /******************************************************** * log_msg -- Write a message to the log file. * * Uses printf type arguements. * ********************************************************/ void log_msg(char *fmt, ...) { char full_string[5000]; /* The string containing the message */ va_list ap; /* For variable arguements */ static int log_fd = -1; /* FD of the file to write */ if (log_fd < 0) { char log_file_name[100]; /* Name of the log file */ sprintf(log_file_name, "debug_log.%d", getpid()); log_fd = open(log_file_name, O_WRONLY|O_CREAT, 0666); } va_start(ap, fmt); vsnprintf(full_string, sizeof(full_string), fmt, ap); if (log_fd >= 0) { write(log_fd, full_string, strlen(full_string)); } }