diff options
Diffstat (limited to 'nis/nis_file.c')
-rw-r--r-- | nis/nis_file.c | 93 |
1 files changed, 58 insertions, 35 deletions
diff --git a/nis/nis_file.c b/nis/nis_file.c index 566f30c48c..1f2295787c 100644 --- a/nis/nis_file.c +++ b/nis/nis_file.c @@ -1,4 +1,4 @@ -/* Copyright (c) 1997, 1998, 1999, 2004, 2005 Free Software Foundation, Inc. +/* Copyright (c) 1997, 1998, 1999, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997. @@ -23,30 +23,27 @@ #include <rpcsvc/nis.h> #include "nis_xdr.h" -typedef bool_t (*iofct_t) (XDR *, void *); -typedef void (*freefct_t) (void *); - +static const char cold_start_file[] = "/var/nis/NIS_COLD_START"; -static void * -read_nis_obj (const char *name, iofct_t readfct, freefct_t freefct, - size_t objsize) +directory_obj * +readColdStartFile (void) { - FILE *in = fopen (name, "rc"); + FILE *in = fopen (cold_start_file, "rc"); if (in == NULL) return NULL; - void *obj = calloc (1, objsize); + directory_obj *obj = calloc (1, sizeof (directory_obj)); if (obj != NULL) { XDR xdrs; xdrstdio_create (&xdrs, in, XDR_DECODE); - bool_t status = readfct (&xdrs, obj); + bool_t status = _xdr_directory_obj (&xdrs, obj); xdr_destroy (&xdrs); if (!status) { - freefct (obj); + nis_free_directory (obj); obj = NULL; } } @@ -55,49 +52,75 @@ read_nis_obj (const char *name, iofct_t readfct, freefct_t freefct, return obj; } +libnsl_hidden_def (readColdStartFile) -static bool_t -write_nis_obj (const char *name, const void *obj, iofct_t writefct) +bool_t +writeColdStartFile (const directory_obj *obj) { - FILE *out = fopen (name, "w"); + XDR xdrs; + FILE *out; + bool_t status; + + out = fopen (cold_start_file, "wb"); if (out == NULL) return FALSE; - XDR xdrs; xdrstdio_create (&xdrs, out, XDR_ENCODE); - bool_t status = writefct (&xdrs, (void *) obj); + status = _xdr_directory_obj (&xdrs, (directory_obj *) obj); xdr_destroy (&xdrs); fclose (out); return status; } +nis_object * +nis_read_obj (const char *name) +{ + XDR xdrs; + FILE *in; + bool_t status; + nis_object *obj; -static const char cold_start_file[] = "/var/nis/NIS_COLD_START"; + in = fopen (name, "rb"); + if (in == NULL) + return NULL; -directory_obj * -readColdStartFile (void) -{ - return read_nis_obj (cold_start_file, (iofct_t) _xdr_directory_obj, - (freefct_t) nis_free_directory, sizeof (directory_obj)); -} -libnsl_hidden_def (readColdStartFile) + obj = calloc (1, sizeof (nis_object)); + if (obj == NULL) + { + fclose (in); + return NULL; + } -bool_t -writeColdStartFile (const directory_obj *obj) -{ - return write_nis_obj (cold_start_file, obj, (iofct_t) _xdr_directory_obj); -} + xdrstdio_create (&xdrs, in, XDR_DECODE); + status =_xdr_nis_object (&xdrs, obj); + xdr_destroy (&xdrs); + fclose (in); -nis_object * -nis_read_obj (const char *name) -{ - return read_nis_obj (name, (iofct_t) _xdr_nis_object, - (freefct_t) nis_free_object, sizeof (nis_object)); + if (status) + return obj; + else + { + nis_free_object (obj); + return NULL; + } } bool_t nis_write_obj (const char *name, const nis_object *obj) { - return write_nis_obj (name, obj, (iofct_t) _xdr_nis_object); + XDR xdrs; + FILE *out; + bool_t status; + + out = fopen (name, "wb"); + if (out == NULL) + return FALSE; + + xdrstdio_create (&xdrs, out, XDR_ENCODE); + status = _xdr_nis_object (&xdrs, (nis_object *) obj); + xdr_destroy (&xdrs); + fclose (out); + + return status; } |