summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2010-10-26 20:25:02 +0100
committerLars Wirzenius <liw@liw.fi>2010-10-26 20:25:02 +0100
commit85270841ad91bab30efe89c083dd547cc928283c (patch)
tree2117543f663966fb585187d7bb05045372761179
parent8f231f428f584372b712be61fd098eebd0d439ce (diff)
downloaddynstr-85270841ad91bab30efe89c083dd547cc928283c.tar.gz
Rename dynstr_cat to dynstr_cat_many and introduce 2-argument dynstr_cat.
-rw-r--r--dynstr.c12
-rw-r--r--dynstr.h6
-rw-r--r--unittests.c8
3 files changed, 18 insertions, 8 deletions
diff --git a/dynstr.c b/dynstr.c
index ef5a251..339cf47 100644
--- a/dynstr.c
+++ b/dynstr.c
@@ -209,7 +209,13 @@ Dynstr *dynstr_substr(Dynstr *dynstr, size_t offset, size_t size)
}
-Dynstr *dynstr_cat(Dynstr *dynstr, ...)
+Dynstr *dynstr_cat(Dynstr *dynstr1, Dynstr *dynstr2)
+{
+ return dynstr_cat_many(dynstr1, dynstr2, (Dynstr *) NULL);
+}
+
+
+Dynstr *dynstr_cat_many(Dynstr *dynstr, ...)
{
va_list args;
Dynstr *result;
@@ -446,7 +452,7 @@ static Dynstr *readline_helper(int (*callback)(FILE *, int), FILE *f, int fd)
temp1 = dynstr_new_from_constant_memory(buf, buflen);
if (temp1 == NULL)
goto error;
- temp2 = dynstr_cat(line, temp1, (void *) NULL);
+ temp2 = dynstr_cat(line, temp1);
if (temp2 == NULL)
goto error;
dynstr_free(temp1);
@@ -463,7 +469,7 @@ static Dynstr *readline_helper(int (*callback)(FILE *, int), FILE *f, int fd)
temp1 = dynstr_new_from_constant_memory(buf, buflen);
if (temp1 == NULL)
goto error;
- temp2 = dynstr_cat(line, temp1, (void *) NULL);
+ temp2 = dynstr_cat(line, temp1);
if (temp2 == NULL)
goto error;
dynstr_free(temp1);
diff --git a/dynstr.h b/dynstr.h
index 401dc85..5a6f7ad 100644
--- a/dynstr.h
+++ b/dynstr.h
@@ -116,10 +116,14 @@ bool dynstr_is_empty(Dynstr *dynstr);
/* Create a new string, copying its contents from an existing one. */
Dynstr *dynstr_substr(Dynstr *dynstr, size_t offset, size_t size);
+/* Create a new string by catenating two existing ones. Return NULL on
+ * failure. */
+Dynstr *dynstr_cat(Dynstr *dynstr1, Dynstr *dynstr2);
+
/* Create a new string by catenating zero or more existing ones. The
* argument list has zero or more pointers to dynamic strings, and
* then a NULL pointer. */
-Dynstr *dynstr_cat(Dynstr *dynstr, ...);
+Dynstr *dynstr_cat_many(Dynstr *dynstr, ...);
/* Return value of byte at a given offset. The value is non-negative. If
* the offset is past the end of the string, -1 is returned. */
diff --git a/unittests.c b/unittests.c
index 8671a5b..fc6b663 100644
--- a/unittests.c
+++ b/unittests.c
@@ -525,7 +525,7 @@ static int test_cats_ok(void)
a = new_from_cstring("abc");
b = new_from_cstring("def");
- c = dynstr_cat(a, b, (void *) NULL);
+ c = dynstr_cat(a, b);
size = dynstr_memcpy(buf, c, 0, dynstr_len(c));
FAIL_UNLESS_EQUAL(size, 6);
FAIL_UNLESS_EQUAL(memcmp(buf, "abcdef", 6), 0);
@@ -543,7 +543,7 @@ static int test_cat_returns_NULL_for_first_malloc_failure(void)
a = new_from_cstring("abc");
b = new_from_cstring("def");
dynstr_set_malloc(fail_malloc);
- c = dynstr_cat(a, b, (void *) NULL);
+ c = dynstr_cat(a, b);
FAIL_UNLESS_EQUAL(c, NULL);
return true;
}
@@ -559,7 +559,7 @@ static int test_cat_returns_NULL_for_second_malloc_failure(void)
b = new_from_cstring("def");
dynstr_set_malloc(fail_malloc);
fail_malloc_after = 1;
- c = dynstr_cat(a, b, (void *) NULL);
+ c = dynstr_cat(a, b);
FAIL_UNLESS_EQUAL(c, NULL);
return true;
}
@@ -1135,7 +1135,7 @@ static int readline_test(Dynstr *(*callback)(char *filename))
line1 = dynstr_new_from_constant_cstring(cline1);
line2 = dynstr_new_from_constant_cstring(cline2);
- lines = dynstr_cat(line1, line2, (void *) NULL);
+ lines = dynstr_cat(line1, line2);
if (dynstr_write(fd, lines) != dynstr_len(lines))
abort();
close(fd);