1 /* Proxytunnel - (C) 2001-2008 Jos Visser / Mark Janssen */
2 /* Contact: josv@osp.nl / maniac@maniac.nl */
3
4 /*
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20 #include <stdio.h>
21 #include <stdarg.h>
22 #include <string.h>
23 #include <errno.h>
24 #include <syslog.h>
25 #include "proxytunnel.h"
26
27 /*
28 * Give a message to the user
29 */
message(char * s,...)30 void message( char *s, ... ) {
31 va_list ap;
32 char buf[1024];
33
34 va_start( ap, s );
35 vsnprintf( (char *)buf, sizeof( buf ), s, ap );
36 va_end( ap );
37
38 if ( i_am_daemon )
39 syslog( LOG_NOTICE, "%s", buf );
40 else
41 fputs( buf, stderr );
42 }
43
44 /* My own perror function (uses the internal message) */
my_perror(char * msg)45 void my_perror( char *msg ) {
46 if (errno == 0) {
47 message( "error: %s.\n", msg );
48 } else {
49 char *errstr = strerror( errno );
50 message( "error: %s: [%d] %s\n", msg, errno, errstr );
51 }
52 }
53
54 // vim:noexpandtab:ts=4
55