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
This commit is contained in:
John Mark Bell 2006-06-20 22:58:36 +00:00
parent 5adef63ac5
commit 9eb3efff78
4 changed files with 50 additions and 34 deletions

View File

@ -252,7 +252,7 @@ void bitmap_overlay_sprite(struct bitmap *bitmap, const osspriteop_header *s)
assert(sprite_bpp(s) == 8);
if ((unsigned)s->mode & 0x80000000U)
alpha = true;
alpha = true;
error = xosspriteop_read_sprite_info(osspriteop_PTR,
(osspriteop_area *)0x100,
@ -376,7 +376,7 @@ bool bitmap_initialise(struct bitmap *bitmap)
void bitmap_set_opaque(struct bitmap *bitmap, bool opaque)
{
assert(bitmap);
if (opaque)
bitmap->state |= BITMAP_OPAQUE;
else
@ -459,7 +459,7 @@ char *bitmap_get_buffer(struct bitmap *bitmap)
bitmap->previous = NULL;
bitmap_head = bitmap;
}
/* dynamically create the buffer */
if (!(bitmap->state & BITMAP_READY)) {
if (!bitmap_initialise(bitmap))
@ -592,8 +592,8 @@ void bitmap_set_suspendable(struct bitmap *bitmap, void *private_word,
void (*invalidate)(struct bitmap *bitmap, void *private_word)) {
bitmap->private_word = private_word;
bitmap->invalidate = invalidate;
bitmap_suspendable++;
}
bitmap_suspendable++;
}
/**
@ -644,7 +644,7 @@ void bitmap_maintain(void)
bitmap_maintenance_priority = false;
return;
}
/* the fastest and easiest way to release memory is by suspending
* images. as such, we try to do this first for as many images as
* possible, potentially freeing up large amounts of memory */
@ -659,7 +659,7 @@ void bitmap_maintain(void)
bitmap_direct_used -= 16 + 44 +
bitmap->width * bitmap->height * 4;
bitmap_suspended++;
}
}
}
return;
}
@ -892,7 +892,7 @@ void bitmap_save_file(struct bitmap *bitmap)
os_error *error;
struct bitmap_compressed_header *header;
assert(bitmap->compressed || bitmap->sprite_area);
assert(bitmap && (bitmap->compressed || bitmap->sprite_area));
/* unmodified bitmaps will still have their file available */
if ((!(bitmap->state & BITMAP_MODIFIED)) && bitmap->filename[0]) {
@ -907,6 +907,11 @@ void bitmap_save_file(struct bitmap *bitmap)
/* dump the data (compressed or otherwise) to disk */
filename = filename_request();
if (!filename) {
LOG(("filename_request failed"));
return;
}
strcpy(bitmap->filename, filename);
sprintf(bitmap_unixname, "%s/%s", TEMP_FILENAME_PREFIX,
bitmap->filename);

View File

@ -2164,20 +2164,22 @@ void ro_gui_view_source(struct content *content)
message.file_name[211] = '\0';
free(temp_name);
} else {
/* We cannot release the requested filename until after it has finished
being used. As we can't easily find out when this is, we simply don't
bother releasing it and simply allow it to be re-used next time NetSurf
is started. The memory overhead from doing this is under 1 byte per
filename. */
temp_name = filename_request();
if (!temp_name) {
/* We cannot release the requested filename until after it
* has finished being used. As we can't easily find out when
* this is, we simply don't bother releasing it and simply
* allow it to be re-used next time NetSurf is started. The
* memory overhead from doing this is under 1 byte per
* filename. */
const char *filename = filename_request();
if (!filename) {
warn_user("NoMemory", 0);
return;
}
snprintf(full_name, 256, "%s/%s", TEMP_FILENAME_PREFIX, temp_name);
snprintf(full_name, 256, "%s/%s", TEMP_FILENAME_PREFIX,
filename);
full_name[255] = '\0';
r = __riscosify(full_name, 0, __RISCOSIFY_NO_SUFFIX, message.file_name,
212, 0);
r = __riscosify(full_name, 0, __RISCOSIFY_NO_SUFFIX,
message.file_name, 212, 0);
if (r == 0) {
LOG(("__riscosify failed"));
return;
@ -2205,7 +2207,8 @@ void ro_gui_view_source(struct content *content)
message.pos.y = 0;
message.est_size = 0;
message.file_type = 0xfff;
ro_message_send_message(wimp_USER_MESSAGE_RECORDED, (wimp_message*)&message, 0,
ro_message_send_message(wimp_USER_MESSAGE_RECORDED,
(wimp_message*)&message, 0,
ro_gui_view_source_bounce);
}

View File

@ -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;
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));
/* 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;
}

View File

@ -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);