mirror of
https://github.com/systemd/systemd.git
synced 2024-10-30 23:21:22 +03:00
Merge pull request #8378 from evverx/get-around-freopen
tests: stop using `freopen` in `test-fileio`
This commit is contained in:
commit
6f10433df7
@ -406,7 +406,7 @@ static void test_capeff(void) {
|
|||||||
|
|
||||||
static void test_write_string_stream(void) {
|
static void test_write_string_stream(void) {
|
||||||
char fn[] = "/tmp/test-write_string_stream-XXXXXX";
|
char fn[] = "/tmp/test-write_string_stream-XXXXXX";
|
||||||
_cleanup_fclose_ FILE *f = NULL;
|
FILE *f = NULL;
|
||||||
int fd;
|
int fd;
|
||||||
char buf[64];
|
char buf[64];
|
||||||
|
|
||||||
@ -416,8 +416,9 @@ static void test_write_string_stream(void) {
|
|||||||
f = fdopen(fd, "r");
|
f = fdopen(fd, "r");
|
||||||
assert_se(f);
|
assert_se(f);
|
||||||
assert_se(write_string_stream(f, "boohoo", 0) < 0);
|
assert_se(write_string_stream(f, "boohoo", 0) < 0);
|
||||||
|
f = safe_fclose(f);
|
||||||
|
|
||||||
f = freopen(fn, "r+", f);
|
f = fopen(fn, "r+");
|
||||||
assert_se(f);
|
assert_se(f);
|
||||||
|
|
||||||
assert_se(write_string_stream(f, "boohoo", 0) == 0);
|
assert_se(write_string_stream(f, "boohoo", 0) == 0);
|
||||||
@ -425,8 +426,9 @@ static void test_write_string_stream(void) {
|
|||||||
|
|
||||||
assert_se(fgets(buf, sizeof(buf), f));
|
assert_se(fgets(buf, sizeof(buf), f));
|
||||||
assert_se(streq(buf, "boohoo\n"));
|
assert_se(streq(buf, "boohoo\n"));
|
||||||
|
f = safe_fclose(f);
|
||||||
|
|
||||||
f = freopen(fn, "w+", f);
|
f = fopen(fn, "w+");
|
||||||
assert_se(f);
|
assert_se(f);
|
||||||
|
|
||||||
assert_se(write_string_stream(f, "boohoo", WRITE_STRING_FILE_AVOID_NEWLINE) == 0);
|
assert_se(write_string_stream(f, "boohoo", WRITE_STRING_FILE_AVOID_NEWLINE) == 0);
|
||||||
@ -435,6 +437,7 @@ static void test_write_string_stream(void) {
|
|||||||
assert_se(fgets(buf, sizeof(buf), f));
|
assert_se(fgets(buf, sizeof(buf), f));
|
||||||
printf(">%s<", buf);
|
printf(">%s<", buf);
|
||||||
assert_se(streq(buf, "boohoo"));
|
assert_se(streq(buf, "boohoo"));
|
||||||
|
f = safe_fclose(f);
|
||||||
|
|
||||||
unlink(fn);
|
unlink(fn);
|
||||||
}
|
}
|
||||||
@ -607,7 +610,8 @@ static void test_writing_tmpfile(void) {
|
|||||||
char name[] = "/tmp/test-systemd_writing_tmpfile.XXXXXX";
|
char name[] = "/tmp/test-systemd_writing_tmpfile.XXXXXX";
|
||||||
_cleanup_free_ char *contents = NULL;
|
_cleanup_free_ char *contents = NULL;
|
||||||
size_t size;
|
size_t size;
|
||||||
int fd, r;
|
int r;
|
||||||
|
_cleanup_close_ int fd = -1;
|
||||||
struct iovec iov[3];
|
struct iovec iov[3];
|
||||||
|
|
||||||
iov[0] = IOVEC_MAKE_STRING("abc\n");
|
iov[0] = IOVEC_MAKE_STRING("abc\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user