Fixed game save in dfrotz broken in 6c65ac8e.
authorDavid Griffith <dave@661.org>
Sun, 14 May 2023 19:10:22 +0000 (12:10 -0700)
committerDavid Griffith <dave@661.org>
Sun, 14 May 2023 19:10:22 +0000 (12:10 -0700)
src/dumb/dinput.c

index 222af9742219019a9aca41daf2b48b5c2b6c895f..5b7a779fac85a7d3b3c358f5b229bef984448c6f 100644 (file)
@@ -551,32 +551,26 @@ char *os_read_file_name (const char *default_name, int flag)
                else
                        buf = basename((char *)default_name);
        } else {
-               if (f_setup.restricted_path) {
-                       for (i = strlen(default_name); i > 0; i--) {
-                               if (default_name[i] == PATH_SEPARATOR) {
-                                       i++;
-                                       break;
-                               }
-                       }
-                       tempname = strdup(default_name + i);
-                       sprintf(prompt, "Please enter a filename [%s]: ", tempname);
+               if (f_setup.restricted_path != NULL) {
+                       sprintf(prompt, "Please enter a filename [%s]: ", basename((char *)default_name));
                } else
                        sprintf(prompt, "Please enter a filename [%s]: ", default_name);
+
                dumb_read_misc_line(fullpath, prompt);
-               if (!fullpath[0])
-                       buf = fullpath;
-               else
-                       buf = basename(fullpath);
+
+               /* If using default filename... */
+               if (strlen(fullpath) == 0)
+                       buf = strndup(default_name, MAX_FILE_NAME);
+               else /* Using supplied filename... */
+                       buf = strndup(fullpath, MAX_FILE_NAME);
+
                if (strlen(buf) > MAX_FILE_NAME) {
                        printf("Filename too long\n");
                        return NULL;
                }
        }
 
-       if (buf == NULL || flag == FILE_NO_PROMPT)
-               strncpy(file_name, default_name, FILENAME_MAX);
-       else
-               strncpy(file_name, fullpath, FILENAME_MAX);
+       strncpy(file_name, buf, FILENAME_MAX);
 
        /* Check if we're restricted to one directory. */
        if (f_setup.restricted_path != NULL) {