ARPDAS_QNX6 1.0
strdup.c
Go to the documentation of this file.
00001 /* strdup is a replacement for the Lattice function of the same name.
00002 */
00003 #include <string.h>
00004 #include "nortlib.h"
00005 char rcsid_strdup_c[] =
00006   "$Header: /cvsroot/arp-das/nortlib2/src/strdup.c,v 1.3 2000/10/19 14:18:38 nort Exp $";
00007 
00008 /* t = nrtl_strdup(s);
00009 char *t, *s;
00010 
00011 strdup is a replacement for the Lattice function of the same name.
00012 This one provides the same function, but uses my dynamic memory
00013 allocators instead of malloc so it is guaranteed to return a valid
00014 pointer or die!
00015 -*/
00016 char *nrtl_strdup(const char *s) {
00017   char *copy;
00018 
00019   copy = new_memory(strlen(s)+1);
00020   if (copy != NULL) strcpy(copy, s);
00021   return(copy);
00022 }
00023 /*
00024 =Name nrtl_strdup(): Safe strdup() function
00025 =Subject Nortlib
00026 =Name nl_strdup(): Safe strdup() function
00027 =Subject Nortlib
00028 =Synopsis
00029 #include "nortlib.h"
00030 char *nrtl_strdup(const char *s);
00031 char *nl_strdup(const char *s);
00032 
00033 =Description
00034 
00035   nrtl_strdup() and nl_strdup() both provide the functionality of
00036   the semi-standard strdup() function with the exception that
00037   if memory allocation fails, it will cause a fatal error.
00038   As such, both functions are guaranteed to return a
00039   newly-allocated copy of the passed string.
00040   
00041   nrtl_strdup() is the function that is included in the nortlib
00042   library. nl_strdup() is implemented as a macro in nortlib.h
00043   only if memlib.h has not been included, since the name
00044   conflicts with a routine in that library.
00045   
00046 =Returns
00047 
00048   Returns a newly allocated copy of the argument string.
00049   If memory allocation fails, the program will terminate
00050   via =nl_error=(3).
00051 
00052 =SeeAlso
00053   =nl_response=, =new_memory=().
00054 =End
00055 */
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines