summaryrefslogtreecommitdiff
path: root/riscos/filename.c
diff options
context:
space:
mode:
Diffstat (limited to 'riscos/filename.c')
-rw-r--r--riscos/filename.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/riscos/filename.c b/riscos/filename.c
index 9355c4ffb..799ff3afd 100644
--- a/riscos/filename.c
+++ b/riscos/filename.c
@@ -86,9 +86,9 @@ bool ro_filename_claim(const char *filename) {
struct directory *dir;
/* extract the prefix */
- sprintf(dir_prefix, filename);
+ strcpy(dir_prefix, filename);
for (i = 0, last = dir_prefix; i < 3; i++)
- while (*last++ != '.');
+ while (*last && *last++ != '.');
i = atoi(last);
last[0] = '\0';
@@ -177,11 +177,9 @@ static struct directory *ro_filename_create_directory(const char *prefix) {
int result, index;
struct directory *old_dir, *new_dir, *prev_dir = NULL;
char dir_prefix[16];
-
+
/* get the lowest unique prefix, or use the provided one */
- if (prefix) {
- strcpy(dir_prefix, prefix);
- } else {
+ if (!prefix) {
sprintf(dir_prefix, "00.00.00.");
for (index = 1, old_dir = root; old_dir;
index++, old_dir = old_dir->next) {
@@ -192,8 +190,9 @@ static struct directory *ro_filename_create_directory(const char *prefix) {
((index >> 6) & 63),
((index >> 0) & 63));
}
+ prefix = dir_prefix;
}
-
+
/* allocate a new directory */
new_dir = (struct directory *)calloc(1,
sizeof(struct directory));
@@ -201,12 +200,13 @@ static struct directory *ro_filename_create_directory(const char *prefix) {
LOG(("No memory for calloc()"));
return NULL;
}
- strcpy(new_dir->prefix, dir_prefix);
+ strncpy(new_dir->prefix, prefix, 9);
+ new_dir->prefix[9] = '\0';
/* link into the tree, sorted by prefix. */
for (old_dir = root; old_dir; prev_dir = old_dir,
old_dir = old_dir->next) {
- result = strcmp(old_dir->prefix, dir_prefix);
+ result = strcmp(old_dir->prefix, prefix);
if (result == 0) {
free(new_dir);
return old_dir;
@@ -225,12 +225,15 @@ static struct directory *ro_filename_create_directory(const char *prefix) {
sprintf(ro_filename_directory, "%s.", CACHE_FILENAME_PREFIX);
last_1 = ro_filename_directory + strlen(CACHE_FILENAME_PREFIX) + 1;
last_2 = new_dir->prefix;
- for (int i = 0; i < 3; i++) {
+ for (int i = 0; i < 3 && *last_2; i++) {
*last_1++ = *last_2++;
- while (*last_2 != '.')
+ while (*last_2 && *last_2 != '.')
*last_1++ = *last_2++;
- last_1[0] = '\0';
- xosfile_create_dir(ro_filename_directory, 0);
+ if (*last_2) {
+ last_1[0] = '\0';
+ xosfile_create_dir(ro_filename_directory, 0);
+ }
}
+
return new_dir;
}