aboutsummaryrefslogtreecommitdiffstats
path: root/file.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2005-02-17 03:05:54 +0000
committerGuy Harris <guy@alum.mit.edu>2005-02-17 03:05:54 +0000
commit9105b04e4bdc3b9954ba474652c171ebcd32cadb (patch)
tree42adc7ae815b3fa17187af437c07eee04de224ce /file.c
parent60ffea9d7a9db78a3910c8da27f5081a31555fb9 (diff)
Have "cf_merge_files()" take a pointer-to-pointer-to-char as the output
file name argument; if the pointed-to pointer is null, it opens a temporary file, and sets that pointer to a mallocated copy of the pathname of the temporary file. It no longer needs a file descriptor as an argument. svn path=/trunk/; revision=13419
Diffstat (limited to 'file.c')
-rw-r--r--file.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/file.c b/file.c
index 09d074038f..43c3990322 100644
--- a/file.c
+++ b/file.c
@@ -939,11 +939,14 @@ read_packet(capture_file *cf, long offset)
}
cf_status_t
-cf_merge_files(const char *out_filename, int out_fd, int in_file_count,
+cf_merge_files(char **out_filenamep, int in_file_count,
char *const *in_filenames, int file_type, gboolean do_append)
{
merge_in_file_t *in_files;
wtap *wth;
+ char *out_filename;
+ char tmpname[128+1];
+ int out_fd;
wtap_dumper *pdh;
int open_err, read_err, write_err, close_err;
gchar *err_info;
@@ -977,6 +980,26 @@ cf_merge_files(const char *out_filename, int out_fd, int in_file_count,
return CF_ERROR;
}
+ if (*out_filenamep != NULL) {
+ out_filename = *out_filenamep;
+ out_fd = open(out_filename, O_CREAT|O_TRUNC|O_BINARY, 0600);
+ if (out_fd == -1)
+ open_err = errno;
+ } else {
+ out_fd = create_tempfile(tmpname, sizeof tmpname, "ether");
+ if (out_fd == -1)
+ open_err = errno;
+ out_filename = g_strdup(tmpname);
+ *out_filenamep = out_filename;
+ }
+ if (out_fd == -1) {
+ err_info = NULL;
+ merge_close_in_files(in_file_count, in_files);
+ free(in_files);
+ cf_open_failure_alert_box(out_filename, open_err, NULL, TRUE, file_type);
+ return CF_ERROR;
+ }
+
pdh = wtap_dump_fdopen(out_fd, file_type,
merge_select_frame_type(in_file_count, in_files),
merge_max_snapshot_length(in_file_count, in_files), &open_err);