* nis/nis_file.c: Rewrite the two pairs of functions into wrappers
around a pair of new, generalized functions. 22% size reduction.
This commit is contained in:
parent
c3c45d9cde
commit
eca086a613
@ -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.
|
||||
|
105
nis/nis_file.c
105
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;
|
||||
}
|
||||
|
||||
static bool_t
|
||||
write_nis_obj (const char *name, const void *obj, iofct_t writefct)
|
||||
{
|
||||
FILE *out = fopen (name, "w");
|
||||
if (out == NULL)
|
||||
return FALSE;
|
||||
|
||||
XDR xdrs;
|
||||
xdrstdio_create (&xdrs, out, XDR_ENCODE);
|
||||
bool_t status = writefct (&xdrs, (void *) obj);
|
||||
xdr_destroy (&xdrs);
|
||||
fclose (out);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
static const char cold_start_file[] = "/var/nis/NIS_COLD_START";
|
||||
|
||||
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)
|
||||
|
||||
bool_t
|
||||
writeColdStartFile (const directory_obj *obj)
|
||||
{
|
||||
XDR xdrs;
|
||||
FILE *out;
|
||||
bool_t status;
|
||||
|
||||
out = fopen (cold_start_file, "wb");
|
||||
if (out == NULL)
|
||||
return FALSE;
|
||||
|
||||
xdrstdio_create (&xdrs, out, XDR_ENCODE);
|
||||
status = _xdr_directory_obj (&xdrs, (directory_obj *) obj);
|
||||
xdr_destroy (&xdrs);
|
||||
fclose (out);
|
||||
|
||||
return status;
|
||||
return write_nis_obj (cold_start_file, obj, (iofct_t) _xdr_directory_obj);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
obj = calloc (1, sizeof (nis_object));
|
||||
if (obj == NULL)
|
||||
{
|
||||
fclose (in);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
xdrstdio_create (&xdrs, in, XDR_DECODE);
|
||||
status =_xdr_nis_object (&xdrs, obj);
|
||||
xdr_destroy (&xdrs);
|
||||
fclose (in);
|
||||
|
||||
if (status)
|
||||
return obj;
|
||||
else
|
||||
{
|
||||
nis_free_object (obj);
|
||||
return NULL;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user