diff options
author | Guy Harris <guy@alum.mit.edu> | 2016-12-03 17:57:34 -0800 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2016-12-04 03:12:23 +0000 |
commit | dd98856afce144eb19104a6f40c1abedc9069558 (patch) | |
tree | 2136bbdee3544f4324bf214a78aff65da350682c /mergecap.c | |
parent | 5aede1bc50b6bb9ae13926e2249d22d95c12814e (diff) |
Have separate merge APIs for regular file/temporary file/standard output.
This is similar to what we have for opening a dump file - one API that
uses the file name as specified, one that creates a temporary file and
provides the file name, and one that uses the standard output.
All of those APIs handle closing the output file.
Change-Id: I56beea7be347402773460b9148ab31a8f8bc51e1
Reviewed-on: https://code.wireshark.org/review/19059
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'mergecap.c')
-rw-r--r-- | mergecap.c | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/mergecap.c b/mergecap.c index 94fb70b7f0..c64341dd3b 100644 --- a/mergecap.c +++ b/mergecap.c @@ -257,7 +257,6 @@ main(int argc, char *argv[]) #else int file_type = WTAP_FILE_TYPE_SUBTYPE_PCAP; /* default to pcapng format */ #endif - int out_fd; int err = 0; gchar *err_info = NULL; int err_fileno; @@ -428,25 +427,21 @@ main(int argc, char *argv[]) /* open the outfile */ if (strcmp(out_filename, "-") == 0) { - /* use stdout as the outfile */ + /* merge the files to the standard output */ use_stdout = TRUE; - out_fd = 1 /*stdout*/; + status = merge_files_to_stdout(file_type, + (const char *const *) &argv[optind], + in_file_count, do_append, mode, snaplen, + "mergecap", verbose ? &cb : NULL, + &err, &err_info, &err_fileno); } else { - /* open the outfile */ - out_fd = ws_open(out_filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644); - if (out_fd == -1) { - fprintf(stderr, "mergecap: Couldn't open output file %s: %s\n", - out_filename, g_strerror(errno)); - exit(1); - } + /* merge the files to the outfile */ + status = merge_files(out_filename, file_type, + (const char *const *) &argv[optind], in_file_count, + do_append, mode, snaplen, "mergecap", verbose ? &cb : NULL, + &err, &err_info, &err_fileno); } - /* merge the files */ - status = merge_files(out_fd, out_filename, file_type, - (const char *const *) &argv[optind], in_file_count, - do_append, mode, snaplen, "mergecap", verbose ? &cb : NULL, - &err, &err_info, &err_fileno); - switch (status) { case MERGE_OK: break; @@ -462,10 +457,13 @@ main(int argc, char *argv[]) break; case MERGE_ERR_CANT_OPEN_OUTFILE: - fprintf(stderr, "mergecap: Can't open or create %s: %s\n", out_filename, - wtap_strerror(err)); - if (!use_stdout) - ws_close(out_fd); + if (use_stdout) { + fprintf(stderr, "mergecap: Can't set up the standard output: %s\n", + wtap_strerror(err)); + } else { + fprintf(stderr, "mergecap: Can't open or create %s: %s\n", out_filename, + wtap_strerror(err)); + } break; case MERGE_ERR_CANT_READ_INFILE: /* fall through */ |