aboutsummaryrefslogtreecommitdiff
path: root/jerry-libc
diff options
context:
space:
mode:
authorPéter Gál <pgal.u-szeged@partner.samsung.com>2018-06-11 21:38:35 +0200
committeryichoi <duddlf.choi@samsung.com>2018-06-12 04:38:35 +0900
commitefa88507833f554bcf2dc1f901e3549529bb99da (patch)
treed0674004190a9b1e838e2ba893f69ee96232fad1 /jerry-libc
parent9ae60a4910b9891759051dd281e0737fd4f7f23e (diff)
Use binary mode when opening via fopen in the tools (#2371)
In the snapshot tool the files were opened in text mode. However the snapshot files are binary files thus it is advised to use the binary mode when opening the files. Specifying the binary mode is a must on Windows platform otherwise the read/write operations are inserting extra '\r' characters. To make the tools consitent across OSes all fopen are now opening files in binary mode. Also update jerry-libc to accept the 'b' modifier and add a test case where the JS file uses CR-LF line endings. JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
Diffstat (limited to 'jerry-libc')
-rw-r--r--jerry-libc/target/posix/jerry-libc-target.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/jerry-libc/target/posix/jerry-libc-target.c b/jerry-libc/target/posix/jerry-libc-target.c
index d0a628c3..4fb7e010 100644
--- a/jerry-libc/target/posix/jerry-libc-target.c
+++ b/jerry-libc/target/posix/jerry-libc-target.c
@@ -113,16 +113,25 @@ fopen (const char *path, /**< file path */
bool truncate = false;
bool create_if_not_exist = false;
bool position_at_end = false;
+ int modifier_position = 1;
assert (path != NULL && mode != NULL);
- assert (mode[1] == '+' || mode[1] == '\0');
+ assert (mode[1] == '\0'
+ || (mode[1] == '+' && mode[2] == '\0')
+ || (mode[1] == 'b' && mode[2] == '\0')
+ || (mode[1] == 'b' && mode[2] == '+' && mode[3] == '\0'));
+
+ if (mode[1] == 'b')
+ {
+ modifier_position = 2;
+ }
switch (mode[0])
{
case 'r':
{
may_read = true;
- may_write = (mode[1] == '+');
+ may_write = (mode[modifier_position] == '+');
break;
}
case 'w':
@@ -130,7 +139,7 @@ fopen (const char *path, /**< file path */
may_write = true;
truncate = true;
create_if_not_exist = true;
- may_read = (mode[1] == '+');
+ may_read = (mode[modifier_position] == '+');
break;
}
case 'a':
@@ -138,7 +147,7 @@ fopen (const char *path, /**< file path */
may_write = true;
position_at_end = true;
create_if_not_exist = true;
- if (mode[1] == '+')
+ if (mode[modifier_position] == '+')
{
assert (false && "unsupported mode a+");
}