On Sun, May 20, 2007 at 04:24:29AM CEST, Timo Sirainen wrote: > diff --git a/str.c b/str.c > new file mode 100644 > index 0000000..d46e7f4 > --- /dev/null > +++ b/str.c > @@ -0,0 +1,40 @@ > +#include "str.h" > + > +void _str_append(struct string *str, const char *cstr) _ is reserved namespace. > +{ > + unsigned int avail = str->size - str->len; > + unsigned int len = strlen(cstr); > + > + if (len >= avail) { > + len = avail - 1; > + str->overflowed = 1; > + } > + memcpy(str->buf + str->len, cstr, len); > + str->len += len; > + str->buf[str->len] = '\0'; You can copy len + 1 and avoid this assignment. > +} > + > +void _str_printfa(struct string *str, const char *fmt, ...) printfA? > +{ > + unsigned int avail = str->size - str->len; > + va_list va; > + int ret; > + > + va_start(va, fmt); > + ret = vsnprintf(str->buf + str->len, avail, fmt, va); > + if (ret < avail) > + str->len += ret; > + else { > + str->len += avail - 1; > + str->overflowed = 1; > + } > + va_end(va); > +} -- Petr "Pasky" Baudis Stuff: http://pasky.or.cz/ Ever try. Ever fail. No matter. // Try again. Fail again. Fail better. -- Samuel Beckett - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html