Skip to content

Commit

Permalink
Syn spprintf fix with that of 5.3 and above
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilia Alshanetsky committed Feb 4, 2009
1 parent 7f2d38d commit c4a9c79
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ strcoll \
strdup \
strerror \
strftime \
strnlen \
strptime \
strstr \
strtok_r \
Expand Down
13 changes: 10 additions & 3 deletions main/spprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@

/* }}} */

#if !HAVE_STRNLEN
static size_t strnlen(const char *s, size_t maxlen) {
char *r = memchr(s, '\0', maxlen);
return r ? r-s : maxlen;
}
#endif

/*
* Do format conversion placing the output in buffer
*/
Expand Down Expand Up @@ -547,10 +554,10 @@ static void xbuf_format_converter(smart_str *xbuf, const char *fmt, va_list ap)
case 'v':
s = va_arg(ap, char *);
if (s != NULL) {
if (adjust_precision && precision) {
s_len = precision;
} else {
if (!adjust_precision) {
s_len = strlen(s);
} else {
s_len = strnlen(s, precision);
}
} else {
s = S_NULL;
Expand Down

0 comments on commit c4a9c79

Please sign in to comment.