Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
add sbuf_init
Baptiste Daroussin committed 14 years ago
commit 676c0169bae583d4c634e01e644d5e08acda00e8
parent a212a96
4 files changed +13 -12
modified libpkg/pkg.c
@@ -931,10 +931,7 @@ pkg_open2(struct pkg **pkg_p, struct archive **a, struct archive_entry **ae, con

	assert(path != NULL && path[0] != '\0');

-
	if (manifest == NULL)
-
		manifest = sbuf_new_auto();
-
	else
-
		sbuf_clear(manifest);
+
	sbuf_init(&manifest);

	*a = archive_read_new();
	archive_read_support_compression_all(*a);
modified libpkg/pkg_manifest.c
@@ -105,10 +105,7 @@ urlencode(const char *src, struct sbuf **dest)
	size_t len;
	size_t i;

-
	if (*dest == NULL)
-
		*dest = sbuf_new_auto();
-
	else
-
		sbuf_clear(*dest);
+
	sbuf_init(dest);

	len = strlen(src);
	for (i = 0; i < len; i++) {
@@ -131,10 +128,7 @@ urldecode(const char *src, struct sbuf **dest)
	char c;
	char hex[] = {'\0', '\0', '\0'};

-
	if (*dest == NULL)
-
		*dest = sbuf_new_auto();
-
	else
-
		sbuf_reset(*dest);
+
	sbuf_init(dest);

	len = strlen(src);
	for (i = 0; i < len; i++) {
modified libpkg/private/utils.h
@@ -39,6 +39,7 @@
#define ERROR_SQLITE(db) \
	pkg_emit_error("sqlite: %s", sqlite3_errmsg(db))

+
void sbuf_init(struct sbuf **);
int sbuf_set(struct sbuf **, const char *);
char * sbuf_get(struct sbuf *);
void sbuf_reset(struct sbuf *);
modified libpkg/utils.c
@@ -41,6 +41,15 @@
#include "private/event.h"
#include "private/utils.h"

+
void
+
sbuf_init(struct sbuf **buf)
+
{
+
	if (*buf == NULL)
+
		*buf = sbuf_new_auto();
+
	else
+
		sbuf_clear(*buf);
+
}
+

int
sbuf_set(struct sbuf **buf, const char *str)
{