LibC: Implement vsyslog
This commit is contained in:
parent
5be9bc64a2
commit
14f1c1a358
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#define LOG_PID 0x01
|
||||
|
|
@ -47,6 +49,7 @@ void closelog(void);
|
|||
void openlog(const char* ident, int logopt, int facility);
|
||||
int setlogmask(int maskpri);
|
||||
void syslog(int priority, const char* message, ...);
|
||||
void vsyslog(int priority, const char* format, va_list ap);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
|
|
@ -17,24 +16,31 @@ void openlog(const char* ident, int option, int facility)
|
|||
s_ident = ident;
|
||||
}
|
||||
|
||||
void syslog(int priority, const char* format, ...)
|
||||
{
|
||||
(void)priority;
|
||||
if (s_ident)
|
||||
fprintf(s_log_file, "%s: ", s_ident);
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vfprintf(s_log_file, format, args);
|
||||
va_end(args);
|
||||
|
||||
const size_t format_len = strlen(format);
|
||||
if (format_len && format[format_len - 1] != '\n')
|
||||
fputc('\n', s_log_file);
|
||||
}
|
||||
|
||||
void closelog()
|
||||
{
|
||||
fclose(s_log_file);
|
||||
s_log_file = nullptr;
|
||||
s_ident = nullptr;
|
||||
}
|
||||
|
||||
void syslog(int priority, const char* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vsyslog(priority, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void vsyslog(int priority, const char* format, va_list ap)
|
||||
{
|
||||
(void)priority;
|
||||
|
||||
if (s_ident)
|
||||
fprintf(s_log_file, "%s: ", s_ident);
|
||||
|
||||
vfprintf(s_log_file, format, ap);
|
||||
|
||||
const size_t format_len = strlen(format);
|
||||
if (format_len && format[format_len - 1] != '\n')
|
||||
fputc('\n', s_log_file);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue