summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--linenoise/linenoise.c10
-rw-r--r--linenoise/linenoise.h11
-rw-r--r--parser.c16
3 files changed, 23 insertions, 14 deletions
diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c
index 005cdb1d..1cdb1997 100644
--- a/linenoise/linenoise.c
+++ b/linenoise/linenoise.c
@@ -1825,10 +1825,10 @@ static void edit_in_editor(lino_t *l) {
#if HAVE_MKSTEMPS
if ((fd = mkstemps(path, strlen(suffix))) != -1)
- fo = lino_os.fdopen_fn(fd, L"w");
+ fo = lino_os.fdopen_fn(fd, lino_overwrite);
#else
if ((fd = mkstemp(path)) != -1)
- fo = lino_os.fdopen_fn(fd, L"w");
+ fo = lino_os.fdopen_fn(fd, lino_overwrite);
#endif
if (!fo && fd != -1)
@@ -1846,7 +1846,7 @@ static void edit_in_editor(lino_t *l) {
lino_os.close_fn(fo);
fo = 0;
- if (system(cmd) == 0 && (fi = lino_os.open8_fn(path, L"r")) != 0) {
+ if (system(cmd) == 0 && (fi = lino_os.open8_fn(path, lino_read)) != 0) {
size_t len;
(void) lino_os.gets_fn(fi, l->data, nelem(l->data));
lino_os.close_fn(fi);
@@ -2619,7 +2619,7 @@ int lino_hist_set_max_len(lino_t *ls, int len) {
/* Save the history in the specified file. On success 0 is returned
* otherwise -1 is returned. */
int lino_hist_save(lino_t *ls, const wchar_t *filename) {
- mem_t *fp = lino_os.open_fn(filename, L"w");
+ mem_t *fp = lino_os.open_fn(filename, lino_overwrite);
int j;
if (fp == NULL) {
@@ -2642,7 +2642,7 @@ int lino_hist_save(lino_t *ls, const wchar_t *filename) {
* If the file exists and the operation succeeded 0 is returned, otherwise
* on error -1 is returned. */
int lino_hist_load(lino_t *ls, const wchar_t *filename) {
- mem_t *fp = lino_os.open_fn(filename, L"r");
+ mem_t *fp = lino_os.open_fn(filename, lino_read);
wchar_t buf[LINENOISE_MAX_LINE];
if (fp == NULL) {
diff --git a/linenoise/linenoise.h b/linenoise/linenoise.h
index 8cc0a234..3c887a33 100644
--- a/linenoise/linenoise.h
+++ b/linenoise/linenoise.h
@@ -54,6 +54,11 @@ typedef unsigned char mem_t;
#define MEM_T_DEFINED
#endif
+typedef enum lino_file_mode {
+ lino_read,
+ lino_overwrite,
+} lino_file_mode_t;
+
typedef struct lino_os {
mem_t *(*alloc_fn)(size_t n);
mem_t *(*realloc_fn)(mem_t *old, size_t size);
@@ -67,9 +72,9 @@ typedef struct lino_os {
wchar_t *(*getl_fn)(mem_t *stream, wchar_t *buf, size_t nchar);
wchar_t *(*gets_fn)(mem_t *stream, wchar_t *buf, size_t nchar);
int (*eof_fn)(mem_t *stream);
- mem_t *(*open_fn)(const wchar_t *name, const wchar_t *mode);
- mem_t *(*open8_fn)(const char *name, const wchar_t *mode);
- mem_t *(*fdopen_fn)(int fd, const wchar_t *mode);
+ mem_t *(*open_fn)(const wchar_t *name, lino_file_mode_t mode);
+ mem_t *(*open8_fn)(const char *name, lino_file_mode_t mode);
+ mem_t *(*fdopen_fn)(int fd, lino_file_mode_t mode);
void (*close_fn)(mem_t *stream);
int (*wide_display_fn)(wchar_t);
} lino_os_t;
diff --git a/parser.c b/parser.c
index 575ea1e3..ddd72fd1 100644
--- a/parser.c
+++ b/parser.c
@@ -1489,23 +1489,27 @@ static int lino_feof(mem_t *stream_in)
return get_error(stream) == t;
}
-static mem_t *lino_open(const wchar_t *name_in, const wchar_t *mode_in)
+static const wchli_t *lino_mode_str[] = {
+ wli("r"), wli("w")
+};
+
+static mem_t *lino_open(const wchar_t *name_in, lino_file_mode_t mode_in)
{
val name = string(name_in);
- val mode = static_str(coerce(const wchli_t *, mode_in));
+ val mode = static_str(lino_mode_str[mode_in]);
return coerce(mem_t *, open_file(name, mode));
}
-static mem_t *lino_open8(const char *name_in, const wchar_t *mode_in)
+static mem_t *lino_open8(const char *name_in, lino_file_mode_t mode_in)
{
val name = string_utf8(name_in);
- val mode = static_str(coerce(const wchli_t *, mode_in));
+ val mode = static_str(lino_mode_str[mode_in]);
return coerce(mem_t *, open_file(name, mode));
}
-static mem_t *lino_fdopen(int fd, const wchar_t *mode_in)
+static mem_t *lino_fdopen(int fd, lino_file_mode_t mode_in)
{
- val mode = static_str(coerce(const wchli_t *, mode_in));
+ val mode = static_str(lino_mode_str[mode_in]);
return coerce(mem_t *, open_fileno(num(fd), mode));
}