]> sourceware.org Git - glibc.git/blame - nis/nis_file.c
Update.
[glibc.git] / nis / nis_file.c
CommitLineData
3d8fa13a 1/* Copyright (c) 1997, 1998, 1999 Free Software Foundation, Inc.
e61abf83 2 This file is part of the GNU C Library.
32abdb71 3 Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
e61abf83
UD
4
5 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
e61abf83
UD
9
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
41bdb6e2 13 Lesser General Public License for more details.
e61abf83 14
41bdb6e2
AJ
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. */
e61abf83
UD
19
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
23#include <rpcsvc/nis.h>
91eee4dd 24#include "nis_xdr.h"
5ae9d168
UD
25
26static const char cold_start_file[] = "/var/nis/NIS_COLD_START";
27
e61abf83
UD
28directory_obj *
29readColdStartFile (void)
30{
31 XDR xdrs;
32 FILE *in;
3d8fa13a
UD
33 bool_t status = TRUE;
34 directory_obj *obj;
e61abf83 35
5ae9d168 36 in = fopen (cold_start_file, "rb");
e61abf83 37 if (in == NULL)
3e5f5557 38 return NULL;
e61abf83 39
3d8fa13a
UD
40 obj = calloc (1, sizeof (directory_obj));
41
42 if (obj != NULL)
e852e889 43 {
3d8fa13a
UD
44 xdrstdio_create (&xdrs, in, XDR_DECODE);
45 status = _xdr_directory_obj (&xdrs, obj);
46 xdr_destroy (&xdrs);
47
48 if (!status)
49 {
50 nis_free_directory (obj);
51 obj = NULL;
52 }
e852e889 53 }
3d8fa13a
UD
54
55 fclose (in);
56
57 return obj;
e61abf83
UD
58}
59
60bool_t
61writeColdStartFile (const directory_obj *obj)
62{
63 XDR xdrs;
64 FILE *out;
a53bad16 65 bool_t status;
e61abf83 66
5ae9d168 67 out = fopen (cold_start_file, "wb");
e61abf83 68 if (out == NULL)
3e5f5557 69 return FALSE;
e61abf83
UD
70
71 xdrstdio_create (&xdrs, out, XDR_ENCODE);
a53bad16
UD
72 status = _xdr_directory_obj (&xdrs, (directory_obj *) obj);
73 xdr_destroy (&xdrs);
74 fclose (out);
e61abf83 75
a53bad16 76 return status;
e61abf83
UD
77}
78
79nis_object *
80nis_read_obj (const char *name)
81{
82 XDR xdrs;
83 FILE *in;
a53bad16 84 bool_t status;
32abdb71 85 nis_object *obj;
e61abf83
UD
86
87 in = fopen (name, "rb");
88 if (in == NULL)
89 return NULL;
90
32abdb71
UD
91 obj = calloc (1, sizeof (nis_object));
92 if (obj == NULL)
93 {
94 fclose (in);
95 return NULL;
96 }
97
e61abf83 98 xdrstdio_create (&xdrs, in, XDR_DECODE);
e852e889 99 status =_xdr_nis_object (&xdrs, obj);
a53bad16
UD
100 xdr_destroy (&xdrs);
101 fclose (in);
e61abf83 102
e852e889
UD
103 if (status)
104 return obj;
105 else
106 {
107 nis_free_object (obj);
108 return NULL;
109 }
e61abf83
UD
110}
111
112bool_t
113nis_write_obj (const char *name, const nis_object *obj)
114{
115 XDR xdrs;
116 FILE *out;
a53bad16 117 bool_t status;
e61abf83
UD
118
119 out = fopen (name, "wb");
120 if (out == NULL)
121 return FALSE;
122
123 xdrstdio_create (&xdrs, out, XDR_ENCODE);
a53bad16
UD
124 status = _xdr_nis_object (&xdrs, (nis_object *) obj);
125 xdr_destroy (&xdrs);
126 fclose (out);
e61abf83 127
a53bad16 128 return status;
e61abf83 129}
This page took 0.220161 seconds and 5 git commands to generate.