diff options
Diffstat (limited to 'linenoise')
-rw-r--r-- | linenoise/linenoise.c | 10 | ||||
-rw-r--r-- | linenoise/linenoise.h | 11 |
2 files changed, 13 insertions, 8 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; |