aboutsummaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorGilbert Ramirez <gram@alumni.rice.edu>1999-04-06 16:24:50 +0000
committerGilbert Ramirez <gram@alumni.rice.edu>1999-04-06 16:24:50 +0000
commit2870ce29ce6b02be8a1e3044e98800d3db45d82c (patch)
treeb0a74c3c123e11753fcf51bd369444a4b42e9c62 /util.c
parentbad78f629a420ede7fa0ad7929efb343354fb037 (diff)
Capturing packets from ethereal now saves the capture in an "anonymous" buffer. That is, it's
a random name chosen by tempnam(), unknown to the user. If the user decides to save that trace, he then uses File | Save to save it to a file. File | Save As lets him make a copy of his named trace file as well. I also updated my e-mail address in the various credit locations. svn path=/trunk/; revision=242
Diffstat (limited to 'util.c')
-rw-r--r--util.c79
1 files changed, 78 insertions, 1 deletions
diff --git a/util.c b/util.c
index e3b551d244..4c8277db3c 100644
--- a/util.c
+++ b/util.c
@@ -1,7 +1,7 @@
/* util.c
* Utility routines
*
- * $Id: util.c,v 1.13 1999/04/05 22:51:44 guy Exp $
+ * $Id: util.c,v 1.14 1999/04/06 16:24:49 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -34,6 +34,14 @@
#include <stdarg.h>
#include <stdio.h>
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
#ifdef NEED_SNPRINTF_H
# ifdef HAVE_STDARG_H
# include <stdarg.h>
@@ -166,3 +174,72 @@ simple_dialog_cancel_cb(GtkWidget *w, gpointer win) {
*btn_mask = ESD_BTN_CANCEL;
gtk_widget_destroy(GTK_WIDGET(win));
}
+
+/* Tries to mv a file. If unsuccessful, tries to cp the file.
+ * Returns 0 on failure to do either, 1 on success of either
+ */
+int
+file_mv(char *from, char *to)
+{
+
+#define COPY_BUFFER_SIZE 8192
+
+ int retval;
+
+ /* try a hard link */
+ retval = link(from, to);
+
+ /* or try a copy */
+ if (retval < 0) {
+ retval = file_cp(from, to);
+ if (!retval) {
+ return 0;
+ }
+ }
+
+ unlink(from);
+ return 1;
+}
+
+/* Copies a file.
+ * Returns 0 on failure to do either, 1 on success of either
+ */
+int
+file_cp(char *from, char *to)
+{
+
+#define COPY_BUFFER_SIZE 8192
+
+ int from_fd, to_fd, nread;
+ char *buffer;
+ gint dialogue_button = ESD_BTN_OK;
+
+ buffer = g_malloc(COPY_BUFFER_SIZE);
+
+ from_fd = open(from, O_RDONLY);
+ if (from_fd < 0) {
+ simple_dialog(ESD_TYPE_WARN, &dialogue_button,
+ "Cannot open from-file for copying.");
+ return 0;
+ }
+
+ to_fd = creat(to, 0644);
+ if (to_fd < 0) {
+ simple_dialog(ESD_TYPE_WARN, &dialogue_button,
+ "Cannot open to-file for copying.");
+ close(from_fd);
+ return 0;
+ }
+
+ while( (nread = read(from_fd, buffer, COPY_BUFFER_SIZE)) > 0) {
+ if (write(to_fd, buffer, nread) < nread) {
+ close(from_fd);
+ close(to_fd);
+ return 0;
+ }
+ }
+ close(from_fd);
+ close(to_fd);
+
+ return 1;
+}