Home

Traffic Server Software Developers Kit

INKstrndup

Returns a pointer to a duplicate string of specified length.

Prototype

char* INKstrndup (const char *str, int length)

Arguments

str is a pointer to the string to duplicate.

length is the length of the string to duplicate.

Description

Returns a pointer to a new string that's a duplicate of the string pointed to by str that is length bytes long. The new string will be null-terminated. This API is very useful for transforming non-null terminated string values (returned by APIs such as INKMimeHdrFieldStringValueGet) into null-terminated string values. The memory for the new string is allocated using INKmalloc and should be freed by a call to INKfree.

Returns

A pointer to the duplicated string.

[Note] Note

A valid null-terminated string may not be returned if the input str argument is not a valid pointer (i.e. a NULL argument would simply cause INKstrndup to return NULL).