aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--file.c25
-rw-r--r--file.h8
-rw-r--r--gtk/drag_and_drop.c12
-rw-r--r--gtk/file_dlg.c20
4 files changed, 44 insertions, 21 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);
diff --git a/file.h b/file.h
index bb56e31585..5c10c314f1 100644
--- a/file.h
+++ b/file.h
@@ -406,8 +406,9 @@ char *cf_read_error_message(int err, const gchar *err_info);
* Merge two (or more) capture files into one.
* @todo is this the right place for this function? It doesn't have to do a lot with capture_file.
*
- * @param out_filename output filename
- * @param out_fd output file descriptor
+ * @param out_filename pointer to output filename; if output filename is
+ * NULL, a temporary file name is generated and *out_filename is set
+ * to point to the generated file name
* @param in_file_count the number of input files to merge
* @param in_filnames array of input filenames
* @param file_type the output filetype
@@ -415,8 +416,7 @@ char *cf_read_error_message(int err, const gchar *err_info);
* @return one of cf_status_t
*/
cf_status_t
-cf_merge_files(const char *out_filename, int out_fd, int in_file_count,
+cf_merge_files(char **out_filename, int in_file_count,
char *const *in_filenames, int file_type, gboolean do_append);
-
#endif /* file.h */
diff --git a/gtk/drag_and_drop.c b/gtk/drag_and_drop.c
index fbdbafb897..4a124c706b 100644
--- a/gtk/drag_and_drop.c
+++ b/gtk/drag_and_drop.c
@@ -134,20 +134,18 @@ dnd_uri2filename(gchar *cf_name)
static void
dnd_merge_files(int in_file_count, char **in_filenames)
{
- int out_fd;
+ char *tmpname;
gboolean merge_ok;
int err;
- char tmpname[128+1];
-
-
- out_fd = create_tempfile(tmpname, sizeof tmpname, "ether");
/* merge the files in chonological order */
- merge_ok = cf_merge_files(tmpname, out_fd, in_file_count, in_filenames,
+ tmpname = NULL;
+ merge_ok = cf_merge_files(&tmpname, in_file_count, in_filenames,
WTAP_FILE_PCAP, FALSE);
if (!merge_ok) {
/* merge failed */
+ g_free(tmpname);
return;
}
@@ -159,8 +157,10 @@ dnd_merge_files(int in_file_count, char **in_filenames)
just leave it around so that the user can, after they
dismiss the alert box popped up for the open error,
try again. */
+ g_free(tmpname);
return;
}
+ g_free(tmpname);
switch (cf_read(&cfile)) {
diff --git a/gtk/file_dlg.c b/gtk/file_dlg.c
index 92d16ed651..40f9581347 100644
--- a/gtk/file_dlg.c
+++ b/gtk/file_dlg.c
@@ -1000,8 +1000,7 @@ file_merge_ok_cb(GtkWidget *w, gpointer fs) {
int err;
cf_status_t merge_status;
char *in_filenames[2];
- int out_fd;
- char tmpname[128+1];
+ char *tmpname;
#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
cf_name = g_strdup(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fs)));
@@ -1027,30 +1026,28 @@ file_merge_ok_cb(GtkWidget *w, gpointer fs) {
return;
}
- out_fd = create_tempfile(tmpname, sizeof tmpname, "ether");
-
/* merge or append the two files */
rb = OBJECT_GET_DATA(w, E_MERGE_CHRONO_KEY);
+ tmpname = NULL;
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (rb))) {
/* chronological order */
in_filenames[0] = cfile.filename;
in_filenames[1] = cf_name;
- merge_status = cf_merge_files(tmpname, out_fd, 2, in_filenames,
- filetype, FALSE);
+ merge_status = cf_merge_files(&tmpname, 2, in_filenames, filetype, FALSE);
} else {
rb = OBJECT_GET_DATA(w, E_MERGE_PREPEND_KEY);
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (rb))) {
/* prepend file */
in_filenames[0] = cfile.filename;
in_filenames[1] = cf_name;
- merge_status = cf_merge_files(tmpname, out_fd, 2, in_filenames,
- filetype, TRUE);
+ merge_status = cf_merge_files(&tmpname, 2, in_filenames, filetype,
+ TRUE);
} else {
/* append file */
in_filenames[0] = cf_name;
in_filenames[1] = cfile.filename;
- merge_status = cf_merge_files(tmpname, out_fd, 2, in_filenames,
- filetype, TRUE);
+ merge_status = cf_merge_files(&tmpname, 2, in_filenames, filetype,
+ TRUE);
}
}
@@ -1059,6 +1056,7 @@ file_merge_ok_cb(GtkWidget *w, gpointer fs) {
if (merge_status != CF_OK) {
if (rfcode != NULL)
dfilter_free(rfcode);
+ g_free(tmpname);
return;
}
@@ -1075,8 +1073,10 @@ file_merge_ok_cb(GtkWidget *w, gpointer fs) {
try again. */
if (rfcode != NULL)
dfilter_free(rfcode);
+ g_free(tmpname);
return;
}
+ g_free(tmpname);
/* Attach the new read filter to "cf" ("cf_open()" succeeded, so
it closed the previous capture file, and thus destroyed any