home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / lib / libc / src / strdup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  1.5 KB  |  65 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "plstr.h"
  20. #include "prmem.h"
  21.  
  22. PR_IMPLEMENT(char *)
  23. PL_strdup(const char *s)
  24. {
  25.     char *rv;
  26.     PRUint32 l;
  27.  
  28.     l = PL_strlen(s);
  29.  
  30.     rv = (char *)malloc(l+1);
  31.     if( (char *)0 == rv ) return rv;
  32.  
  33.     if( (const char *)0 == s )
  34.         *rv = '\0';
  35.     else
  36.         (void)PL_strcpy(rv, s);
  37.  
  38.     return rv;
  39. }
  40.  
  41. PR_IMPLEMENT(void)
  42. PL_strfree(char *s)
  43. {
  44.     free(s);
  45. }
  46.  
  47. PR_IMPLEMENT(char *)
  48. PL_strndup(const char *s, PRUint32 max)
  49. {
  50.     char *rv;
  51.     PRUint32 l;
  52.  
  53.     l = PL_strnlen(s, max);
  54.  
  55.     rv = (char *)malloc(l+1);
  56.     if( (char *)0 == rv ) return rv;
  57.  
  58.     if( (const char *)0 == s )
  59.         *rv = '\0';
  60.     else
  61.         (void)PL_strncpyz(rv, s, l+1);
  62.  
  63.     return rv;
  64. }
  65.