home *** CD-ROM | disk | FTP | other *** search
- /* > C.Strndup - save a string on the heap; return pointer to it */
-
- #include <string.h>
- #include <stddef.h>
- #include <stdlib.h>
- #include "utils.h"
-
- char *strndup (const char *str, int n)
- {
- char *p = malloc (n+1);
-
- if ( p == NULL )
- fatal (1, "Not enough memory to save string\n");
-
- if ( n > 0 )
- memcpy (p, str, n);
-
- p[n] = '\0';
-
- return p;
- }
-