commit ef78f20dd8dfbe9c72e0477fc620c31ec852d7e1
Author: sin <[email protected]>
Date:   Mon Aug 18 22:02:22 2014 +0100

    Use agetline() in lastlog(8)
    
    Some other minor changes as well.

diff --git a/lastlog.c b/lastlog.c
index 1a27ae4..c9f0949 100644
--- a/lastlog.c
+++ b/lastlog.c
@@ -8,6 +8,7 @@
 #include <time.h>
 #include <utmp.h>
 
+#include "text.h"
 #include "util.h"
 
 #define PASSWD   "/etc/passwd"
@@ -34,7 +35,7 @@ lastlog(char *user)
        fread(&ll, sizeof(struct lastlog), 1, last);
 
        if (ferror(last))
-               eprintf("error reading lastlog
");
+               eprintf("%s: read error:", _PATH_LASTLOG);
 
        /* on glibc `ll_time' can be an int32_t with compat32
         * avoid compiler warning when calling ctime() */
@@ -47,7 +48,8 @@ int
 main(int argc, char **argv)
 {
        FILE *fp;
-       char line[512], *p;
+       char *line = NULL, *p;
+       size_t sz = 0;
 
        if ((last = fopen(_PATH_LASTLOG, "r")) == NULL)
                eprintf("fopen %s:", _PATH_LASTLOG);
@@ -58,17 +60,19 @@ main(int argc, char **argv)
        } else {
                if ((fp = fopen(PASSWD, "r")) == NULL)
                        eprintf("fopen %s:", PASSWD);
-               while ((fgets(line, sizeof(line), fp)) != NULL) {
+               while (agetline(&line, &sz, fp) != -1) {
                        if ((p = strchr(line, ':')) == NULL)
                                eprintf("invalid passwd entry
");
                        *p = '

Reply via email to