Remove _hurd_longjmp_thread_state decl.
[glibc.git] / sunrpc / getrpcent.c
blob8ef65618b004c32ee3df9801ce8bad7dca59a81d
1 /* @(#)getrpcent.c 2.2 88/07/29 4.0 RPCSRC */
2 #if !defined(lint) && defined(SCCSIDS)
3 static char sccsid[] = "@(#)getrpcent.c 1.9 87/08/11 Copyr 1984 Sun Micro";
4 #endif
6 /*
7 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
8 * unrestricted use provided that this legend is included on all tape
9 * media and as a part of the software program in whole or part. Users
10 * may copy or modify Sun RPC without charge, but are not authorized
11 * to license or distribute it to anyone else except as part of a product or
12 * program developed by the user.
14 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
15 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
18 * Sun RPC is provided with no support and without any obligation on the
19 * part of Sun Microsystems, Inc. to assist in its use, correction,
20 * modification or enhancement.
22 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
23 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
24 * OR ANY PART THEREOF.
26 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
27 * or profits or other special, indirect and consequential damages, even if
28 * Sun has been advised of the possibility of such damages.
30 * Sun Microsystems, Inc.
31 * 2550 Garcia Avenue
32 * Mountain View, California 94043
36 * Copyright (c) 1985 by Sun Microsystems, Inc.
39 #include <stdio.h>
40 #include <sys/types.h>
41 #include <rpc/rpc.h>
42 #include <netdb.h>
43 #include <sys/socket.h>
46 * Internet version.
48 struct rpcdata {
49 FILE *rpcf;
50 char *current;
51 int currentlen;
52 int stayopen;
53 #define MAXALIASES 35
54 char *rpc_aliases[MAXALIASES];
55 struct rpcent rpc;
56 char line[BUFSIZ+1];
57 char *domain;
58 } *rpcdata, *_rpcdata();
60 static struct rpcent *interpret();
61 struct hostent *gethostent();
62 char *inet_ntoa();
63 extern char *index(); /* Changed from static by roland@gnu */
65 static char RPCDB[] = _PATH_RPC; /* Changed from "/etc/rpc" by roland@gnu */
67 static struct rpcdata *
68 _rpcdata()
70 register struct rpcdata *d = rpcdata;
72 if (d == 0) {
73 d = (struct rpcdata *)calloc(1, sizeof (struct rpcdata));
74 rpcdata = d;
76 return (d);
79 struct rpcent *
80 getrpcbynumber(number)
81 register int number;
83 register struct rpcdata *d = _rpcdata();
84 register struct rpcent *p;
85 int reason;
86 char adrstr[16], *val = NULL;
87 int vallen;
89 if (d == 0)
90 return (0);
91 setrpcent(0);
92 while (p = getrpcent()) {
93 if (p->r_number == number)
94 break;
96 endrpcent();
97 return (p);
100 struct rpcent *
101 getrpcbyname(name)
102 const char *name; /* const added by roland@gnu */
104 struct rpcent *rpc;
105 char **rp;
107 setrpcent(0);
108 while(rpc = getrpcent()) {
109 if (strcmp(rpc->r_name, name) == 0)
110 return (rpc);
111 for (rp = rpc->r_aliases; *rp != NULL; rp++) {
112 if (strcmp(*rp, name) == 0)
113 return (rpc);
116 endrpcent();
117 return (NULL);
120 setrpcent(f)
121 int f;
123 register struct rpcdata *d = _rpcdata();
125 if (d == 0)
126 return;
127 if (d->rpcf == NULL)
128 d->rpcf = fopen(RPCDB, "r");
129 else
130 rewind(d->rpcf);
131 if (d->current)
132 free(d->current);
133 d->current = NULL;
134 d->stayopen |= f;
137 endrpcent()
139 register struct rpcdata *d = _rpcdata();
141 if (d == 0)
142 return;
143 if (d->current && !d->stayopen) {
144 free(d->current);
145 d->current = NULL;
147 if (d->rpcf && !d->stayopen) {
148 fclose(d->rpcf);
149 d->rpcf = NULL;
153 struct rpcent *
154 getrpcent()
156 struct rpcent *hp;
157 int reason;
158 char *key = NULL, *val = NULL;
159 int keylen, vallen;
160 register struct rpcdata *d = _rpcdata();
162 if (d == 0)
163 return(NULL);
164 if (d->rpcf == NULL && (d->rpcf = fopen(RPCDB, "r")) == NULL)
165 return (NULL);
166 if (fgets(d->line, BUFSIZ, d->rpcf) == NULL)
167 return (NULL);
168 return interpret(d->line, strlen(d->line));
171 static struct rpcent *
172 interpret(val, len)
174 register struct rpcdata *d = _rpcdata();
175 char *p;
176 register char *cp, **q;
178 if (d == 0)
179 return;
180 strncpy(d->line, val, len);
181 p = d->line;
182 d->line[len] = '\n';
183 if (*p == '#')
184 return (getrpcent());
185 cp = index(p, '#');
186 if (cp == NULL)
188 cp = index(p, '\n');
189 if (cp == NULL)
190 return (getrpcent());
192 *cp = '\0';
193 cp = index(p, ' ');
194 if (cp == NULL)
196 cp = index(p, '\t');
197 if (cp == NULL)
198 return (getrpcent());
200 *cp++ = '\0';
201 /* THIS STUFF IS INTERNET SPECIFIC */
202 d->rpc.r_name = d->line;
203 while (*cp == ' ' || *cp == '\t')
204 cp++;
205 d->rpc.r_number = atoi(cp);
206 q = d->rpc.r_aliases = d->rpc_aliases;
207 cp = index(p, ' ');
208 if (cp != NULL)
209 *cp++ = '\0';
210 else
212 cp = index(p, '\t');
213 if (cp != NULL)
214 *cp++ = '\0';
216 while (cp && *cp) {
217 if (*cp == ' ' || *cp == '\t') {
218 cp++;
219 continue;
221 if (q < &(d->rpc_aliases[MAXALIASES - 1]))
222 *q++ = cp;
223 cp = index(p, ' ');
224 if (cp != NULL)
225 *cp++ = '\0';
226 else
228 cp = index(p, '\t');
229 if (cp != NULL)
230 *cp++ = '\0';
233 *q = NULL;
234 return (&d->rpc);