Back to index

glibc  2.9
nis_clone_obj.c
Go to the documentation of this file.
00001 /* Copyright (c) 1997, 1998, 2004, 2005 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <string.h>
00021 #include <rpc/rpc.h>
00022 #include <rpcsvc/nis.h>
00023 
00024 #include "nis_xdr.h"
00025 
00026 nis_object *
00027 nis_clone_object (const nis_object *src, nis_object *dest)
00028 {
00029   char *addr;
00030   unsigned int size;
00031   XDR xdrs;
00032   nis_object *res = NULL;
00033 
00034   if (src == NULL)
00035     return (NULL);
00036 
00037   size = xdr_sizeof ((xdrproc_t)_xdr_nis_object, (char *) src);
00038   if ((addr = calloc (1, size)) == NULL)
00039     return NULL;
00040 
00041   if (dest == NULL)
00042     {
00043       if ((res = calloc (1, sizeof (nis_object))) == NULL)
00044        goto out;
00045     }
00046   else
00047     res = dest;
00048 
00049   xdrmem_create (&xdrs, addr, size, XDR_ENCODE);
00050   if (!_xdr_nis_object (&xdrs, (nis_object *) src))
00051     goto out2;
00052   xdr_destroy (&xdrs);
00053   xdrmem_create (&xdrs, addr, size, XDR_DECODE);
00054   if (!_xdr_nis_object (&xdrs, res))
00055     {
00056     out2:
00057       if (dest == NULL)
00058        free (res);
00059       res = NULL;
00060     }
00061 
00062   xdr_destroy (&xdrs);
00063  out:
00064   free (addr);
00065 
00066   return res;
00067 }
00068 libnsl_hidden_def (nis_clone_object)