Back to index

glibc  2.9
nis_clone_dir.c
Go to the documentation of this file.
00001 /* Copyright (c) 1997, 1998, 2005, 2006 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 directory_obj *
00027 nis_clone_directory (const directory_obj *src, directory_obj *dest)
00028 {
00029   char *addr;
00030   unsigned int size;
00031   XDR xdrs;
00032 
00033   if (src == NULL)
00034     return NULL;
00035 
00036   size = xdr_sizeof ((xdrproc_t)_xdr_directory_obj, (char *)src);
00037   if ((addr = calloc(1, size)) == NULL)
00038     return NULL;
00039 
00040   xdrmem_create(&xdrs, addr, size, XDR_ENCODE);
00041   if (!_xdr_directory_obj (&xdrs, (directory_obj *)src))
00042     {
00043       xdr_destroy (&xdrs);
00044       free (addr);
00045       return NULL;
00046     }
00047   xdr_destroy (&xdrs);
00048 
00049   directory_obj *res;
00050   if (dest == NULL)
00051     {
00052       if ((res = calloc (1, sizeof (directory_obj))) == NULL)
00053        {
00054          free (addr);
00055          return NULL;
00056        }
00057     }
00058   else
00059     res = dest;
00060 
00061   xdrmem_create (&xdrs, addr, size, XDR_DECODE);
00062   if (!_xdr_directory_obj (&xdrs, res))
00063     {
00064       xdr_destroy (&xdrs);
00065       if (res != dest)
00066        free (res);
00067       free (addr);
00068       return NULL;
00069     }
00070   xdr_destroy (&xdrs);
00071   free (addr);
00072 
00073   return res;
00074 }