mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-28 10:46:33 +08:00
posix main shell: fix getchar() return value and check for EOF to avoid busy loop
This commit is contained in:
@@ -533,11 +533,15 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
while (!_ExitFlag) {
|
while (!_ExitFlag) {
|
||||||
|
|
||||||
char c = getchar();
|
int c = getchar();
|
||||||
string add_string; // string to add at current cursor position
|
string add_string; // string to add at current cursor position
|
||||||
bool update_prompt = true;
|
bool update_prompt = true;
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
case EOF:
|
||||||
|
_ExitFlag = true;
|
||||||
|
break;
|
||||||
|
|
||||||
case 127: // backslash
|
case 127: // backslash
|
||||||
if (mystr.length() - cursor_position > 0) {
|
if (mystr.length() - cursor_position > 0) {
|
||||||
mystr.erase(mystr.length() - cursor_position - 1, 1);
|
mystr.erase(mystr.length() - cursor_position - 1, 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user