For /dev/mem, map in memory to be copied to memory's own address space
[minix3.git] / lib / ip / getprotoent.c
blob8c56716883b9d0dc6bb3dc619bbfbfdb1a8ec75d
1 /*
2 * Copyright (c) 1983 Regents of the University of California.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that: (1) source distributions retain this entire copyright
7 * notice and comment, and (2) distributions including binaries display
8 * the following acknowledgement: ``This product includes software
9 * developed by the University of California, Berkeley and its contributors''
10 * in the documentation or other materials provided with the distribution
11 * and in all advertising materials mentioning features or use of this
12 * software. Neither the name of the University nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 #if defined(LIBC_SCCS) && !defined(lint)
21 static char sccsid[] = "@(#)getprotoent.c 5.7 (Berkeley) 6/1/90";
22 #endif /* LIBC_SCCS and not lint */
24 #include <ctype.h>
25 #include <stdio.h>
26 #include <stdlib.h>
28 #ifdef _MINIX
29 #include <net/gen/netdb.h>
31 static char *any _ARGS(( char *cp, char *match ));
32 #endif
34 #define MAXALIASES 35
36 static FILE *protof = NULL;
37 static char line[BUFSIZ+1];
38 static struct protoent proto;
39 static char *proto_aliases[MAXALIASES];
40 int _proto_stayopen;
42 void
43 setprotoent(f)
44 int f;
46 if (protof == NULL)
47 protof = fopen(_PATH_PROTOCOLS, "r" );
48 else
49 rewind(protof);
50 _proto_stayopen |= f;
53 void
54 endprotoent()
56 if (protof) {
57 fclose(protof);
58 protof = NULL;
60 _proto_stayopen = 0;
63 struct protoent *
64 getprotoent()
66 char *p;
67 register char *cp, **q;
69 if (protof == NULL && (protof = fopen(_PATH_PROTOCOLS, "r" )) == NULL)
70 return (NULL);
71 again:
72 if ((p = fgets(line, BUFSIZ, protof)) == NULL)
73 return (NULL);
74 if (*p == '#')
75 goto again;
76 cp = any(p, "#\n");
77 if (cp == NULL)
78 goto again;
79 *cp = '\0';
80 proto.p_name = p;
81 cp = any(p, " \t");
82 if (cp == NULL)
83 goto again;
84 *cp++ = '\0';
85 while (*cp == ' ' || *cp == '\t')
86 cp++;
87 p = any(cp, " \t");
88 if (p != NULL)
89 *p++ = '\0';
90 proto.p_proto = atoi(cp);
91 q = proto.p_aliases = proto_aliases;
92 if (p != NULL) {
93 cp = p;
94 while (cp && *cp) {
95 if (*cp == ' ' || *cp == '\t') {
96 cp++;
97 continue;
99 if (q < &proto_aliases[MAXALIASES - 1])
100 *q++ = cp;
101 cp = any(cp, " \t");
102 if (cp != NULL)
103 *cp++ = '\0';
106 *q = NULL;
107 return (&proto);
110 static char *
111 any(cp, match)
112 register char *cp;
113 char *match;
115 register char *mp, c;
117 while (c = *cp) {
118 for (mp = match; *mp; mp++)
119 if (*mp == c)
120 return (cp);
121 cp++;
123 return ((char *)0);