fileio: add 'enforce_newline' argument to write_string_stream()

Add a flag to control whether write_string_stream() should always enforce a
trailing newline character in the file.
This commit is contained in:
Daniel Mack
2015-07-06 17:31:44 -04:00
parent eff8efe671
commit 40beecdb6d
4 changed files with 19 additions and 9 deletions
+12 -2
View File
@@ -302,17 +302,27 @@ static void test_write_string_stream(void) {
f = fdopen(fd, "r");
assert_se(f);
assert_se(write_string_stream(f, "boohoo") < 0);
assert_se(write_string_stream(f, "boohoo", true) < 0);
f = freopen(fn, "r+", f);
assert_se(f);
assert_se(write_string_stream(f, "boohoo") == 0);
assert_se(write_string_stream(f, "boohoo", true) == 0);
rewind(f);
assert_se(fgets(buf, sizeof(buf), f));
assert_se(streq(buf, "boohoo\n"));
f = freopen(fn, "w+", f);
assert_se(f);
assert_se(write_string_stream(f, "boohoo", false) == 0);
rewind(f);
assert_se(fgets(buf, sizeof(buf), f));
printf(">%s<", buf);
assert_se(streq(buf, "boohoo"));
unlink(fn);
}