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:
+12
-2
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user