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.
This commit is contained in:
Mark Pizzolato 2019-12-14 14:38:25 -08:00
parent 26128800ee
commit e5f9a7dca8

6
scp.c
View file

@ -6612,6 +6612,12 @@ if ((!cptr) || (*cptr == '\0'))
strlcpy (path, cptr, sizeof (path)); strlcpy (path, cptr, sizeof (path));
while ((c = strchr (path, '\\'))) while ((c = strchr (path, '\\')))
*c = '/'; *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; c = path;
while ((c = strchr (c, '/'))) { while ((c = strchr (c, '/'))) {
*c = '\0'; *c = '\0';