Expand PMF_FN_* macros.
[netbsd-mini2440.git] / lib / libwrap / misc.c
blob24718ca8e1dec4bacebce7f36dcb2f6723dfde82
1 /* $NetBSD: misc.c,v 1.8 2002/05/24 05:38:20 itojun Exp $ */
3 /*
4 * Misc routines that are used by tcpd and by tcpdchk.
5 *
6 * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
7 */
9 #include <sys/cdefs.h>
10 #ifndef lint
11 #if 0
12 static char sccsic[] = "@(#) misc.c 1.2 96/02/11 17:01:29";
13 #else
14 __RCSID("$NetBSD: misc.c,v 1.8 2002/05/24 05:38:20 itojun Exp $");
15 #endif
16 #endif
18 #include <sys/types.h>
19 #include <sys/param.h>
20 #include <netinet/in.h>
21 #include <arpa/inet.h>
22 #include <stdio.h>
23 #include <string.h>
25 #include "tcpd.h"
27 /* xgets - fgets() with backslash-newline stripping */
29 char *xgets(ptr, len, fp)
30 char *ptr;
31 int len;
32 FILE *fp;
34 int got;
35 char *start = ptr;
37 while (len > 1 && fgets(ptr, len, fp)) {
38 got = strlen(ptr);
39 if (got >= 1 && ptr[got - 1] == '\n') {
40 tcpd_context.line++;
41 if (got >= 2 && ptr[got - 2] == '\\') {
42 got -= 2;
43 } else {
44 return (start);
47 ptr += got;
48 len -= got;
49 ptr[0] = 0;
51 return (ptr > start ? start : 0);
54 /* split_at - break string at delimiter or return NULL */
56 char *split_at(string, delimiter)
57 char *string;
58 int delimiter;
60 char *cp;
61 int bracket;
63 bracket = 0;
64 for (cp = string; cp && *cp; cp++) {
65 switch (*cp) {
66 case '[':
67 bracket++;
68 break;
69 case ']':
70 bracket--;
71 break;
72 default:
73 if (bracket == 0 && *cp == delimiter) {
74 *cp++ = 0;
75 return cp;
77 break;
80 return NULL;
83 /* dot_quad_addr - convert dotted quad to internal form */
85 int dot_quad_addr(str, addr)
86 char *str;
87 unsigned long *addr;
89 struct in_addr a;
91 if (!inet_aton(str, &a))
92 return -1;
93 if (addr)
94 *addr = a.s_addr;
95 return 0;