summaryrefslogtreecommitdiff
path: root/utils/filename.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils/filename.c')
-rw-r--r--utils/filename.c51
1 files changed, 35 insertions, 16 deletions
diff --git a/utils/filename.c b/utils/filename.c
index 9c95901a1..f0e1bb0f5 100644
--- a/utils/filename.c
+++ b/utils/filename.c
@@ -84,7 +84,8 @@ const char *filename_request(void)
/* no available slots - create a new directory */
dir = filename_create_directory(NULL);
if (dir == NULL) {
- LOG("Failed to create a new directory.");
+ NSLOG(netsurf, INFO,
+ "Failed to create a new directory.");
return NULL;
}
i = 63;
@@ -182,10 +183,12 @@ bool filename_initialise(void)
for (start = directory; *start != '\0'; start++) {
if (*start == '/') {
*start = '\0';
- LOG("Creating \"%s\"", directory);
+ NSLOG(netsurf, INFO, "Creating \"%s\"", directory);
ret = nsmkdir(directory, S_IRWXU);
if (ret != 0 && errno != EEXIST) {
- LOG("Failed to create directory \"%s\"", directory);
+ NSLOG(netsurf, INFO,
+ "Failed to create directory \"%s\"",
+ directory);
free(directory);
return false;
}
@@ -194,7 +197,7 @@ bool filename_initialise(void)
}
}
- LOG("Temporary directory location: %s", directory);
+ NSLOG(netsurf, INFO, "Temporary directory location: %s", directory);
ret = nsmkdir(directory, S_IRWXU);
free(directory);
@@ -269,18 +272,23 @@ bool filename_flush_directory(const char *folder, int depth)
parent = opendir(folder);
while ((entry = readdir(parent))) {
- struct stat statbuf;
+ int written;
+ struct stat statbuf;
/* Ignore '.' and '..' */
if (strcmp(entry->d_name, ".") == 0 ||
strcmp(entry->d_name, "..") == 0)
continue;
- snprintf(child, sizeof(child), "%s/%s", folder, entry->d_name);
- child[sizeof(child) - 1] = '\0';
+ written = snprintf(child, sizeof(child), "%s/%s",
+ folder, entry->d_name);
+ if (written == sizeof(child)) {
+ child[sizeof(child) - 1] = '\0';
+ }
if (stat(child, &statbuf) == -1) {
- LOG("Unable to stat %s: %s", child, strerror(errno));
+ NSLOG(netsurf, INFO, "Unable to stat %s: %s", child,
+ strerror(errno));
continue;
}
@@ -348,7 +356,8 @@ bool filename_flush_directory(const char *folder, int depth)
filename_delete_recursive(child);
if (remove(child))
- LOG("Failed to remove '%s'", child);
+ NSLOG(netsurf, INFO, "Failed to remove '%s'",
+ child);
else
changed = true;
} else {
@@ -378,16 +387,22 @@ bool filename_delete_recursive(char *folder)
parent = opendir(folder);
while ((entry = readdir(parent))) {
+ int written;
+
/* Ignore '.' and '..' */
if (strcmp(entry->d_name, ".") == 0 ||
strcmp(entry->d_name, "..") == 0)
continue;
- snprintf(child, sizeof(child), "%s/%s", folder, entry->d_name);
- child[sizeof(child) - 1] = '\0';
+ written = snprintf(child, sizeof(child), "%s/%s",
+ folder, entry->d_name);
+ if (written == sizeof(child)) {
+ child[sizeof(child) - 1] = '\0';
+ }
if (stat(child, &statbuf) == -1) {
- LOG("Unable to stat %s: %s", child, strerror(errno));
+ NSLOG(netsurf, INFO, "Unable to stat %s: %s", child,
+ strerror(errno));
continue;
}
@@ -399,7 +414,7 @@ bool filename_delete_recursive(char *folder)
}
if (remove(child)) {
- LOG("Failed to remove '%s'", child);
+ NSLOG(netsurf, INFO, "Failed to remove '%s'", child);
closedir(parent);
return false;
}
@@ -465,7 +480,7 @@ static struct directory *filename_create_directory(const char *prefix)
/* allocate a new directory */
new_dir = malloc(sizeof(struct directory));
if (new_dir == NULL) {
- LOG("No memory for malloc()");
+ NSLOG(netsurf, INFO, "No memory for malloc()");
return NULL;
}
@@ -499,7 +514,9 @@ static struct directory *filename_create_directory(const char *prefix)
* 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);
+ NSLOG(netsurf, INFO,
+ "Failed to create optimised structure '%s'",
+ filename_directory);
}
}
@@ -519,7 +536,9 @@ static struct directory *filename_create_directory(const char *prefix)
if (!is_dir(filename_directory)) {
if (nsmkdir(filename_directory, S_IRWXU)) {
- LOG("Failed to create directory '%s'", filename_directory);
+ NSLOG(netsurf, INFO,
+ "Failed to create directory '%s'",
+ filename_directory);
return NULL;
}
}