aboutsummaryrefslogtreecommitdiffstats
path: root/epan/filesystem.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2004-01-24 01:44:29 +0000
committerGuy Harris <guy@alum.mit.edu>2004-01-24 01:44:29 +0000
commit46848f0a9ef2b8ceefdf75d8c75339778cd70e8c (patch)
treed4316f905060985bfa20d83b9b46102334975bb6 /epan/filesystem.c
parent49093048ac524c7eb2124c15a8db11d21c7fbab4 (diff)
Add a new "file_open_error_message()" routine in "epan/filesystem.c", to
translate UNIX errno values to a somewhat friendly message format string. Rename "file_open_error_message()" in "file.c" to "cf_open_error_message()", make "cf_open_error_message()" use the new "file_open_error_message()" for UNIX errno values, have "do_capture()" in "capture.c" use "file_open_error_message()" to report errors from "open()", and make "cf_open_error_message()" static as nothing outside "file.c" uses it. Do similar stuff in "tethereal.c". svn path=/trunk/; revision=9821
Diffstat (limited to 'epan/filesystem.c')
-rw-r--r--epan/filesystem.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/epan/filesystem.c b/epan/filesystem.c
index c6d7c2b606..2debf626a4 100644
--- a/epan/filesystem.c
+++ b/epan/filesystem.c
@@ -1,7 +1,7 @@
/* filesystem.c
* Filesystem utility routines
*
- * $Id: filesystem.c,v 1.27 2003/11/03 22:32:36 guy Exp $
+ * $Id: filesystem.c,v 1.28 2004/01/24 01:44:29 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -643,3 +643,42 @@ char *get_tempfile_path(const char *filename)
return path;
}
+/*
+ * Return an error message for UNIX-style errno indications.
+ */
+char *
+file_open_error_message(int err, gboolean for_writing)
+{
+ char *errmsg;
+ static char errmsg_errno[1024+1];
+
+ switch (err) {
+
+ case ENOENT:
+ if (for_writing)
+ errmsg = "The path to the file \"%s\" does not exist.";
+ else
+ errmsg = "The file \"%s\" does not exist.";
+ break;
+
+ case EACCES:
+ if (for_writing)
+ errmsg = "You do not have permission to create or write to the file \"%s\".";
+ else
+ errmsg = "You do not have permission to read the file \"%s\".";
+ break;
+
+ case EISDIR:
+ errmsg = "\"%s\" is a directory (folder), not a file.";
+ break;
+
+ default:
+ snprintf(errmsg_errno, sizeof(errmsg_errno),
+ "The file \"%%s\" could not be %s: %s.",
+ for_writing ? "created" : "opened",
+ strerror(err));
+ errmsg = errmsg_errno;
+ break;
+ }
+ return errmsg;
+}