Don't define exp2 inline.
[glibc/history.git] / nis / nis_getservlist.c
blob1629c24053a80417e2abd46f45c3699bf3f891c8
1 /* Copyright (c) 1997 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library 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 GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 #include <string.h>
21 #include <rpcsvc/nis.h>
22 #include "nis_intern.h"
24 nis_server **
25 nis_getservlist (const_nis_name dir)
27 nis_result *res;
28 nis_server **serv;
30 res = nis_lookup (dir, FOLLOW_LINKS);
32 if (NIS_RES_STATUS (res) == NIS_SUCCESS)
34 unsigned long i;
35 nis_server *server;
37 serv =
38 calloc (1, sizeof (nis_server *) *
39 (NIS_RES_OBJECT (res)->DI_data.do_servers.do_servers_len + 1));
40 if (serv == NULL)
41 return NULL;
42 for (i = 0; i < NIS_RES_OBJECT (res)->DI_data.do_servers.do_servers_len;
43 ++i)
45 server =
46 &NIS_RES_OBJECT (res)->DI_data.do_servers.do_servers_val[i];
47 serv[i] = calloc (1, sizeof (nis_server));
48 if (server->name != NULL)
49 serv[i]->name = strdup (server->name);
51 serv[i]->ep.ep_len = server->ep.ep_len;
52 if (serv[i]->ep.ep_len > 0)
54 unsigned long j;
56 serv[i]->ep.ep_val =
57 malloc (server->ep.ep_len * sizeof (endpoint));
58 for (j = 0; j < serv[i]->ep.ep_len; ++j)
60 if (server->ep.ep_val[j].uaddr)
61 serv[i]->ep.ep_val[j].uaddr =
62 strdup (server->ep.ep_val[j].uaddr);
63 else
64 serv[i]->ep.ep_val[j].uaddr = NULL;
65 if (server->ep.ep_val[j].family)
66 serv[i]->ep.ep_val[j].family =
67 strdup (server->ep.ep_val[j].family);
68 else
69 serv[i]->ep.ep_val[j].family = NULL;
70 if (server->ep.ep_val[j].proto)
71 serv[i]->ep.ep_val[j].proto =
72 strdup (server->ep.ep_val[j].proto);
73 else
74 serv[i]->ep.ep_val[j].proto = NULL;
77 else
78 serv[i]->ep.ep_val = NULL;
79 serv[i]->key_type = server->key_type;
80 serv[i]->pkey.n_len = server->pkey.n_len;
81 if (server->pkey.n_len > 0)
83 serv[i]->pkey.n_bytes =
84 malloc (server->pkey.n_len);
85 if (serv[i]->pkey.n_bytes == NULL)
86 return NULL;
87 memcpy (serv[i]->pkey.n_bytes, server->pkey.n_bytes,
88 server->pkey.n_len);
90 else
91 serv[i]->pkey.n_bytes = NULL;
94 else
96 serv = malloc (sizeof (nis_server *));
97 if (serv != NULL)
98 serv[0] = NULL;
100 return serv;
103 void
104 nis_freeservlist (nis_server **serv)
106 int i;
108 if (serv == NULL)
109 return;
111 i = 0;
112 while (serv[i] != NULL)
114 xdr_free ((xdrproc_t)xdr_nis_server, (char *)serv[i]);
115 free (serv[i]);
116 ++i;
118 free (serv);