AArch64: Don't clobber argument for tail call to __sigjmp_save in sigsetjmp
[glibc.git] / nis / nis_file.c
blob0034ab994842a680205fb6196b711d4daf689501
1 /* Copyright (c) 1997-2013 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, see
17 <http://www.gnu.org/licenses/>. */
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <rpcsvc/nis.h>
23 #include "nis_xdr.h"
25 typedef bool_t (*iofct_t) (XDR *, void *);
26 typedef void (*freefct_t) (void *);
29 static void *
30 read_nis_obj (const char *name, iofct_t readfct, freefct_t freefct,
31 size_t objsize)
33 FILE *in = fopen (name, "rce");
34 if (in == NULL)
35 return NULL;
37 void *obj = calloc (1, objsize);
39 if (obj != NULL)
41 XDR xdrs;
42 xdrstdio_create (&xdrs, in, XDR_DECODE);
43 bool_t status = readfct (&xdrs, obj);
44 xdr_destroy (&xdrs);
46 if (!status)
48 freefct (obj);
49 obj = NULL;
53 fclose (in);
55 return obj;
58 static bool_t
59 write_nis_obj (const char *name, const void *obj, iofct_t writefct)
61 FILE *out = fopen (name, "wce");
62 if (out == NULL)
63 return FALSE;
65 XDR xdrs;
66 xdrstdio_create (&xdrs, out, XDR_ENCODE);
67 bool_t status = writefct (&xdrs, (void *) obj);
68 xdr_destroy (&xdrs);
69 fclose (out);
71 return status;
75 static const char cold_start_file[] = "/var/nis/NIS_COLD_START";
77 directory_obj *
78 readColdStartFile (void)
80 return read_nis_obj (cold_start_file, (iofct_t) _xdr_directory_obj,
81 (freefct_t) nis_free_directory, sizeof (directory_obj));
83 libnsl_hidden_def (readColdStartFile)
85 bool_t
86 writeColdStartFile (const directory_obj *obj)
88 return write_nis_obj (cold_start_file, obj, (iofct_t) _xdr_directory_obj);
91 nis_object *
92 nis_read_obj (const char *name)
94 return read_nis_obj (name, (iofct_t) _xdr_nis_object,
95 (freefct_t) nis_free_object, sizeof (nis_object));
98 bool_t
99 nis_write_obj (const char *name, const nis_object *obj)
101 return write_nis_obj (name, obj, (iofct_t) _xdr_nis_object);