Update.
[glibc.git] / nis / nis_file.c
blob94fa4eb86586bea1b43e5351661826b33411db25
1 /* Copyright (c) 1997, 1998 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 <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 XDR xdrs;
32 FILE *in;
33 bool_t status;
34 directory_obj obj;
36 in = fopen (cold_start_file, "rb");
37 if (in == NULL)
38 return NULL;
39 memset (&obj, '\0', sizeof (obj));
40 xdrstdio_create (&xdrs, in, XDR_DECODE);
41 status = _xdr_directory_obj (&xdrs, &obj);
42 xdr_destroy (&xdrs);
43 fclose (in);
45 return status ? nis_clone_directory (&obj, NULL) : NULL;
48 bool_t
49 writeColdStartFile (const directory_obj *obj)
51 XDR xdrs;
52 FILE *out;
53 bool_t status;
55 out = fopen (cold_start_file, "wb");
56 if (out == NULL)
57 return FALSE;
59 xdrstdio_create (&xdrs, out, XDR_ENCODE);
60 status = _xdr_directory_obj (&xdrs, (directory_obj *) obj);
61 xdr_destroy (&xdrs);
62 fclose (out);
64 return status;
67 nis_object *
68 nis_read_obj (const char *name)
70 XDR xdrs;
71 FILE *in;
72 bool_t status;
73 nis_object obj;
75 in = fopen (name, "rb");
76 if (in == NULL)
77 return NULL;
79 memset (&obj, '\0', sizeof (obj));
80 xdrstdio_create (&xdrs, in, XDR_DECODE);
81 status =_xdr_nis_object (&xdrs, &obj);
82 xdr_destroy (&xdrs);
83 fclose (in);
85 return status ? nis_clone_object (&obj, NULL) : NULL;
88 bool_t
89 nis_write_obj (const char *name, const nis_object *obj)
91 XDR xdrs;
92 FILE *out;
93 bool_t status;
95 out = fopen (name, "wb");
96 if (out == NULL)
97 return FALSE;
99 xdrstdio_create (&xdrs, out, XDR_ENCODE);
100 status = _xdr_nis_object (&xdrs, (nis_object *) obj);
101 xdr_destroy (&xdrs);
102 fclose (out);
104 return status;