Skip to content

Commit 2a9ff07

Browse files
committedFeb 1, 2025·
Set binary mode for stdin and stdout on Windows
1 parent 3912de7 commit 2a9ff07

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed
 

‎src/dukpt-tool.c

+15-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file dukpt-tool.c
33
* @brief Simple DUKPT tool
44
*
5-
* Copyright 2021-2023 Leon Lynch
5+
* Copyright 2021-2025 Leon Lynch
66
*
77
* This program is free software; you can redistribute it and/or
88
* modify it under the terms of the GNU Lesser General Public
@@ -35,6 +35,12 @@
3535

3636
#include <time.h> // for time, gmtime and strftime
3737

38+
#ifdef _WIN32
39+
// For _setmode
40+
#include <fcntl.h>
41+
#include <io.h>
42+
#endif
43+
3844
// Globals
3945
static uint8_t* bdk = NULL;
4046
static size_t bdk_len = 0;
@@ -681,6 +687,10 @@ static void* read_file(FILE* file, size_t* len)
681687
return NULL;
682688
}
683689

690+
#ifdef _WIN32
691+
_setmode(_fileno(file), _O_BINARY);
692+
#endif
693+
684694
do {
685695
// Grow buffer
686696
buf_len += block_size;
@@ -787,6 +797,10 @@ static int parse_dec_str(const char* str, uint8_t* buf, size_t* buf_len)
787797
static void output_buf(const void* buf, size_t length)
788798
{
789799
if (output_format == DUKPT_TOOL_OUTPUT_FORMAT_RAW) {
800+
#ifdef _WIN32
801+
_setmode(_fileno(stdout), _O_BINARY);
802+
#endif
803+
790804
// Output buffer as raw bytes
791805
fwrite(buf, length, 1, stdout);
792806
return;

0 commit comments

Comments
 (0)
Please sign in to comment.