git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/3] Added generic string handling code.

From
Petr Baudis <pasky@suse.cz>
Date
May 22, 2007, 13:40 UTC
Message-ID
<20070522134007.GK4489@pasky.or.cz>
In-Reply-To
<1179627869.32181.1284.camel@hurina>
On Sun, May 20, 2007 at 04:24:29AM CEST, Timo Sirainen wrote:
Show 9 quoted lines
> 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.
Show 11 quoted lines
> +{
> +	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?
Show 15 quoted lines
> +{
> +	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
Previous: Timo SirainenNext: Timo Sirainen
Message 4 of 7 in “Added generic string handling code.”
  1. 1/3 Added generic string handling code.Timo Sirainen, May 20, 2007
  2. Alex RiesenMay 20, 2007
  3. Timo SirainenMay 20, 2007
  4. Petr BaudisMay 22, 2007
  5. Timo SirainenMay 23, 2007
  6. Petr BaudisMay 23, 2007
  7. Timo SirainenMay 23, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.