Sun Java System Web Server 7.0 NSAPI Developer's Guide

STRDUP

The STRDUP macro is a platform-independent substitute for the C library routine strdup. It creates a new copy of a string in the request’s memory pool. The memory can be explicitly freed by a call to FREE. If the memory is not explicitly freed, it is automatically freed after processing the current request. If pooled memory has been disabled in the configuration file (with the pool-init built-in SAF), PERM_STRDUP and STRDUP both obtain their memory from the system heap. However, since the memory allocated by STRDUP is automatically freed, it should not be shared between threads.

The STRDUP routine is functionally equivalent to:


newstr = (char *) MALLOC(strlen(str) + 1);
strcpy(newstr, str);

         

Syntax

char *STRDUP(char *ptr);

Returns

A pointer to the new string.

Parameters

char *ptr is a pointer to a string.

Example

char *name1 = "MyName";
char *name2 = STRDUP(name1);

See Also

CALLOC,MALLOC, FREE, REALLOC, PERM_STRDUP