diff options
Diffstat (limited to 'fish')
-rw-r--r-- | fish/fish.c | 48 | ||||
-rw-r--r-- | fish/fish.h | 1 |
2 files changed, 49 insertions, 0 deletions
diff --git a/fish/fish.c b/fish/fish.c index 3300536d..f6996032 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -1295,3 +1295,51 @@ xwrite (int fd, const void *v_buf, size_t len) return 0; } + +/* Resolve the special "win:..." form for Windows-specific paths. + * This always returns a newly allocated string which is freed by the + * caller function in "cmds.c". + */ +char * +resolve_win_path (const char *path) +{ + char *ret; + size_t i; + + if (strncasecmp (path, "win:", 4) != 0) { + ret = strdup (path); + if (ret == NULL) + perror ("strdup"); + return ret; + } + + path += 4; + + /* Drop drive letter, if it's "C:". */ + if (strncasecmp (path, "c:", 2) == 0) + path += 2; + + if (!*path) { + ret = strdup ("/"); + if (ret == NULL) + perror ("strdup"); + return ret; + } + + ret = strdup (path); + if (ret == NULL) { + perror ("strdup"); + return NULL; + } + + /* Blindly convert any backslashes into forward slashes. Is this good? */ + for (i = 0; i < strlen (ret); ++i) + if (ret[i] == '\\') + ret[i] = '/'; + + char *t = guestfs_case_sensitive_path (g, ret); + free (ret); + ret = t; + + return ret; +} diff --git a/fish/fish.h b/fish/fish.h index 642c269a..8c5dba16 100644 --- a/fish/fish.h +++ b/fish/fish.h @@ -46,6 +46,7 @@ extern int launch (guestfs_h *); extern int is_true (const char *str); extern char **parse_string_list (const char *str); extern int xwrite (int fd, const void *buf, size_t len); +extern char *resolve_win_path (const char *path); /* in cmds.c (auto-generated) */ extern void list_commands (void); |