when compiling with every option manually turned on, including
NANO_SMALL. (David Benbennick)
- files.c:
+ get_next_filename()
+ - Tweak for efficiency, and add the ".save" suffix to the file
+ here. (David Benbennick)
close_open_file()
- Tweak to no longer rely on the return values of
open_(prev|next)file(). (DLR)
thanks_for_all_the_fish()
- Delete topwin, edit, and bottomwin. (David Benbennick)
- nano.c:
+ die()
+ - Don't add the ".save" suffix to a saved file here anymore,
+ since get_next_filename() does that now. (David Benbennick)
+ die_save_file()
+ - Tweak for efficiency. (David Benbennick)
help_init()
- Fix the display of the translated key descriptions "Up" and
"Space" under all circumstances, and make the help browser
}
/* This function will return the name of the first available extension
- * of a filename (starting with the filename, then filename.1, etc).
- * Memory is allocated for the return value. If no writable extension
- * exists, we return "". */
+ * of a filename (starting with the filename.save, then filename.save.1,
+ * etc). Memory is allocated for the return value. If no writable
+ * extension exists, we return "". */
char *get_next_filename(const char *name)
{
int i = 0;
- char *buf = NULL;
- struct stat fs;
+ char *buf;
+ size_t namelen = strlen(name);
- buf = charalloc(strlen(name) + num_of_digits(INT_MAX) + 2);
+ buf = charalloc(namelen + num_of_digits(INT_MAX) + 7);
strcpy(buf, name);
+ strcpy(buf + namelen, ".save");
+ namelen += 5;
while (TRUE) {
+ struct stat fs;
if (stat(buf, &fs) == -1)
return buf;
break;
i++;
- strcpy(buf, name);
- sprintf(&buf[strlen(name)], ".%d", i);
+ sprintf(buf + namelen, ".%d", i);
}
/* We get here only if there is no possible save file. */
exit(0);
}
-/* Die (gracefully?) */
+/* Die (gracefully?). */
void die(const char *msg, ...)
{
va_list ap;
/* If we can't save, we have REAL bad problems, but we might as well
TRY. */
if (die_filename[0] == '\0')
- ret = get_next_filename("nano.save");
- else {
- char *buf = charalloc(strlen(die_filename) + 6);
+ die_filename = "nano";
- strcpy(buf, die_filename);
- strcat(buf, ".save");
- ret = get_next_filename(buf);
- free(buf);
- }
+ ret = get_next_filename(die_filename);
if (ret[0] != '\0')
failed = -1 == write_file(ret, TRUE, FALSE, TRUE);