OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libc/] [inet/] [rpc/] [getrpcent.c] - Blame information for rev 1325

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/* @(#)getrpcent.c      2.2 88/07/29 4.0 RPCSRC */
2
#define __FORCE_GLIBC
3
#include <features.h>
4
 
5
/*
6
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
7
 * unrestricted use provided that this legend is included on all tape
8
 * media and as a part of the software program in whole or part.  Users
9
 * may copy or modify Sun RPC without charge, but are not authorized
10
 * to license or distribute it to anyone else except as part of a product or
11
 * program developed by the user.
12
 *
13
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
14
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
15
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
16
 *
17
 * Sun RPC is provided with no support and without any obligation on the
18
 * part of Sun Microsystems, Inc. to assist in its use, correction,
19
 * modification or enhancement.
20
 *
21
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
22
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
23
 * OR ANY PART THEREOF.
24
 *
25
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
26
 * or profits or other special, indirect and consequential damages, even if
27
 * Sun has been advised of the possibility of such damages.
28
 *
29
 * Sun Microsystems, Inc.
30
 * 2550 Garcia Avenue
31
 * Mountain View, California  94043
32
 */
33
 
34
/*
35
 * Copyright (c) 1985 by Sun Microsystems, Inc.
36
 */
37
 
38
#include <stdio.h>
39
#include <string.h>
40
#include <sys/types.h>
41
#include <rpc/rpc.h>
42
#include <netdb.h>
43
#include <sys/socket.h>
44
#include <arpa/inet.h>
45
 
46
/*
47
 * Internet version.
48
 */
49
static struct rpcdata {
50
        FILE *rpcf;
51
        char *current;
52
        int currentlen;
53
        int stayopen;
54
#define MAXALIASES      35
55
        char *rpc_aliases[MAXALIASES];
56
        struct rpcent rpc;
57
        char line[BUFSIZ + 1];
58
        char *domain;
59
} *rpcdata;
60
 
61
static struct rpcent *interpret(const char *val, int len);
62
 
63
static char RPCDB[] = "/etc/rpc";
64
 
65
static struct rpcdata *_rpcdata(void)
66
{
67
        register struct rpcdata *d = rpcdata;
68
 
69
        if (d == 0) {
70
                d = (struct rpcdata *) calloc(1, sizeof(struct rpcdata));
71
 
72
                rpcdata = d;
73
        }
74
        return (d);
75
}
76
 
77
struct rpcent *getrpcbynumber(number)
78
register int number;
79
{
80
        register struct rpcdata *d = _rpcdata();
81
        register struct rpcent *p;
82
 
83
        if (d == 0)
84
                return (0);
85
        setrpcent(0);
86
        while ((p = getrpcent())) {
87
                if (p->r_number == number)
88
                        break;
89
        }
90
        endrpcent();
91
        return (p);
92
}
93
 
94
struct rpcent *
95
#ifdef __linux__
96
getrpcbyname(const char *name)
97
#else
98
getrpcbyname(name)
99
char *name;
100
#endif
101
{
102
        struct rpcent *rpc;
103
        char **rp;
104
 
105
        setrpcent(0);
106
        while ((rpc = getrpcent())) {
107
                if (strcmp(rpc->r_name, name) == 0)
108
                        return (rpc);
109
                for (rp = rpc->r_aliases; *rp != NULL; rp++) {
110
                        if (strcmp(*rp, name) == 0)
111
                                return (rpc);
112
                }
113
        }
114
        endrpcent();
115
        return (NULL);
116
}
117
 
118
#ifdef __linux__
119
void
120
#endif
121
setrpcent(f)
122
int f;
123
{
124
        register struct rpcdata *d = _rpcdata();
125
 
126
        if (d == 0)
127
                return;
128
        if (d->rpcf == NULL)
129
                d->rpcf = fopen(RPCDB, "r");
130
        else
131
                rewind(d->rpcf);
132
        if (d->current)
133
                free(d->current);
134
        d->current = NULL;
135
        d->stayopen |= f;
136
}
137
 
138
#ifdef __linux__
139
void
140
#endif
141
endrpcent()
142
{
143
        register struct rpcdata *d = _rpcdata();
144
 
145
        if (d == 0)
146
                return;
147
        if (d->current && !d->stayopen) {
148
                free(d->current);
149
                d->current = NULL;
150
        }
151
        if (d->rpcf && !d->stayopen) {
152
                fclose(d->rpcf);
153
                d->rpcf = NULL;
154
        }
155
}
156
 
157
struct rpcent *getrpcent()
158
{
159
        register struct rpcdata *d = _rpcdata();
160
 
161
        if (d == 0)
162
                return (NULL);
163
        if (d->rpcf == NULL && (d->rpcf = fopen(RPCDB, "r")) == NULL)
164
                return (NULL);
165
        if (fgets(d->line, BUFSIZ, d->rpcf) == NULL)
166
                return (NULL);
167
        return interpret(d->line, strlen(d->line));
168
}
169
 
170
#ifdef __linux__
171
static char *firstwhite(char *s)
172
{
173
        char *s1, *s2;
174
 
175
        s1 = index(s, ' ');
176
        s2 = index(s, '\t');
177
        if (s1) {
178
                if (s2)
179
                        return (s1 < s2) ? s1 : s2;
180
                else
181
                        return s1;
182
        } else
183
                return s2;
184
}
185
#endif
186
 
187
static struct rpcent *interpret(const char *val, int len)
188
{
189
        register struct rpcdata *d = _rpcdata();
190
        char *p;
191
        register char *cp, **q;
192
 
193
        if (d == 0)
194
                return NULL;
195
        strncpy(d->line, val, len);
196
        p = d->line;
197
        d->line[len] = '\n';
198
        if (*p == '#')
199
                return (getrpcent());
200
        cp = index(p, '#');
201
        if (cp == NULL) {
202
                cp = index(p, '\n');
203
                if (cp == NULL)
204
                        return (getrpcent());
205
        }
206
        *cp = '\0';
207
#ifdef __linux__
208
        if ((cp = firstwhite(p)))
209
                *cp++ = 0;
210
        else
211
                return (getrpcent());
212
#else
213
        cp = index(p, ' ');
214
        if (cp == NULL) {
215
                cp = index(p, '\t');
216
                if (cp == NULL)
217
                        return (getrpcent());
218
        }
219
        *cp++ = '\0';
220
#endif
221
        /* THIS STUFF IS INTERNET SPECIFIC */
222
        d->rpc.r_name = d->line;
223
        while (*cp == ' ' || *cp == '\t')
224
                cp++;
225
        d->rpc.r_number = atoi(cp);
226
        q = d->rpc.r_aliases = d->rpc_aliases;
227
#ifdef __linux__
228
        if ((cp = firstwhite(cp)))
229
                *cp++ = '\0';
230
#else
231
        cp = index(p, ' ');
232
        if (cp != NULL)
233
                *cp++ = '\0';
234
        else {
235
                cp = index(p, '\t');
236
                if (cp != NULL)
237
                        *cp++ = '\0';
238
        }
239
#endif
240
        while (cp && *cp) {
241
                if (*cp == ' ' || *cp == '\t') {
242
                        cp++;
243
                        continue;
244
                }
245
                if (q < &(d->rpc_aliases[MAXALIASES - 1]))
246
                        *q++ = cp;
247
#ifdef __linux__
248
                if ((cp = firstwhite(cp)))
249
                        *cp++ = '\0';
250
#else
251
                cp = index(p, ' ');
252
                if (cp != NULL)
253
                        *cp++ = '\0';
254
                else {
255
                        cp = index(p, '\t');
256
                        if (cp != NULL)
257
                                *cp++ = '\0';
258
                }
259
#endif
260
        }
261
        *q = NULL;
262
        return (&d->rpc);
263
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.