diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2025-07-02 21:55:42 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2025-07-02 21:55:42 +0200 |
| commit | bbaa56f7378240fca3db9165dfd02a4504d95ff1 (patch) | |
| tree | 565e7a149385f5a678d3d69ac2e92959b0f4b8f8 | |
| parent | 8c835540efb88f46a66ee28c74f031b74ad07b26 (diff) | |
| download | busybox-w32-bbaa56f7378240fca3db9165dfd02a4504d95ff1.tar.gz busybox-w32-bbaa56f7378240fca3db9165dfd02a4504d95ff1.tar.bz2 busybox-w32-bbaa56f7378240fca3db9165dfd02a4504d95ff1.zip | |
use pollfd[1] array for poll() argument
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | libbb/read_key.c | 11 | ||||
| -rw-r--r-- | shell/shell_common.c | 4 |
2 files changed, 8 insertions, 7 deletions
diff --git a/libbb/read_key.c b/libbb/read_key.c index cf8ed411e..1bea75fcf 100644 --- a/libbb/read_key.c +++ b/libbb/read_key.c | |||
| @@ -11,7 +11,7 @@ | |||
| 11 | 11 | ||
| 12 | int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout) | 12 | int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout) |
| 13 | { | 13 | { |
| 14 | struct pollfd pfd; | 14 | struct pollfd pfd[1]; |
| 15 | const char *seq; | 15 | const char *seq; |
| 16 | int n; | 16 | int n; |
| 17 | 17 | ||
| @@ -112,8 +112,8 @@ int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout) | |||
| 112 | 0 | 112 | 0 |
| 113 | }; | 113 | }; |
| 114 | 114 | ||
| 115 | pfd.fd = fd; | 115 | pfd->fd = fd; |
| 116 | pfd.events = POLLIN; | 116 | pfd->events = POLLIN; |
| 117 | 117 | ||
| 118 | buffer++; /* saved chars counter is in buffer[-1] now */ | 118 | buffer++; /* saved chars counter is in buffer[-1] now */ |
| 119 | 119 | ||
| @@ -135,6 +135,7 @@ int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout) | |||
| 135 | return -1; | 135 | return -1; |
| 136 | } | 136 | } |
| 137 | } | 137 | } |
| 138 | |||
| 138 | /* It is tempting to read more than one byte here, | 139 | /* It is tempting to read more than one byte here, |
| 139 | * but it breaks pasting. Example: at shell prompt, | 140 | * but it breaks pasting. Example: at shell prompt, |
| 140 | * user presses "c","a","t" and then pastes "\nline\n". | 141 | * user presses "c","a","t" and then pastes "\nline\n". |
| @@ -173,7 +174,7 @@ int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout) | |||
| 173 | * so if we block for long it's not really an escape sequence. | 174 | * so if we block for long it's not really an escape sequence. |
| 174 | * Timeout is needed to reconnect escape sequences | 175 | * Timeout is needed to reconnect escape sequences |
| 175 | * split up by transmission over a serial console. */ | 176 | * split up by transmission over a serial console. */ |
| 176 | if (safe_poll(&pfd, 1, 50) == 0) { | 177 | if (safe_poll(pfd, 1, 50) == 0) { |
| 177 | /* No more data! | 178 | /* No more data! |
| 178 | * Array is sorted from shortest to longest, | 179 | * Array is sorted from shortest to longest, |
| 179 | * we can't match anything later in array - | 180 | * we can't match anything later in array - |
| @@ -222,7 +223,7 @@ int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout) | |||
| 222 | * n = bytes read. Try to read more until we time out. | 223 | * n = bytes read. Try to read more until we time out. |
| 223 | */ | 224 | */ |
| 224 | while (n < KEYCODE_BUFFER_SIZE-1) { /* 1 for count byte at buffer[-1] */ | 225 | while (n < KEYCODE_BUFFER_SIZE-1) { /* 1 for count byte at buffer[-1] */ |
| 225 | if (safe_poll(&pfd, 1, 50) == 0) { | 226 | if (safe_poll(pfd, 1, 50) == 0) { |
| 226 | /* No more data! */ | 227 | /* No more data! */ |
| 227 | break; | 228 | break; |
| 228 | } | 229 | } |
diff --git a/shell/shell_common.c b/shell/shell_common.c index 9a03f7265..2baa9d3a8 100644 --- a/shell/shell_common.c +++ b/shell/shell_common.c | |||
| @@ -55,7 +55,7 @@ const char* FAST_FUNC | |||
| 55 | shell_builtin_read(struct builtin_read_params *params) | 55 | shell_builtin_read(struct builtin_read_params *params) |
| 56 | { | 56 | { |
| 57 | struct pollfd pfd[1]; | 57 | struct pollfd pfd[1]; |
| 58 | #define fd (pfd[0].fd) /* -u FD */ | 58 | #define fd (pfd->fd) /* -u FD */ |
| 59 | unsigned err; | 59 | unsigned err; |
| 60 | unsigned end_ms; /* -t TIMEOUT */ | 60 | unsigned end_ms; /* -t TIMEOUT */ |
| 61 | int nchars; /* -n NUM */ | 61 | int nchars; /* -n NUM */ |
| @@ -142,7 +142,7 @@ shell_builtin_read(struct builtin_read_params *params) | |||
| 142 | * bash seems to ignore -p PROMPT for this use case. | 142 | * bash seems to ignore -p PROMPT for this use case. |
| 143 | */ | 143 | */ |
| 144 | int r; | 144 | int r; |
| 145 | pfd[0].events = POLLIN; | 145 | pfd->events = POLLIN; |
| 146 | r = poll(pfd, 1, /*timeout:*/ 0); | 146 | r = poll(pfd, 1, /*timeout:*/ 0); |
| 147 | /* Return 0 only if poll returns 1 ("one fd ready"), else return 1: */ | 147 | /* Return 0 only if poll returns 1 ("one fd ready"), else return 1: */ |
| 148 | return (const char *)(uintptr_t)(r <= 0); | 148 | return (const char *)(uintptr_t)(r <= 0); |
