From e5f9a7dca8513f75acfabdff1412c6f4bab231e6 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Sat, 14 Dec 2019 14:38:25 -0800 Subject: [PATCH] SCP: Cleanup path argument to MKDIR command Also allow making a directory that already exists to return successfully with a message. The message can be suppressed with the -Q switch. --- scp.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scp.c b/scp.c index 2b073e3b..c8649f29 100644 --- a/scp.c +++ b/scp.c @@ -6612,6 +6612,12 @@ if ((!cptr) || (*cptr == '\0')) strlcpy (path, cptr, sizeof (path)); while ((c = strchr (path, '\\'))) *c = '/'; +if (path[strlen (path) - 1] == '/') /* trim any trailing / from the path */ + path[strlen (path) - 1] = '\0'; +while ((c = strstr (path, "//"))) + memmove (c, c + 1, strlen (c + 1) + 1); /* clean out any empty directories // */ +if ((!stat (path, &filestat)) && (filestat.st_mode & S_IFDIR)) + return sim_messagef (SCPE_OK, "directory %s already exists\n", path); c = path; while ((c = strchr (c, '/'))) { *c = '\0';