Open RobSim0116 opened 1 month ago
You're definitely correct! If you'd like to submit a pull request with that change, I'd be happy to merge it. One slight change I would suggest is rather than the fprintf()
call you have, you can use the perror(3)
function:
perror("getchar");
This will automatically lookup what the error was (using the errno
variable and then strerror(3)
), and it will print that message to stderr
, prefixed by whatever you put in as the first string argument. So, for example, you might get something like this printed to stderr:
getchar: Bad file descriptor
Hi :) I just wanted to contribute to your excellent tutorial by (I think) improving the error handling in
lsh_read_line()
. Unless I'm mistaken, I don't think it currently handles the case when EOF actually indicates a read error and not a "successful" EOF/an EOF proper. My own code for thewhile
loop looks more or less like this at the moment (you can see I'm (a) checking for the meaning of the returned EOF and (b) ensuring the buffer is freed before exiting):What do you think? Have I made a mistake in my reasoning?