Set errno for ±Inf.
[glibc/history.git] / nis / nis_file.c
blob566f30c48c8cb701b9b29e7ae554499fca0ec50a
1 /* Copyright (c) 1997, 1998, 1999, 2004, 2005 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 typedef bool_t (*iofct_t) (XDR *, void *);
27 typedef void (*freefct_t) (void *);
30 static void *
31 read_nis_obj (const char *name, iofct_t readfct, freefct_t freefct,
32 size_t objsize)
34 FILE *in = fopen (name, "rc");
35 if (in == NULL)
36 return NULL;
38 void *obj = calloc (1, objsize);
40 if (obj != NULL)
42 XDR xdrs;
43 xdrstdio_create (&xdrs, in, XDR_DECODE);
44 bool_t status = readfct (&xdrs, obj);
45 xdr_destroy (&xdrs);
47 if (!status)
49 freefct (obj);
50 obj = NULL;
54 fclose (in);
56 return obj;
59 static bool_t
60 write_nis_obj (const char *name, const void *obj, iofct_t writefct)
62 FILE *out = fopen (name, "w");
63 if (out == NULL)
64 return FALSE;
66 XDR xdrs;
67 xdrstdio_create (&xdrs, out, XDR_ENCODE);
68 bool_t status = writefct (&xdrs, (void *) obj);
69 xdr_destroy (&xdrs);
70 fclose (out);
72 return status;
76 static const char cold_start_file[] = "/var/nis/NIS_COLD_START";
78 directory_obj *
79 readColdStartFile (void)
81 return read_nis_obj (cold_start_file, (iofct_t) _xdr_directory_obj,
82 (freefct_t) nis_free_directory, sizeof (directory_obj));
84 libnsl_hidden_def (readColdStartFile)
86 bool_t
87 writeColdStartFile (const directory_obj *obj)
89 return write_nis_obj (cold_start_file, obj, (iofct_t) _xdr_directory_obj);
92 nis_object *
93 nis_read_obj (const char *name)
95 return read_nis_obj (name, (iofct_t) _xdr_nis_object,
96 (freefct_t) nis_free_object, sizeof (nis_object));
99 bool_t
100 nis_write_obj (const char *name, const nis_object *obj)
102 return write_nis_obj (name, obj, (iofct_t) _xdr_nis_object);