diff options
Diffstat (limited to 'src/user/knob/file.c')
-rw-r--r-- | src/user/knob/file.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/user/knob/file.c b/src/user/knob/file.c index 8ab7acd..0032cf2 100644 --- a/src/user/knob/file.c +++ b/src/user/knob/file.c @@ -9,9 +9,9 @@ struct file { uint32_t length; }; -static const char *try_remove_prefix(const char *path, uint8_t *dn_out) { +const char *remove_prefix(const char *path, uint8_t *dn_out) { if ((path[0] != 's') || (path[1] != 'd')) - return 0; + goto no_prefix; const char *num_part = path + 2; for (uint32_t i = 0; num_part[i]; ++i) @@ -19,22 +19,20 @@ static const char *try_remove_prefix(const char *path, uint8_t *dn_out) { uint32_t dn_large; if (!try_sntoi(num_part, i, &dn_large) || dn_large > 255) - return 0; + goto no_prefix; *dn_out = (uint8_t)dn_large; return num_part + i + 1; } - return 0; +no_prefix: + *dn_out = current_drive; + return path; } struct file *open_file(const char *path) { uint8_t dn; - const char *path_part = try_remove_prefix(path, &dn); - if (path_part) - path = path_part; - else - dn = current_drive; + path = remove_prefix(path, &dn); _file_handle_t h = _open_file(dn, path); if (!h) |