summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-12-06 20:18:18 +0800
committerruki <[email protected]>2025-12-06 20:18:18 +0800
commit4b01b0b660b04415663d2a1b4929a8e07f182387 (patch)
tree3c44ca2c539658db4428c5e5719cc5074ead1a5e
parent9f72cca908c2e2a531adb3276287a2ac28b3e8af (diff)
improve newline in bin2c
-rw-r--r--core/src/xmake/utils/bin2c.c32
1 files changed, 4 insertions, 28 deletions
diff --git a/core/src/xmake/utils/bin2c.c b/core/src/xmake/utils/bin2c.c
index a0e0cf7dd..7cf7aefca 100644
--- a/core/src/xmake/utils/bin2c.c
+++ b/core/src/xmake/utils/bin2c.c
@@ -93,22 +93,8 @@ static tb_bool_t xm_utils_bin2c_dump(tb_stream_ref_t istream,
while (data_pos < data_size) {
// check if we need a new line
if (bytes_in_line >= (tb_size_t)linewidth) {
- // ensure we have space for newline
- if (linesize + 2 > sizeof(line)) {
- // flush line if buffer is full
- if (!tb_stream_bwrit(ostream, (tb_byte_t *)line, linesize)) {
- return tb_false;
- }
- linesize = 0;
- }
- // add newline
- #ifdef TB_CONFIG_OS_WINDOWS
- line[linesize++] = '\r';
- #endif
- line[linesize++] = '\n';
-
- // write line
- if (!tb_stream_bwrit(ostream, (tb_byte_t *)line, linesize)) {
+ // write line (tb_stream_bwrit_line will add newline automatically)
+ if (tb_stream_bwrit_line(ostream, line, linesize) < 0) {
return tb_false;
}
@@ -150,18 +136,8 @@ static tb_bool_t xm_utils_bin2c_dump(tb_stream_ref_t istream,
// flush remaining line
if (linesize > 0) {
- // ensure we have space for newline
- if (linesize + 2 > sizeof(line)) {
- if (!tb_stream_bwrit(ostream, (tb_byte_t *)line, linesize)) {
- return tb_false;
- }
- linesize = 0;
- }
- #ifdef TB_CONFIG_OS_WINDOWS
- line[linesize++] = '\r';
- #endif
- line[linesize++] = '\n';
- if (!tb_stream_bwrit(ostream, (tb_byte_t *)line, linesize)) {
+ // write line (tb_stream_bwrit_line will add newline automatically)
+ if (tb_stream_bwrit_line(ostream, line, linesize) < 0) {
return tb_false;
}
}