non-zero-terminated source string.
svn path=/trunk/yasm/; revision=649
#else
/* strdup() implementation with error checking (using xmalloc). */
/*@only@*/ char *xstrdup(const char *str);
+/*@only@*/ char *xstrndup(const char *str, size_t len);
/* Error-checking memory allocation routines in xmalloc.c. */
/*@only@*/ /*@out@*/ void *xmalloc(size_t size);
return (copy);
}
#endif
+
+char *
+xstrndup(const char *str, size_t len)
+{
+ char *copy;
+
+ copy = xmalloc(len+1);
+ memcpy(copy, str, len);
+ copy[len] = '\0';
+ return (copy);
+}
#else
/* strdup() implementation with error checking (using xmalloc). */
/*@only@*/ char *xstrdup(const char *str);
+/*@only@*/ char *xstrndup(const char *str, size_t len);
/* Error-checking memory allocation routines in xmalloc.c. */
/*@only@*/ /*@out@*/ void *xmalloc(size_t size);
return (copy);
}
#endif
+
+char *
+xstrndup(const char *str, size_t len)
+{
+ char *copy;
+
+ copy = xmalloc(len+1);
+ memcpy(copy, str, len);
+ copy[len] = '\0';
+ return (copy);
+}
#else
/* strdup() implementation with error checking (using xmalloc). */
/*@only@*/ char *xstrdup(const char *str);
+/*@only@*/ char *xstrndup(const char *str, size_t len);
/* Error-checking memory allocation routines in xmalloc.c. */
/*@only@*/ /*@out@*/ void *xmalloc(size_t size);