]> sourceware.org Git - glibc.git/blob - nis/nis_file.c
Update.
[glibc.git] / nis / nis_file.c
1 /* Copyright (c) 1997, 1998, 1999 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.
4
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.
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
13 Library General Public License for more details.
14
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. */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <rpcsvc/nis.h>
24 #include "nis_xdr.h"
25
26 static const char cold_start_file[] = "/var/nis/NIS_COLD_START";
27
28 directory_obj *
29 readColdStartFile (void)
30 {
31 XDR xdrs;
32 FILE *in;
33 bool_t status = TRUE;
34 directory_obj *obj;
35
36 in = fopen (cold_start_file, "rb");
37 if (in == NULL)
38 return NULL;
39
40 obj = calloc (1, sizeof (directory_obj));
41
42 if (obj != NULL)
43 {
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 }
53 }
54
55 fclose (in);
56
57 return obj;
58 }
59
60 bool_t
61 writeColdStartFile (const directory_obj *obj)
62 {
63 XDR xdrs;
64 FILE *out;
65 bool_t status;
66
67 out = fopen (cold_start_file, "wb");
68 if (out == NULL)
69 return FALSE;
70
71 xdrstdio_create (&xdrs, out, XDR_ENCODE);
72 status = _xdr_directory_obj (&xdrs, (directory_obj *) obj);
73 xdr_destroy (&xdrs);
74 fclose (out);
75
76 return status;
77 }
78
79 nis_object *
80 nis_read_obj (const char *name)
81 {
82 XDR xdrs;
83 FILE *in;
84 bool_t status;
85 nis_object *obj = calloc (1, sizeof (nis_object));
86
87 if (obj == NULL)
88 return NULL;
89
90 in = fopen (name, "rb");
91 if (in == NULL)
92 return NULL;
93
94 xdrstdio_create (&xdrs, in, XDR_DECODE);
95 status =_xdr_nis_object (&xdrs, obj);
96 xdr_destroy (&xdrs);
97 fclose (in);
98
99 if (status)
100 return obj;
101 else
102 {
103 nis_free_object (obj);
104 return NULL;
105 }
106 }
107
108 bool_t
109 nis_write_obj (const char *name, const nis_object *obj)
110 {
111 XDR xdrs;
112 FILE *out;
113 bool_t status;
114
115 out = fopen (name, "wb");
116 if (out == NULL)
117 return FALSE;
118
119 xdrstdio_create (&xdrs, out, XDR_ENCODE);
120 status = _xdr_nis_object (&xdrs, (nis_object *) obj);
121 xdr_destroy (&xdrs);
122 fclose (out);
123
124 return status;
125 }
This page took 0.043696 seconds and 6 git commands to generate.