We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent fdf0716 commit bb229d8Copy full SHA for bb229d8
src/main.c
@@ -181,14 +181,19 @@ char *lsh_read_line(void)
181
// Read a character
182
c = getchar();
183
184
- if (c == EOF) {
+ if (c == EOF && feof(stdin)) {
185
+ free(buffer);
186
exit(EXIT_SUCCESS);
187
+ } else if (c == EOF && ferror(stdin)) {
188
+ perror("getchar (EOF)");
189
190
+ exit(EXIT_FAILURE);
191
} else if (c == '\n') {
192
buffer[position] = '\0';
193
return buffer;
- } else {
- buffer[position] = c;
194
}
195
+
196
+ buffer[position] = c;
197
position++;
198
199
// If we have exceeded the buffer, reallocate.
0 commit comments