Skip to content

Commit

Permalink
Windows: use binary I/O everywhere
Browse files Browse the repository at this point in the history
...because newlines matter, at least in the test suite, and because
having a stable file format really helps. No LF/CRLF changes for me,
please.
  • Loading branch information
jktjkt authored and michalvasko committed Dec 16, 2021
1 parent 13ed812 commit b1aa77f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/out.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ ly_out_new_filepath(const char *filepath, struct ly_out **out)
LY_CHECK_ERR_RET(!*out, LOGMEM(NULL), LY_EMEM);

(*out)->type = LY_OUT_FILEPATH;
(*out)->method.fpath.f = fopen(filepath, "w");
(*out)->method.fpath.f = fopen(filepath, "wb");
if (!(*out)->method.fpath.f) {
LOGERR(NULL, LY_ESYS, "Failed to open file \"%s\" (%s).", filepath, strerror(errno));
free(*out);
Expand All @@ -353,7 +353,7 @@ ly_out_filepath(struct ly_out *out, const char *filepath)

/* replace filepath */
f = out->method.fpath.f;
out->method.fpath.f = fopen(filepath, "w");
out->method.fpath.f = fopen(filepath, "wb");
if (!out->method.fpath.f) {
LOGERR(NULL, LY_ESYS, "Failed to open file \"%s\" (%s).", filepath, strerror(errno));
out->method.fpath.f = f;
Expand Down
14 changes: 7 additions & 7 deletions tests/utests/basic/test_inout.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ test_input_file(void **UNUSED(state))
assert_int_equal(LY_EINVAL, ly_in_new_file(NULL, NULL));
assert_null(ly_in_file(NULL, NULL));

assert_int_not_equal(-1, f1 = fopen(__FILE__, "r"));
assert_int_not_equal(-1, f2 = fopen(__FILE__, "r"));
assert_int_not_equal(-1, f1 = fopen(__FILE__, "rb"));
assert_int_not_equal(-1, f2 = fopen(__FILE__, "rb"));

assert_int_equal(LY_EINVAL, ly_in_new_file(f1, NULL));

Expand Down Expand Up @@ -203,8 +203,8 @@ test_output_file(void **UNUSED(state))
char buf[31] = {0};
const char *filepath = TESTS_BIN "/libyang_test_output";

assert_int_not_equal(-1, f1 = fopen(filepath, "w"));
assert_int_not_equal(-1, f2 = fopen(filepath, "w"));
assert_int_not_equal(-1, f1 = fopen(filepath, "wb"));
assert_int_not_equal(-1, f2 = fopen(filepath, "wb"));

/* manipulate with the handler */
assert_int_equal(LY_SUCCESS, ly_out_new_file(f1, &out));
Expand All @@ -218,8 +218,8 @@ test_output_file(void **UNUSED(state))
ly_out_free(out, NULL, 1);

/* writing data */
assert_int_not_equal(-1, f1 = fopen(filepath, "w"));
assert_int_not_equal(-1, f2 = fopen(filepath, "r"));
assert_int_not_equal(-1, f1 = fopen(filepath, "wb"));
assert_int_not_equal(-1, f2 = fopen(filepath, "rb"));

assert_int_equal(LY_SUCCESS, ly_out_new_file(f1, &out));
assert_int_equal(LY_SUCCESS, ly_print(out, "test %s", "print"));
Expand Down Expand Up @@ -260,7 +260,7 @@ test_output_filepath(void **UNUSED(state))
ly_out_free(out, NULL, 1);

/* writing data */
assert_int_not_equal(-1, f1 = fopen(fp1, "r"));
assert_int_not_equal(-1, f1 = fopen(fp1, "rb"));

assert_int_equal(LY_SUCCESS, ly_out_new_filepath(fp1, &out));
assert_int_equal(LY_SUCCESS, ly_print(out, "test %s", "print"));
Expand Down
2 changes: 1 addition & 1 deletion tools/re/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ main(int argc, char *argv[])
fprintf(stderr, "yangre error: command line patterns cannot be mixed with file input.\n");
goto cleanup;
}
infile = fopen(optarg, "r");
infile = fopen(optarg, "rb");
if (!infile) {
fprintf(stderr, "yangre error: unable to open input file %s (%s).\n", optarg, strerror(errno));
goto cleanup;
Expand Down

0 comments on commit b1aa77f

Please sign in to comment.