aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/blogc-git-receiver/pre-receive.c5
-rw-r--r--src/blogc/main.c9
-rw-r--r--src/common/stdin.c6
-rw-r--r--src/common/stdin.h4
-rw-r--r--tests/common/check_stdin.c8
5 files changed, 22 insertions, 10 deletions
diff --git a/src/blogc-git-receiver/pre-receive.c b/src/blogc-git-receiver/pre-receive.c
index 76cf1bf..71e84e8 100644
--- a/src/blogc-git-receiver/pre-receive.c
+++ b/src/blogc-git-receiver/pre-receive.c
@@ -170,8 +170,9 @@ default_sym:
bc_strv_free(pieces);
}
else {
- char *input = bc_stdin_read();
- master = bgr_pre_receive_parse(input, strlen(input));
+ size_t input_len;
+ char *input = bc_stdin_read(&input_len);
+ master = bgr_pre_receive_parse(input, input_len);
free(input);
}
diff --git a/src/blogc/main.c b/src/blogc/main.c
index b1ea6a9..628c481 100644
--- a/src/blogc/main.c
+++ b/src/blogc/main.c
@@ -270,10 +270,11 @@ main(int argc, char **argv)
}
if (input_stdin) {
- char *in = bc_stdin_read();
- bc_slist_t *in_list = blogc_filelist_parse(in, strlen(in));
- free(in);
- sources = bc_slist_append_list(sources, in_list);
+ size_t input_len;
+ char *input = bc_stdin_read(&input_len);
+ bc_slist_t *input_list = blogc_filelist_parse(input, input_len);
+ free(input);
+ sources = bc_slist_append_list(sources, input_list);
}
if (!listing && bc_slist_length(sources) == 0) {
diff --git a/src/common/stdin.c b/src/common/stdin.c
index a460247..c4bf746 100644
--- a/src/common/stdin.c
+++ b/src/common/stdin.c
@@ -14,11 +14,15 @@
// splitted in single file to make it easier to test
char*
-bc_stdin_read(void)
+bc_stdin_read(size_t *len)
{
+ if (len == NULL)
+ return NULL;
+
int c;
bc_string_t *rv = bc_string_new();
while (EOF != (c = fgetc(stdin)))
bc_string_append_c(rv, c);
+ *len = rv->len;
return bc_string_free(rv, false);
}
diff --git a/src/common/stdin.h b/src/common/stdin.h
index e6bd7a0..be99922 100644
--- a/src/common/stdin.h
+++ b/src/common/stdin.h
@@ -9,6 +9,8 @@
#ifndef _STDIN_H
#define _STDIN_H
-char* bc_stdin_read(void);
+#include <stddef.h>
+
+char* bc_stdin_read(size_t *len);
#endif /* _STDIN_H */
diff --git a/tests/common/check_stdin.c b/tests/common/check_stdin.c
index 716916d..3d90202 100644
--- a/tests/common/check_stdin.c
+++ b/tests/common/check_stdin.c
@@ -27,19 +27,23 @@ __wrap_fgetc(FILE *stream)
static void
test_read(void **state)
{
+ assert_null(bc_stdin_read(NULL));
will_return(__wrap_fgetc, EOF);
- char *t = bc_stdin_read();
+ size_t len;
+ char *t = bc_stdin_read(&len);
assert_non_null(t);
assert_string_equal(t, "");
+ assert_int_equal(len, 0);
free(t);
will_return(__wrap_fgetc, 'b');
will_return(__wrap_fgetc, 'o');
will_return(__wrap_fgetc, 'l');
will_return(__wrap_fgetc, 'a');
will_return(__wrap_fgetc, EOF);
- t = bc_stdin_read();
+ t = bc_stdin_read(&len);
assert_non_null(t);
assert_string_equal(t, "bola");
+ assert_int_equal(len, 4);
free(t);
}