fix in commit today using strnlen, which is only available for gcc.

This adds a BLI_strnlen() to the blenlib.

Patch provided by Sergey Sharybin (nazgul)
This commit is contained in:
Ton Roosendaal
2010-02-27 15:39:13 +00:00
parent c76b6fcb06
commit 7fca47e0cf
2 changed files with 8 additions and 1 deletions

View File

@@ -85,7 +85,7 @@ void BLI_dynstr_append(DynStr *ds, const char *cstr) {
void BLI_dynstr_nappend(DynStr *ds, const char *cstr, int len) {
DynStrElem *dse= malloc(sizeof(*dse));
int cstrlen= strnlen(cstr, len);
int cstrlen= BLI_strnlen(cstr, len);
dse->str= malloc(cstrlen+1);
memcpy(dse->str, cstr, cstrlen);

View File

@@ -342,3 +342,10 @@ void BLI_timestr(double _time, char *str)
str[11]=0;
}
/* determine the length of a fixed-size string */
size_t BLI_strnlen(const char *str, size_t maxlen)
{
const char *end = memchr(str, '\0', maxlen);
return end ? (size_t) (end - str) : maxlen;
}