Solaris compilation fixes.
[uftps.git] / log.c
blob052e1faf9f029a914cf94ee71092dad6635da069
1 /*
2 * User FTP Server, Share folders over FTP without being root.
3 * Copyright (C) 2008 Isaac Jurado
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option) any later
8 * version.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "uftps.h"
21 #ifdef __MINGW32__
22 # include "hase.h"
23 #else
24 # include <unistd.h>
25 #endif
26 #include <stdarg.h>
27 #include <errno.h>
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <string.h>
34 * Logging utility. Display a printf()-like formatted message (msg, args) with
35 * the current PID and a severity label at the beginning of the line. If
36 * show_error is true, append a human readable version of the last system error.
38 static void message ( int show_error,
39 const char *severity,
40 const char *msg,
41 va_list args)
43 int error_code;
45 error_code = errno;
47 printf("(%5d) [%-7s] ", (int) getpid(), severity);
48 vprintf(msg, args);
50 if (show_error && error_code != 0)
51 printf(": %s.\n", strerror(error_code));
52 else
53 puts(".");
58 * Debug message. Only enabled for debug compilations.
60 #ifdef DEBUG
61 void debug (const char *msg, ...)
63 va_list args;
65 va_start(args, msg);
66 message(0, "DEBUG", msg, args);
67 va_end(args);
69 #endif
73 * Informational message.
75 void notice (const char *msg, ...)
77 va_list args;
79 va_start(args, msg);
80 message(0, "NOTICE", msg, args);
81 va_end(args);
86 * Program error message.
88 void warning (const char *msg, ...)
90 va_list args;
92 va_start(args, msg);
93 message(0, "WARNING", msg, args);
94 va_end(args);
99 * System error message. Displays system error information when the last error
100 * code is not zero.
102 void error (const char *msg, ...)
104 va_list args;
106 va_start(args, msg);
107 message(1, "ERROR", msg, args);
108 va_end(args);
113 * Fatal error. Displays a message similar to error() but also terminates the
114 * current process.
116 void fatal (const char *msg, ...)
118 va_list args;
120 va_start(args, msg);
121 message(1, "FATAL", msg, args);
122 va_end(args);
124 exit(EXIT_FAILURE);