aboutsummaryrefslogtreecommitdiff
path: root/nis
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2005-07-28 07:10:28 +0000
committerUlrich Drepper <drepper@redhat.com>2005-07-28 07:10:28 +0000
commiteca086a6135354d530a495a4e61b58bdc3fb48ee (patch)
tree60a56e3db6c6b8dc49438d797f007bfea4e32248 /nis
parentc3c45d9cded782d674bbf0326aff3315050e4092 (diff)
downloadglibc-eca086a6135354d530a495a4e61b58bdc3fb48ee.zip
glibc-eca086a6135354d530a495a4e61b58bdc3fb48ee.tar.gz
glibc-eca086a6135354d530a495a4e61b58bdc3fb48ee.tar.bz2
* nis/nis_file.c: Rewrite the two pairs of functions into wrappers
around a pair of new, generalized functions. 22% size reduction.
Diffstat (limited to 'nis')
-rw-r--r--nis/nis_file.c93
1 files changed, 35 insertions, 58 deletions
diff --git a/nis/nis_file.c b/nis/nis_file.c
index 1f22957..566f30c 100644
--- a/nis/nis_file.c
+++ b/nis/nis_file.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997, 1998, 1999, 2004 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1998, 1999, 2004, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
@@ -23,27 +23,30 @@
#include <rpcsvc/nis.h>
#include "nis_xdr.h"
-static const char cold_start_file[] = "/var/nis/NIS_COLD_START";
+typedef bool_t (*iofct_t) (XDR *, void *);
+typedef void (*freefct_t) (void *);
-directory_obj *
-readColdStartFile (void)
+
+static void *
+read_nis_obj (const char *name, iofct_t readfct, freefct_t freefct,
+ size_t objsize)
{
- FILE *in = fopen (cold_start_file, "rc");
+ FILE *in = fopen (name, "rc");
if (in == NULL)
return NULL;
- directory_obj *obj = calloc (1, sizeof (directory_obj));
+ void *obj = calloc (1, objsize);
if (obj != NULL)
{
XDR xdrs;
xdrstdio_create (&xdrs, in, XDR_DECODE);
- bool_t status = _xdr_directory_obj (&xdrs, obj);
+ bool_t status = readfct (&xdrs, obj);
xdr_destroy (&xdrs);
if (!status)
{
- nis_free_directory (obj);
+ freefct (obj);
obj = NULL;
}
}
@@ -52,75 +55,49 @@ readColdStartFile (void)
return obj;
}
-libnsl_hidden_def (readColdStartFile)
-bool_t
-writeColdStartFile (const directory_obj *obj)
+static bool_t
+write_nis_obj (const char *name, const void *obj, iofct_t writefct)
{
- XDR xdrs;
- FILE *out;
- bool_t status;
-
- out = fopen (cold_start_file, "wb");
+ FILE *out = fopen (name, "w");
if (out == NULL)
return FALSE;
+ XDR xdrs;
xdrstdio_create (&xdrs, out, XDR_ENCODE);
- status = _xdr_directory_obj (&xdrs, (directory_obj *) obj);
+ bool_t status = writefct (&xdrs, (void *) 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;
- in = fopen (name, "rb");
- if (in == NULL)
- return NULL;
+static const char cold_start_file[] = "/var/nis/NIS_COLD_START";
- obj = calloc (1, sizeof (nis_object));
- if (obj == NULL)
- {
- fclose (in);
- 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)
- xdrstdio_create (&xdrs, in, XDR_DECODE);
- status =_xdr_nis_object (&xdrs, obj);
- xdr_destroy (&xdrs);
- fclose (in);
+bool_t
+writeColdStartFile (const directory_obj *obj)
+{
+ return write_nis_obj (cold_start_file, obj, (iofct_t) _xdr_directory_obj);
+}
- if (status)
- return obj;
- else
- {
- nis_free_object (obj);
- return NULL;
- }
+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));
}
bool_t
nis_write_obj (const char *name, const nis_object *obj)
{
- 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;
+ return write_nis_obj (name, obj, (iofct_t) _xdr_nis_object);
}