diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2006-06-20 22:58:36 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2006-06-20 22:58:36 +0000 |
commit | 9eb3efff78d311a386ce783224d5e7bd6b88a5b1 (patch) | |
tree | 2edee3c54b46b7e2c0efa5a53761e8d6de27a9a2 /utils | |
parent | 5adef63ac5099ff12c8fed4872f8df4331072d7e (diff) | |
download | netsurf-9eb3efff78d311a386ce783224d5e7bd6b88a5b1.tar.gz netsurf-9eb3efff78d311a386ce783224d5e7bd6b88a5b1.tar.bz2 |
Make filename_create_directory check if directory already exists
Constify return of filename_request
Make bitmap save code check for filename_request failure
Update ro_gui_view_source to take account of constification
svn path=/trunk/netsurf/; revision=2639
Diffstat (limited to 'utils')
-rw-r--r-- | utils/filename.c | 38 | ||||
-rw-r--r-- | utils/filename.h | 2 |
2 files changed, 24 insertions, 16 deletions
diff --git a/utils/filename.c b/utils/filename.c index 32fbad793..82a0c9965 100644 --- a/utils/filename.c +++ b/utils/filename.c @@ -19,6 +19,7 @@ #include <sys/stat.h> #include "netsurf/utils/filename.h" #include "netsurf/utils/log.h" +#include "netsurf/utils/utils.h" #define FULL_WORD (unsigned int)4294967295 /* '0' + '0' * 10 */ @@ -44,9 +45,9 @@ static bool filename_delete_recursive(char *folder); /** * Request a new, unique, filename. * - * \return a pointer to a shared buffer containing the new filename + * \return a pointer to a shared buffer containing the new filename or NULL on failure */ -char *filename_request(void) { +const char *filename_request(void) { struct directory *dir; int i = -1; @@ -321,7 +322,8 @@ bool filename_delete_recursive(char *folder) { * Creates a new directory. * * \param prefix the prefix to use, or NULL to allocate a new one - * \return a new directory structure, or NULL on memory exhaustion + * \return a new directory structure, or NULL on memory exhaustion or + * creation failure * * Empty directories are never deleted, except by an explicit call to * filename_flush(). @@ -384,14 +386,17 @@ static struct directory *filename_create_directory(const char *prefix) { TEMP_FILENAME_PREFIX, new_dir->prefix); new_dir->prefix[8] = '/'; - if (!mkdir(filename_directory, S_IRWXU)) - return new_dir; - - /* the user has probably deleted the parent directory whilst - * we are running if there is an error, so we don't report - * this yet and try to create the structure normally. */ - LOG(("Failed to create optimised structure '%s'", - filename_directory)); + if (!is_dir(filename_directory)) { + if (!mkdir(filename_directory, S_IRWXU)) + return new_dir; + + /* the user has probably deleted the parent directory + * whilst we are running if there is an error, so we + * don't report this yet and try to create the + * structure normally. */ + LOG(("Failed to create optimised structure '%s'", + filename_directory)); + } } /* create the directory structure */ @@ -405,12 +410,15 @@ static struct directory *filename_create_directory(const char *prefix) { *last_1++ = *last_2++; if (*last_2) { last_1[0] = '\0'; - if (mkdir(filename_directory, S_IRWXU)) { - LOG(("Failed to create directory '%s'", - filename_directory)); - return NULL; + if (!is_dir(filename_directory)) { + if (mkdir(filename_directory, S_IRWXU)) { + LOG(("Failed to create directory '%s'", + filename_directory)); + return NULL; + } } } } + return new_dir; } diff --git a/utils/filename.h b/utils/filename.h index ef5b7090a..dab072b08 100644 --- a/utils/filename.h +++ b/utils/filename.h @@ -16,7 +16,7 @@ #define TEMP_FILENAME_PREFIX "/tmp/WWW/NetSurf/Cache" #endif -char *filename_request(void); +const char *filename_request(void); bool filename_claim(const char *filename); void filename_release(const char *filename); bool filename_initialise(void); |