d05395fead12b1eb6b5354d115d3916eeb5896b9
[ircu2.10.12-pk.git] / ircd / support.c
1 /*
2  * IRC - Internet Relay Chat, common/support.c
3  * Copyright (C) 1990, 1991 Armin Gruner
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 1, or (at your option)
8  * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  * $Id$
20  */
21 #include "config.h"
22
23 #include "support.h"
24 #include "fileio.h"
25 #include "ircd.h"
26 #include "ircd_chattr.h"
27 #include "ircd_snprintf.h"
28 #include "s_bsd.h"
29 #include "s_debug.h"
30 #include "send.h"
31 #include "sprintf_irc.h"
32 #include "sys.h"
33
34 #include <signal.h>   /* kill */
35 #include <stdarg.h>
36 #include <stdio.h>
37 #include <string.h>
38 #include <time.h>
39 #include <unistd.h>
40
41 int check_if_ipmask(const char *mask)
42 {
43   int has_digit = 0;
44   const char *p;
45
46   for (p = mask; *p; ++p)
47     if (*p != '*' && *p != '?' && *p != '.' && *p != '/')
48     {
49       if (!IsDigit(*p))
50         return 0;
51       has_digit = -1;
52     }
53
54   return has_digit;
55 }
56
57 /* Moved from logf() in whocmds.c to here. Modified a 
58  * bit and used for most logging now.
59  *  -Ghostwolf 12-Jul-99
60  */
61
62 extern void write_log(const char *filename, const char *pattern, ...)
63 {
64   FBFILE *logfile;
65   va_list vl;
66   static char logbuf[1024];
67
68   logfile = fbopen(filename, "a");
69
70   if (logfile)
71   {
72     va_start(vl, pattern);
73     ircd_vsnprintf(0, logbuf, sizeof(logbuf) - 1, pattern, vl);
74     va_end(vl);
75
76     fbputs(logbuf, logfile);
77     fbclose(logfile);
78   }
79 }