Handle the bytesRead = CMDLENGTH case properly

This commit is contained in:
Utkarsh Verma 2022-02-26 08:55:50 +05:30
parent 1676c07b8f
commit c720d07df8
No known key found for this signature in database
GPG Key ID: 817656CF818EFCCC

8
main.c
View File

@ -114,6 +114,9 @@ void updateBlock(int i) {
int j = bytesRead - 1;
while ((buffer[j] & 0b11000000) == 0x80)
j--;
// Cache last character and replace it with a trailing space
char ch = buffer[j];
buffer[j] = ' ';
// Trim trailing spaces
@ -121,10 +124,9 @@ void updateBlock(int i) {
j--;
buffer[j + 1] = '\0';
if (bytesRead == LEN(buffer)) {
// Clear the pipe
char ch;
while (read(pipes[i][0], &ch, 1) == 1 && ch != '\n')
if (bytesRead == LEN(buffer)) {
while (ch != '\n' && read(pipes[i][0], &ch, 1) == 1)
;
}