I am writing a program which currently gets continuous input from stdin and does something with it until stdin is closed.
fgets(buffer, BUFFERSIZE, stdin);
while(fcntl(fileno(stdin), F_GETFD) != -1 || errno != EBADF){
/*
some code
*/
fgets(buffer, BUFFERSIZE, stdin);
}
Currently to test out if this is a valid way of checking if stdin is closed the
some code
is set to just print buffer continuously. However when I try to close stdin with Ctrl +D the program keeps printing whatever it had in buffer indefinitely. Why is that?