Windows: use binary I/O everywhere
...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.
diff --git a/src/out.c b/src/out.c
index 868e711..c4c80d9 100644
--- a/src/out.c
+++ b/src/out.c
@@ -329,7 +329,7 @@
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);
@@ -353,7 +353,7 @@
/* 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;
diff --git a/tests/utests/basic/test_inout.c b/tests/utests/basic/test_inout.c
index 99af939..b3b605f 100644
--- a/tests/utests/basic/test_inout.c
+++ b/tests/utests/basic/test_inout.c
@@ -83,8 +83,8 @@
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));
@@ -203,8 +203,8 @@
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));
@@ -218,8 +218,8 @@
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"));
@@ -260,7 +260,7 @@
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"));
diff --git a/tools/re/main.c b/tools/re/main.c
index 9ef32eb..2292b2a 100644
--- a/tools/re/main.c
+++ b/tools/re/main.c
@@ -146,7 +146,7 @@
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;