Skip to content

Commit 89d6c34

Browse files
committed
Fix Ctrl+D on FreeBSD
This was broken by the macOS fix because apparently, editline acts differently on those platforms. I have tested that Linux, macOS, and FreeBSD all work with this one, both SIGWINCH and Ctrl+D. Well, Ctrl+D doesn't work on macOS, but that is actually a limitation I *can't* get around. Fixes FreeBSD being broken by 56bb182. Signed-off-by: Gavin D. Howard <gavin@gavinhoward.com>
1 parent c5b7724 commit 89d6c34

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

include/history.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,30 @@ typedef struct BcHistory
120120
extern const char bc_history_editrc[];
121121
extern const size_t bc_history_editrc_len;
122122

123+
#ifdef __APPLE__
124+
125+
/**
126+
* Returns true if the line is a valid line, false otherwise.
127+
* @param line The line.
128+
* @param len The length of the line.
129+
* @return True if the line is valid, false otherwise.
130+
*/
131+
#define BC_HISTORY_INVALID_LINE(line, len) \
132+
((line) == NULL && ((len) == -1 || errno == EINTR))
133+
134+
#else // __APPLE__
135+
136+
/**
137+
* Returns true if the line is a valid line, false otherwise.
138+
* @param line The line.
139+
* @param len The length of the line.
140+
* @return True if the line is valid, false otherwise.
141+
*/
142+
#define BC_HISTORY_INVALID_LINE(line, len) \
143+
((line) == NULL && (len) == -1 && errno == EINTR)
144+
145+
#endif // __APPLE__
146+
123147
#else // BC_ENABLE_EDITLINE
124148

125149
#if BC_ENABLE_READLINE

src/history.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,18 @@ bc_history_line(BcHistory* h, BcVec* vec, const char* prompt)
264264
errno = EINTR;
265265

266266
// Get the line.
267-
while (line == NULL && (len == -1 || errno == EINTR))
267+
//
268+
// XXX: Why have a macro here? Because macOS needs to be special. Honestly,
269+
// it's starting to feel special like Windows at this point. Anyway, the
270+
// second SIGWINCH signal of multiple will return a valid line length on
271+
// macOS, so we need to allow for that on macOS. However, FreeBSD's editline
272+
// is different and will mess up the terminal if we do it that way.
273+
//
274+
// There is one limitation with this, however: Ctrl+D won't work on macOS.
275+
// But it's because of macOS that this problem exists, and I can't really do
276+
// anything about it. So macOS should fix their broken editline; once they
277+
// do, I'll fix Ctrl+D on macOS.
278+
while (BC_HISTORY_INVALID_LINE(line, len))
268279
{
269280
line = el_gets(h->el, &len);
270281
bc_history_use_prompt = false;

0 commit comments

Comments
 (0)