summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--linenoise/linenoise.c20
-rw-r--r--linenoise/linenoise.h1
2 files changed, 19 insertions, 2 deletions
diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c
index ff931121..d1973e94 100644
--- a/linenoise/linenoise.c
+++ b/linenoise/linenoise.c
@@ -88,6 +88,7 @@ struct lino_state {
char buf[LINENOISE_MAX_DISP]; /* Displayed line bufer. */
char data[LINENOISE_MAX_LINE]; /* True data corresponding to display */
const char *prompt; /* Prompt to display. */
+ const char *suffix; /* Suffix when creating temp file. */
size_t plen; /* Prompt length. */
size_t pos; /* Current cursor position. */
size_t len; /* Current edited line display length. */
@@ -1022,14 +1023,24 @@ static void edit_in_editor(lino_t *l) {
if (ed) {
char *ho = getenv("HOME");
int fd;
+#if HAVE_MKSTEMPS
+ const char *suffix = l->suffix ? l->suffix : "";
+#else
+ const char *suffix = "";
+#endif
if (ho)
- snprintf(path, sizeof path, "%s/%s", ho, template);
+ snprintf(path, sizeof path, "%s/%s%s", ho, template, suffix);
else
- snprintf(path, sizeof path, "%s", template);
+ snprintf(path, sizeof path, "%s%s", template, suffix);
+#if HAVE_MKSTEMPS
+ if ((fd = mkstemps(path, strlen(suffix))) != -1)
+ fo = fdopen(fd, "w");
+#else
if ((fd = mkstemp(path)) != -1)
fo = fdopen(fd, "w");
+#endif
if (!fo && fd != -1)
close(fd);
@@ -1486,6 +1497,11 @@ void lino_free(lino_t *ls)
}
}
+void lino_set_tempfile_suffix(lino_t *l, const char *suffix)
+{
+ l->suffix = suffix;
+}
+
lino_error_t lino_get_error(lino_t *l)
{
return l->error;
diff --git a/linenoise/linenoise.h b/linenoise/linenoise.h
index 688ed64c..6471993f 100644
--- a/linenoise/linenoise.h
+++ b/linenoise/linenoise.h
@@ -61,6 +61,7 @@ lino_t *lino_copy(lino_t *);
void lino_free(lino_t *);
char *linenoise(lino_t *, const char *prompt);
+void lino_set_tempfile_suffix(lino_t *, const char *);
lino_error_t lino_get_error(lino_t *);
lino_error_t lino_set_error(lino_t *, lino_error_t); /* returns old */
int lino_hist_add(lino_t *, const char *line);