Removed non portable -v flag for rm command.
[uftps.git] / log.c
blob37b16261fbf7abf41edd83816febd14b874bb2e4
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;
48 * The value in SS.pid prevents calling getpid() for each message,
49 * saving the expense of a system call.
51 printf("(%5d) [%-7s] ", SS.pid, severity);
52 vprintf(msg, args);
54 if (show_error && error_code != 0)
55 printf(": %s.\n", strerror(error_code));
56 else
57 puts(".");
62 * Debug message. Only enabled for debug compilations.
64 #ifdef DEBUG
65 void debug (const char *msg, ...)
67 va_list args;
69 va_start(args, msg);
70 message(0, "DEBUG", msg, args);
71 va_end(args);
73 #endif
77 * Informational message.
79 void notice (const char *msg, ...)
81 va_list args;
83 va_start(args, msg);
84 message(0, "NOTICE", msg, args);
85 va_end(args);
90 * Program error message.
92 void warning (const char *msg, ...)
94 va_list args;
96 va_start(args, msg);
97 message(0, "WARNING", msg, args);
98 va_end(args);
103 * System error message. Displays system error information when the last error
104 * code is not zero.
106 void error (const char *msg, ...)
108 va_list args;
110 va_start(args, msg);
111 message(1, "ERROR", msg, args);
112 va_end(args);
117 * Fatal error. Displays a message similar to error() but also terminates the
118 * current process.
120 void fatal (const char *msg, ...)
122 va_list args;
124 va_start(args, msg);
125 message(1, "FATAL", msg, args);
126 va_end(args);
128 exit(EXIT_FAILURE);