Xiqual 0.9.1

In file xitools/ftr.c:

char* xi_strndup

(const char* s, size_t n)

Duplicate a string and return a safe buffer.

Documentation

Duplicate a string and return a safe buffer. The Linux strndup() function uses a memory allocation function that its own documentation warns against. Win32, and possibly other systems, don't have strndup() at all (and I'm not going to research the names on every platform). This function is a working, hopefully safe, implementation of it.

The old strndup() is undefined by Xiqual, and by including xios.h, you'll get strndup defined as xi_strndup. This applies to all platforms. The function itself resides in the core xitools library.

(Linux strndup() uses alloca(), which allocates memory in such a way that the memory is no longer safe to use once the calling function returns. This is clearly not good enough for a library where lots of nodes might be created and passed around like bongs at Woodstock.)

Parameters:
- s The string to duplicate
n - Number of characters to copy
Returns:
A copy of the string with terminating NULL byte.
Author:
Ronny Bangsund
See Also:
calloc()

Alphabetic index



This page was generated with the help of DOC++.