commit ae7f5ebdeb7f544bd9dff33fba5553bab91c90a4
parent bea5e85f3ea79d1838e027b5d0880aa018686d84
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Fri, 5 Jun 2020 17:08:04 +0200
tweaks: move a function to before the one that calls it
Diffstat:
M | src/nano.c | | | 73 | ++++++++++++++++++++++++++++++++++++------------------------------------- |
M | src/proto.h | | | 1 | - |
2 files changed, 36 insertions(+), 38 deletions(-)
diff --git a/src/nano.c b/src/nano.c
@@ -273,6 +273,42 @@ void finish(void)
exit(0);
}
+/* Save the current buffer under the given name (or under the name "nano"
+ * for a nameless buffer). If needed, the name is modified to be unique. */
+void emergency_save(const char *die_filename, struct stat *die_stat)
+{
+ bool failed = TRUE;
+ char *targetname;
+
+ if (*die_filename == '\0')
+ die_filename = "nano";
+
+ targetname = get_next_filename(die_filename, ".save");
+
+ if (*targetname != '\0')
+ failed = !write_file(targetname, NULL, TRUE, OVERWRITE, FALSE);
+
+ if (!failed)
+ fprintf(stderr, _("\nBuffer written to %s\n"), targetname);
+ else if (*targetname != '\0')
+ fprintf(stderr, _("\nBuffer not written to %s: %s\n"),
+ targetname, strerror(errno));
+ else
+ fprintf(stderr, _("\nToo many .save files"));
+
+#ifndef NANO_TINY
+ /* Try to chmod/chown the saved file to the values of the original file,
+ * but ignore any failure as we are in a hurry to get out. */
+ if (die_stat) {
+ IGNORE_CALL_RESULT(chmod(targetname, die_stat->st_mode));
+ IGNORE_CALL_RESULT(chown(targetname, die_stat->st_uid,
+ die_stat->st_gid));
+ }
+#endif
+
+ free(targetname);
+}
+
/* Die gracefully -- by restoring the terminal state and saving any buffers
* that were modified. */
void die(const char *msg, ...)
@@ -313,43 +349,6 @@ void die(const char *msg, ...)
exit(1);
}
-/* Save the current buffer under the given name.
- * If necessary, the name is modified to be unique. */
-void emergency_save(const char *die_filename, struct stat *die_stat)
-{
- char *targetname;
- bool failed = TRUE;
-
- /* If the buffer has no name, simply call it "nano". */
- if (*die_filename == '\0')
- die_filename = "nano";
-
- targetname = get_next_filename(die_filename, ".save");
-
- if (*targetname != '\0')
- failed = !write_file(targetname, NULL, TRUE, OVERWRITE, FALSE);
-
- if (!failed)
- fprintf(stderr, _("\nBuffer written to %s\n"), targetname);
- else if (*targetname != '\0')
- fprintf(stderr, _("\nBuffer not written to %s: %s\n"),
- targetname, strerror(errno));
- else
- fprintf(stderr, _("\nToo many .save files"));
-
-#ifndef NANO_TINY
- /* Try to chmod/chown the saved file to the values of the original file,
- * but ignore any failure as we are in a hurry to get out. */
- if (die_stat) {
- IGNORE_CALL_RESULT(chmod(targetname, die_stat->st_mode));
- IGNORE_CALL_RESULT(chown(targetname, die_stat->st_uid,
- die_stat->st_gid));
- }
-#endif
-
- free(targetname);
-}
-
/* Initialize the three window portions nano uses. */
void window_init(void)
{
diff --git a/src/proto.h b/src/proto.h
@@ -411,7 +411,6 @@ void say_there_is_no_help(void);
#endif
void finish(void);
void die(const char *msg, ...);
-void emergency_save(const char *die_filename, struct stat *die_stat);
void window_init(void);
void do_exit(void);
void close_and_go(void);