From f4d6c7abbc32c5eee10e4f771f5e7fc1cc2639ef Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Tue, 22 Nov 2016 10:01:29 -0800 Subject: On Windows, put the standard output in binary mode if we're writing the capture file to it. While we're at it, explicitly compare the restult of strcmp() against 0, to make it clearer that it's testing for the argument *not* being equal to "-". Bug: 13165 Change-Id: Ic63085abb2de5f5c60d2101d19c1a269b7e0c9d7 Reviewed-on: https://code.wireshark.org/review/18924 Reviewed-by: Guy Harris --- text2pcap.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'text2pcap.c') diff --git a/text2pcap.c b/text2pcap.c index 65d6547b45..1c2e415cb1 100644 --- a/text2pcap.c +++ b/text2pcap.c @@ -1758,7 +1758,7 @@ parse_options (int argc, char *argv[]) exit(1); } - if (strcmp(argv[optind], "-")) { + if (strcmp(argv[optind], "-") != 0) { input_filename = g_strdup(argv[optind]); input_file = ws_fopen(input_filename, "rb"); if (!input_file) { @@ -1771,7 +1771,8 @@ parse_options (int argc, char *argv[]) input_file = stdin; } - if (strcmp(argv[optind+1], "-")) { + if (strcmp(argv[optind+1], "-") != 0) { + /* Write to a file. Open the file, in binary mode. */ output_filename = g_strdup(argv[optind+1]); output_file = ws_fopen(output_filename, "wb"); if (!output_file) { @@ -1780,6 +1781,16 @@ parse_options (int argc, char *argv[]) exit(1); } } else { + /* Write to the standard output. */ +#ifdef _WIN32 + /* Put the standard output in binary mode. */ + if (_setmode(1, O_BINARY) == -1) { + /* "Should not happen" */ + fprintf(stderr, "Cannot put standard output in binary mode: %s\n", + g_strerror(errno)); + exit(1); + } +#endif output_filename = "Standard output"; output_file = stdout; } -- cgit v1.2.1