Fix funkiness with EOF

This commit is contained in:
Juhani Krekelä 2018-07-16 18:09:24 +00:00
parent d7840e0ccf
commit 9f057f691f
1 changed files with 11 additions and 6 deletions

View File

@ -1,4 +1,5 @@
#define _GNU_SOURCE #define _GNU_SOURCE
#include <errno.h>
#include <netdb.h> #include <netdb.h>
#include <poll.h> #include <poll.h>
#include <stdarg.h> #include <stdarg.h>
@ -138,16 +139,20 @@ void handle_userlist(int sock) {
// Go over users' home dirs and see if .finger-response is present // Go over users' home dirs and see if .finger-response is present
FILE *passwd = fopen("/etc/passwd", "r"); FILE *passwd = fopen("/etc/passwd", "r");
while(!feof(passwd)) { for(;;) {
char *line = NULL; char *line = NULL;
size_t line_length; size_t line_length;
// FIXME: Funkiness with eof errno = 0;
if(getline(&line, &line_length, passwd) < 0) { if(getline(&line, &line_length, passwd) < 0) {
// Bail out on error if(errno == 0) {
perror("getline"); // EOF reached
free(line); break;
return; } else {
perror("getline");
free(line);
return;
}
} }
printf("%s", line); //debg printf("%s", line); //debg