diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2018-05-18 06:24:22 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2018-05-18 06:24:22 -0700 |
commit | b13a869dddb06218151f00a0abec077fff9cdd4a (patch) | |
tree | 36bc99e1331499e91bed8a9a4a9898b896c95c06 /parser.c | |
parent | a7916fbac400497b6ac35da8a689a3c2cb68141d (diff) | |
download | txr-b13a869dddb06218151f00a0abec077fff9cdd4a.tar.gz txr-b13a869dddb06218151f00a0abec077fff9cdd4a.tar.bz2 txr-b13a869dddb06218151f00a0abec077fff9cdd4a.zip |
listener: Cygwin fix.
We cannot pass raw C wide literals to static_str; this breaks
on platforms where wchar_t is two bytes and strings are
aligned to only two byte boundaries. That's why TXR has the
wli() macro. We don't want to introduce the wli() macro into
linenoise, so the two choices are: duplicate the incoming mode
strings into dynamic storage with string(), or pass some enum
to specify file mode and locally convert to static mode
string. Let's go with the latter.
* linenoise.c (edit_in_editor, lino_hist_save): Use enum
constant for file mode instead of mode string.
* linenoise.h (enum lino_file_mode, line_file_mode_t):
New enum.
(struct lino_os): File opening functions use lino_file_mode_t
instead of mode string.
* parser.c (lino_mode_str): New static array.
(lino_open, lino_open8, lino_fdopen): Take enum mode instead
of string. Convert to literal through lino_mode_str table,
and pass that literal to static_str.
Diffstat (limited to 'parser.c')
-rw-r--r-- | parser.c | 16 |
1 files changed, 10 insertions, 6 deletions
@@ -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)); } |