.
[glibc/history.git] / nis / nis_file.c
blob1f2295787cadccc0138a7106a9e7eba3844660a4
1 /* Copyright (c) 1997, 1998, 1999, 2004 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Thorsten Kukuk <kukuk@suse.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 Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the 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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <rpcsvc/nis.h>
24 #include "nis_xdr.h"
26 static const char cold_start_file[] = "/var/nis/NIS_COLD_START";
28 directory_obj *
29 readColdStartFile (void)
31 FILE *in = fopen (cold_start_file, "rc");
32 if (in == NULL)
33 return NULL;
35 directory_obj *obj = calloc (1, sizeof (directory_obj));
37 if (obj != NULL)
39 XDR xdrs;
40 xdrstdio_create (&xdrs, in, XDR_DECODE);
41 bool_t status = _xdr_directory_obj (&xdrs, obj);
42 xdr_destroy (&xdrs);
44 if (!status)
46 nis_free_directory (obj);
47 obj = NULL;
51 fclose (in);
53 return obj;
55 libnsl_hidden_def (readColdStartFile)
57 bool_t
58 writeColdStartFile (const directory_obj *obj)
60 XDR xdrs;
61 FILE *out;
62 bool_t status;
64 out = fopen (cold_start_file, "wb");
65 if (out == NULL)
66 return FALSE;
68 xdrstdio_create (&xdrs, out, XDR_ENCODE);
69 status = _xdr_directory_obj (&xdrs, (directory_obj *) obj);
70 xdr_destroy (&xdrs);
71 fclose (out);
73 return status;
76 nis_object *
77 nis_read_obj (const char *name)
79 XDR xdrs;
80 FILE *in;
81 bool_t status;
82 nis_object *obj;
84 in = fopen (name, "rb");
85 if (in == NULL)
86 return NULL;
88 obj = calloc (1, sizeof (nis_object));
89 if (obj == NULL)
91 fclose (in);
92 return NULL;
95 xdrstdio_create (&xdrs, in, XDR_DECODE);
96 status =_xdr_nis_object (&xdrs, obj);
97 xdr_destroy (&xdrs);
98 fclose (in);
100 if (status)
101 return obj;
102 else
104 nis_free_object (obj);
105 return NULL;
109 bool_t
110 nis_write_obj (const char *name, const nis_object *obj)
112 XDR xdrs;
113 FILE *out;
114 bool_t status;
116 out = fopen (name, "wb");
117 if (out == NULL)
118 return FALSE;
120 xdrstdio_create (&xdrs, out, XDR_ENCODE);
121 status = _xdr_nis_object (&xdrs, (nis_object *) obj);
122 xdr_destroy (&xdrs);
123 fclose (out);
125 return status;