Add an "open_failure_alert_box()" routine to pop up an alert box for a

failed attempt to open/create a file.

Fix one call to pass the right value for the "for_writing" flag.

svn path=/trunk/; revision=10026
This commit is contained in:
Guy Harris 2004-02-11 01:23:25 +00:00
parent c7fd1b2b13
commit 727b913bbd
9 changed files with 58 additions and 38 deletions

View File

@ -2,7 +2,7 @@
* Routines to put up various "standard" alert boxes used in multiple * Routines to put up various "standard" alert boxes used in multiple
* places * places
* *
* $Id: alert_box.c,v 1.1 2004/02/11 00:55:26 guy Exp $ * $Id: alert_box.c,v 1.2 2004/02/11 01:23:23 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com> * By Gerald Combs <gerald@ethereal.com>
@ -29,12 +29,32 @@
#include <glib.h> #include <glib.h>
#include <epan/filesystem.h>
#include <epan/dfilter/dfilter.h> #include <epan/dfilter/dfilter.h>
#include "alert_box.h" #include "alert_box.h"
#include "simple_dialog.h" #include "simple_dialog.h"
/*
* Alert box for a failed attempt to open or create a file.
* "err" is assumed to be a UNIX-style errno; "for_writing" is TRUE if
* the file is being opened for writing and FALSE if it's being opened
* for reading.
*
* XXX - add explanatory secondary text for at least some of the errors;
* various HIGs suggest that you should, for example, suggest that the
* user remove files if the file system is full. Perhaps that's because
* they're providing guidelines for people less sophisticated than the
* typical Ethereal user is, but....
*/
void
open_failure_alert_box(const char *filename, int err, gboolean for_writing)
{
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
file_open_error_message(err, for_writing), filename);
}
/* /*
* Alert box for an invalid display filter expression. * Alert box for an invalid display filter expression.
* Assumes "dfilter_error_msg" has been set by "dfilter_compile()" to the * Assumes "dfilter_error_msg" has been set by "dfilter_compile()" to the

View File

@ -2,7 +2,7 @@
* Routines to put up various "standard" alert boxes used in multiple * Routines to put up various "standard" alert boxes used in multiple
* places * places
* *
* $Id: alert_box.h,v 1.1 2004/02/11 00:55:27 guy Exp $ * $Id: alert_box.h,v 1.2 2004/02/11 01:23:23 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com> * By Gerald Combs <gerald@ethereal.com>
@ -30,6 +30,15 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
/*
* Alert box for a failed attempt to open or create a file.
* "err" is assumed to be a UNIX-style errno; "for_writing" is TRUE if
* the file is being opened for writing and FALSE if it's being opened
* for reading.
*/
extern void open_failure_alert_box(const char *filename, int err,
gboolean for_writing);
/* /*
* Alert box for an invalid display filter expression. * Alert box for an invalid display filter expression.
* Assumes "dfilter_error_msg" has been set by "dfilter_compile()" to the * Assumes "dfilter_error_msg" has been set by "dfilter_compile()" to the

View File

@ -1,7 +1,7 @@
/* capture.c /* capture.c
* Routines for packet capture windows * Routines for packet capture windows
* *
* $Id: capture.c,v 1.237 2004/02/09 19:19:19 ulfl Exp $ * $Id: capture.c,v 1.238 2004/02/11 01:23:23 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com> * By Gerald Combs <gerald@ethereal.com>
@ -130,11 +130,11 @@
#include <epan/packet.h> #include <epan/packet.h>
#include <epan/dfilter/dfilter.h> #include <epan/dfilter/dfilter.h>
#include <epan/filesystem.h>
#include "file.h" #include "file.h"
#include "capture.h" #include "capture.h"
#include "util.h" #include "util.h"
#include "pcap-util.h" #include "pcap-util.h"
#include "alert_box.h"
#include "simple_dialog.h" #include "simple_dialog.h"
#include "prefs.h" #include "prefs.h"
#include "globals.h" #include "globals.h"
@ -322,8 +322,7 @@ do_capture(const char *save_file)
if (capture_opts.ringbuffer_on) { if (capture_opts.ringbuffer_on) {
ringbuf_error_cleanup(); ringbuf_error_cleanup();
} }
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, open_failure_alert_box(capfile_name, errno, TRUE);
file_open_error_message(errno, TRUE), capfile_name);
} }
g_free(capfile_name); g_free(capfile_name);
return FALSE; return FALSE;

11
file.c
View File

@ -1,7 +1,7 @@
/* file.c /* file.c
* File I/O routines * File I/O routines
* *
* $Id: file.c,v 1.358 2004/02/11 00:55:27 guy Exp $ * $Id: file.c,v 1.359 2004/02/11 01:23:24 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com> * By Gerald Combs <gerald@ethereal.com>
@ -70,6 +70,7 @@
#include "file.h" #include "file.h"
#include "menu.h" #include "menu.h"
#include "util.h" #include "util.h"
#include "alert_box.h"
#include "simple_dialog.h" #include "simple_dialog.h"
#include "progress_dlg.h" #include "progress_dlg.h"
#include "ui_util.h" #include "ui_util.h"
@ -2979,9 +2980,7 @@ copy_binary_file(char *from_filename, char *to_filename)
/* Copy the raw bytes of the file. */ /* Copy the raw bytes of the file. */
from_fd = open(from_filename, O_RDONLY | O_BINARY); from_fd = open(from_filename, O_RDONLY | O_BINARY);
if (from_fd < 0) { if (from_fd < 0) {
err = errno; open_failure_alert_box(from_filename, errno, FALSE);
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
file_open_error_message(err, TRUE), from_filename);
goto done; goto done;
} }
@ -2992,9 +2991,7 @@ copy_binary_file(char *from_filename, char *to_filename)
to be open in binary mode. */ to be open in binary mode. */
to_fd = open(to_filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644); to_fd = open(to_filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
if (to_fd < 0) { if (to_fd < 0) {
err = errno; open_failure_alert_box(to_filename, errno, TRUE);
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
file_open_error_message(err, TRUE), to_filename);
close(from_fd); close(from_fd);
goto done; goto done;
} }

View File

@ -1,6 +1,6 @@
/* follow_dlg.c /* follow_dlg.c
* *
* $Id: follow_dlg.c,v 1.43 2004/02/06 19:19:10 ulfl Exp $ * $Id: follow_dlg.c,v 1.44 2004/02/11 01:23:24 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com> * By Gerald Combs <gerald@ethereal.com>
@ -54,6 +54,7 @@
#include "globals.h" #include "globals.h"
#include "gtkglobals.h" #include "gtkglobals.h"
#include "main.h" #include "main.h"
#include "alert_box.h"
#include "simple_dialog.h" #include "simple_dialog.h"
#include "packet-ipv6.h" #include "packet-ipv6.h"
#include "prefs.h" #include "prefs.h"
@ -765,10 +766,9 @@ follow_print_stream(GtkWidget * w _U_, gpointer data)
fh = open_print_dest(to_file, print_dest); fh = open_print_dest(to_file, print_dest);
if (fh == NULL) { if (fh == NULL) {
if (to_file) { if (to_file)
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, open_failure_alert_box(prefs.pr_file, errno, TRUE);
file_open_error_message(errno, TRUE), prefs.pr_file); else {
} else {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"Couldn't run print command %s.", prefs.pr_cmd); "Couldn't run print command %s.", prefs.pr_cmd);
} }
@ -977,8 +977,7 @@ follow_save_as_ok_cb(GtkWidget * w _U_, GtkFileSelection * fs)
fh = fopen(to_name, "wb"); fh = fopen(to_name, "wb");
if (fh == NULL) { if (fh == NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, open_failure_alert_box(to_name, errno, TRUE);
file_open_error_message(errno, TRUE), to_name);
g_free(to_name); g_free(to_name);
return; return;
} }

View File

@ -1,7 +1,7 @@
/* print_dlg.c /* print_dlg.c
* Dialog boxes for printing * Dialog boxes for printing
* *
* $Id: print_dlg.c,v 1.60 2004/01/31 20:31:20 ulfl Exp $ * $Id: print_dlg.c,v 1.61 2004/02/11 01:23:24 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com> * By Gerald Combs <gerald@ethereal.com>
@ -34,6 +34,7 @@
#include "keys.h" #include "keys.h"
#include "print.h" #include "print.h"
#include "prefs.h" #include "prefs.h"
#include "alert_box.h"
#include "simple_dialog.h" #include "simple_dialog.h"
#include "file_dlg.h" #include "file_dlg.h"
#include "ui_util.h" #include "ui_util.h"
@ -846,8 +847,7 @@ print_ok_cb(GtkWidget *ok_bt, gpointer parent_w)
case PP_OPEN_ERROR: case PP_OPEN_ERROR:
if (print_args.to_file) if (print_args.to_file)
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, open_failure_alert_box(print_args.dest, errno, TRUE);
file_open_error_message(errno, TRUE), print_args.dest);
else else
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Couldn't run print command %s.", simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Couldn't run print command %s.",
print_args.dest); print_args.dest);

View File

@ -1,7 +1,7 @@
/* proto_draw.c /* proto_draw.c
* Routines for GTK+ packet display * Routines for GTK+ packet display
* *
* $Id: proto_draw.c,v 1.86 2004/02/06 19:19:10 ulfl Exp $ * $Id: proto_draw.c,v 1.87 2004/02/11 01:23:24 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com> * By Gerald Combs <gerald@ethereal.com>
@ -62,6 +62,7 @@
#include "gtkglobals.h" #include "gtkglobals.h"
#include "compat_macros.h" #include "compat_macros.h"
#include <epan/filesystem.h> #include <epan/filesystem.h>
#include "alert_box.h"
#include "simple_dialog.h" #include "simple_dialog.h"
#define BYTE_VIEW_WIDTH 16 #define BYTE_VIEW_WIDTH 16
@ -918,8 +919,7 @@ savehex_save_clicked_cb(GtkWidget * w _U_, gpointer data _U_)
fd = open(file, O_WRONLY|O_CREAT|O_TRUNC, 0666); fd = open(file, O_WRONLY|O_CREAT|O_TRUNC, 0666);
if (fd == -1) { if (fd == -1) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, open_failure_alert_box(file, errno, TRUE);
file_open_error_message(errno, TRUE), file);
return; return;
} }
if (write(fd, data_p + start, end - start) < 0) { if (write(fd, data_p + start, end - start) < 0) {

View File

@ -1,7 +1,7 @@
/* rtp_analysis.c /* rtp_analysis.c
* RTP analysis addition for ethereal * RTP analysis addition for ethereal
* *
* $Id: rtp_analysis.c,v 1.32 2004/02/06 19:19:10 ulfl Exp $ * $Id: rtp_analysis.c,v 1.33 2004/02/11 01:23:25 guy Exp $
* *
* Copyright 2003, Alcatel Business Systems * Copyright 2003, Alcatel Business Systems
* By Lars Ruoff <lars.ruoff@gmx.net> * By Lars Ruoff <lars.ruoff@gmx.net>
@ -60,6 +60,7 @@
/* in /gtk ... */ /* in /gtk ... */
#include "dlg_utils.h" #include "dlg_utils.h"
#include "ui_util.h" #include "ui_util.h"
#include "alert_box.h"
#include "simple_dialog.h" #include "simple_dialog.h"
#include "menu.h" #include "menu.h"
#include "main.h" #include "main.h"
@ -986,8 +987,7 @@ static void save_csv_as_ok_cb(GtkWidget *bt _U_, gpointer fs /*user_data_t *user
if (GTK_TOGGLE_BUTTON(forw)->active || GTK_TOGGLE_BUTTON(both)->active) { if (GTK_TOGGLE_BUTTON(forw)->active || GTK_TOGGLE_BUTTON(both)->active) {
fp = fopen(g_dest, "w"); fp = fopen(g_dest, "w");
if (fp == NULL) { if (fp == NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, open_failure_alert_box(g_dest, errno, TRUE);
file_open_error_message(errno, TRUE), g_dest);
return; return;
} }
@ -1045,9 +1045,7 @@ static void save_csv_as_ok_cb(GtkWidget *bt _U_, gpointer fs /*user_data_t *user
if (GTK_TOGGLE_BUTTON(both)->active) { if (GTK_TOGGLE_BUTTON(both)->active) {
fp = fopen(g_dest, "a"); fp = fopen(g_dest, "a");
if (fp == NULL) { if (fp == NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, open_failure_alert_box(g_dest, errno, TRUE);
file_open_error_message(errno, TRUE),
g_dest);
return; return;
} }
fprintf(fp, "\nReverse\n"); fprintf(fp, "\nReverse\n");
@ -1060,9 +1058,7 @@ static void save_csv_as_ok_cb(GtkWidget *bt _U_, gpointer fs /*user_data_t *user
} else { } else {
fp = fopen(g_dest, "w"); fp = fopen(g_dest, "w");
if (fp == NULL) { if (fp == NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, open_failure_alert_box(g_dest, errno, TRUE);
file_open_error_message(errno, TRUE),
g_dest);
return; return;
} }
} }

View File

@ -1,7 +1,7 @@
/* rtp_stream.c /* rtp_stream.c
* RTP streams summary addition for ethereal * RTP streams summary addition for ethereal
* *
* $Id: rtp_stream.c,v 1.11 2004/01/31 09:48:26 guy Exp $ * $Id: rtp_stream.c,v 1.12 2004/02/11 01:23:25 guy Exp $
* *
* Copyright 2003, Alcatel Business Systems * Copyright 2003, Alcatel Business Systems
* By Lars Ruoff <lars.ruoff@gmx.net> * By Lars Ruoff <lars.ruoff@gmx.net>
@ -40,6 +40,7 @@
#include <epan/filesystem.h> #include <epan/filesystem.h>
#include "alert_box.h"
#include "simple_dialog.h" #include "simple_dialog.h"
#ifdef HAVE_SYS_TYPES_H #ifdef HAVE_SYS_TYPES_H
@ -285,8 +286,7 @@ gboolean rtpstream_save(rtp_stream_info_t* stream, const gchar *filename)
/* open file for saving */ /* open file for saving */
the_tapinfo_struct.save_file = fopen(filename, "wb"); the_tapinfo_struct.save_file = fopen(filename, "wb");
if (the_tapinfo_struct.save_file==NULL) { if (the_tapinfo_struct.save_file==NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, open_failure_alert_box(filename, errno, TRUE);
file_open_error_message(errno, TRUE), filename);
return FALSE; return FALSE;
} }