]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
* nis/nis_file.c: Rewrite the two pairs of functions into wrappers
authorUlrich Drepper <drepper@redhat.com>
Thu, 28 Jul 2005 07:10:28 +0000 (07:10 +0000)
committerUlrich Drepper <drepper@redhat.com>
Thu, 28 Jul 2005 07:10:28 +0000 (07:10 +0000)
around a pair of new, generalized functions.  22% size reduction.

ChangeLog
nis/nis_file.c

index 11f6fde74456bbf8ce3eca8920135dbd5d4e0e15..4d2767c6ec102dfc3510d6246604575d65f01a9c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2005-07-28  Ulrich Drepper  <drepper@redhat.com>
+
+       * nis/nis_file.c: Rewrite the two pairs of functions into wrappers
+       around a pair of new, generalized functions.  22% size reduction.
+
 2005-07-27  Ulrich Drepper  <drepper@redhat.com>
 
        * nis/nis_xdr.c: Remove unnecessary cast which might hide bugs.
index 1f2295787cadccc0138a7106a9e7eba3844660a4..566f30c48c8cb701b9b29e7ae554499fca0ec50a 100644 (file)
@@ -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.
 
 #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);
 }