summaryrefslogtreecommitdiff
path: root/wsutil/filesystem.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2016-01-06 19:01:39 -0800
committerGuy Harris <guy@alum.mit.edu>2016-01-07 03:02:08 +0000
commit97378a5bad8c20f4364b7fe86d96d9d14a192d48 (patch)
treeb6fc5354775654b012b4a09731c32cac439fbc3e /wsutil/filesystem.c
parent613b406023dc3d53e05bd9862ab5d4415806fa91 (diff)
downloadwireshark-97378a5bad8c20f4364b7fe86d96d9d14a192d48.tar.gz
Don't assume a stat() fails only if the target file doesn't exist.
If the error is something other than ENOENT, return that error indication. Change-Id: If866cab5f0de0e4fa8b1ed1cead1290feb88a3cb Reviewed-on: https://code.wireshark.org/review/13091 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'wsutil/filesystem.c')
-rw-r--r--wsutil/filesystem.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/wsutil/filesystem.c b/wsutil/filesystem.c
index e8bdea325a..ec1a0b4c3b 100644
--- a/wsutil/filesystem.c
+++ b/wsutil/filesystem.c
@@ -1523,6 +1523,7 @@ create_persconffile_profile(const char *profilename, char **pf_dir_path_return)
#endif
ws_statb64 s_buf;
int ret;
+ int save_errno;
if (profilename) {
/*
@@ -1537,7 +1538,18 @@ create_persconffile_profile(const char *profilename, char **pf_dir_path_return)
* If not then create it.
*/
pf_dir_path = get_profiles_dir ();
- if (ws_stat64(pf_dir_path, &s_buf) != 0 && errno == ENOENT) {
+ if (ws_stat64(pf_dir_path, &s_buf) != 0) {
+ if (errno != ENOENT) {
+ /* Some other problem; give up now. */
+ save_errno = errno;
+ *pf_dir_path_return = g_strdup(pf_dir_path);
+ errno = save_errno;
+ return -1;
+ }
+
+ /*
+ * It doesn't exist; try to create it.
+ */
ret = ws_mkdir(pf_dir_path, 0755);
if (ret == -1) {
*pf_dir_path_return = g_strdup(pf_dir_path);
@@ -1547,7 +1559,14 @@ create_persconffile_profile(const char *profilename, char **pf_dir_path_return)
}
pf_dir_path = get_persconffile_dir(profilename);
- if (ws_stat64(pf_dir_path, &s_buf) != 0 && errno == ENOENT) {
+ if (ws_stat64(pf_dir_path, &s_buf) != 0) {
+ if (errno != ENOENT) {
+ /* Some other problem; give up now. */
+ save_errno = errno;
+ *pf_dir_path_return = g_strdup(pf_dir_path);
+ errno = save_errno;
+ return -1;
+ }
#ifdef _WIN32
/*
* Does the parent directory of that directory
@@ -1567,6 +1586,16 @@ create_persconffile_profile(const char *profilename, char **pf_dir_path_return)
&& pf_dir_parent_path[pf_dir_parent_path_len - 1] != ':'
&& ws_stat64(pf_dir_parent_path, &s_buf) != 0) {
/*
+ * Not a drive letter and the stat() failed.
+ */
+ if (errno != ENOENT) {
+ /* Some other problem; give up now. */
+ save_errno = errno;
+ *pf_dir_path_return = g_strdup(pf_dir_path);
+ errno = save_errno;
+ return -1;
+ }
+ /*
* No, it doesn't exist - make it first.
*/
ret = ws_mkdir(pf_dir_parent_path, 0755);