-
Notifications
You must be signed in to change notification settings - Fork 362
Closed
Description
I did not know where else to raise an issue regarding the blog post, as getline is not there in the code on github.
The code on the blog post does not handle the case where the user inputs an EOF, wanting to exit the shell. I believe it should be:
char *lsh_read_line(void)
{
char *line = NULL;
ssize_t bufsize = 0; // have getline allocate a buffer for us
if (getline(&line, &bufsize, stdin) == -1)
exit(EXIT_SUCCESS);
return line;
}
Or, to be even more pedantic:
char *lsh_read_line(void)
{
char *line = NULL;
ssize_t bufsize = 0; // have getline allocate a buffer for us
if (getline(&line, &bufsize, stdin) == -1){
if (feof(stdin)) {
exit(EXIT_SUCCESS); // We recieved an EOF
} else {
perror("readline");
exit(EXIT_FAILURE);
}
}
return line;
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels