Format
#include <string.h> char *_debug_strdup(const char* filename, size_t, line)
Language Level: XPG4, Extension
_debug_strdup is the debug version of strdup. Like strdup, it
reserves storage space for a copy of string
by calling _debug_malloc.
_debug_strdup validates the heap after copying the strings to the target location, and performs this check only when the target is within a heap. _debug_strdup makes an implicit call to _heap_check. If _debug_strdup detects a corrupted heap when it makes a call to _heap_check, it will report the file name and line number in a message.
Note: The alloc(debug) option maps all calls to other string functions and all calls to memory management functions (including a heap-specific version), to their debug counterparts. To prevent a call from being mapped, parenthesize the function name.
Return Value
_debug_strdup returns a pointer to the storage space
containing the copied string. If it cannot reserve storage,
_debug_strdup returns NULL.
Example
This example uses _debug_strdup to duplicate a string
and print the copy.
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
char *string = "this is a copy";
char *newstr;
/* Make newstr point to a duplicate of string */
if ((newstr = strdup(string)) != NULL)
printf("The new string is: %s\n", newstr);
return 0;
/***********************************************
The output should be:
The new string is: this is a copy
***********************************************/
}
![]()
strdup -- Duplicate String
dup -- Associate Second Handle with Open File
dup2 -- Associate Second Handle with Open
File
alloc
miscellaneous option
