strndup is not avuilable with MSVC

This commit is contained in:
Adrian Johnson 2016-10-07 07:38:37 +10:30
parent 55f8c6d9f4
commit 4790a3663d
2 changed files with 15 additions and 3 deletions

View file

@ -627,8 +627,16 @@ split_label (const char* label, int *num)
if (i < len) if (i < len)
sscanf (label + i, "%d", num); sscanf (label + i, "%d", num);
if (i > 0) if (i > 0) {
return strndup (label, i); char *s;
s = _cairo_malloc (i + 1);
if (!s)
return NULL;
memcpy (s, label, i);
s[i] = 0;
return s;
}
return NULL; return NULL;
} }

View file

@ -134,7 +134,11 @@ layout_paragraph (cairo_t *cr)
cairo_text_extents (cr, begin, &text_extents); cairo_text_extents (cr, begin, &text_extents);
*end = ' '; *end = ' ';
if (text_extents.width + 2*MARGIN > PAGE_WIDTH) { if (text_extents.width + 2*MARGIN > PAGE_WIDTH) {
paragraph_text[paragraph_num_lines++] = strndup (begin, prev_end - begin); int len = prev_end - begin;
char *s = malloc (len);
memcpy (s, begin, len);
s[0] = 0;
paragraph_text[paragraph_num_lines++] = s;
begin = prev_end + 1; begin = prev_end + 1;
} }
prev_end = end; prev_end = end;