summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2016-11-22 10:01:29 -0800
committerGuy Harris <guy@alum.mit.edu>2016-11-22 18:39:35 +0000
commitf4d6c7abbc32c5eee10e4f771f5e7fc1cc2639ef (patch)
treed2e45f0f02f41f21691b12cbbe43a10e31107b8d
parentfb9a356e46c5adbc74e9d117463c0fb2b4778afe (diff)
downloadwireshark-f4d6c7abbc32c5eee10e4f771f5e7fc1cc2639ef.tar.gz
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 <guy@alum.mit.edu>
-rw-r--r--text2pcap.c15
1 files changed, 13 insertions, 2 deletions
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;
}