Fix funkiness with EOF
This commit is contained in:
parent
d7840e0ccf
commit
9f057f691f
|
@ -1,4 +1,5 @@
|
|||
#define _GNU_SOURCE
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <poll.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
|
||||
FILE *passwd = fopen("/etc/passwd", "r");
|
||||
|
||||
while(!feof(passwd)) {
|
||||
for(;;) {
|
||||
char *line = NULL;
|
||||
size_t line_length;
|
||||
|
||||
// FIXME: Funkiness with eof
|
||||
errno = 0;
|
||||
if(getline(&line, &line_length, passwd) < 0) {
|
||||
// Bail out on error
|
||||
perror("getline");
|
||||
free(line);
|
||||
return;
|
||||
if(errno == 0) {
|
||||
// EOF reached
|
||||
break;
|
||||
} else {
|
||||
perror("getline");
|
||||
free(line);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
printf("%s", line); //debg
|
||||
|
|
Loading…
Reference in New Issue