[hackers] [ubase] Use agetline() in lastlog(8) || sin
commit ef78f20dd8dfbe9c72e0477fc620c31ec852d7e1
Author: sin <sin_AT_2f30.org>
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
_AT_@ -8,6 +8,7 @@
#include <time.h>
#include <utmp.h>
+#include "text.h"
#include "util.h"
#define PASSWD "/etc/passwd"
_AT_@ -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() */
_AT_@ -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);
_AT_@ -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 = '
Received on Mon Aug 18 2014 - 23:03:58 CEST
This archive was generated by hypermail 2.3.0
: Mon Aug 18 2014 - 23:12:08 CEST