aboutsummaryrefslogtreecommitdiff
path: root/qlop.c
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2015-11-27 13:14:14 -0500
committerMike Frysinger <vapier@gentoo.org>2015-11-27 13:14:14 -0500
commit92de436359da8f14b7dbef5f62af959095b79d06 (patch)
tree5936173e0b278b45a58d5ea1601433d7cce1ee81 /qlop.c
parentrmspace: rewrite/optimize a bit (diff)
downloadportage-utils-92de436359da8f14b7dbef5f62af959095b79d06.tar.gz
portage-utils-92de436359da8f14b7dbef5f62af959095b79d06.tar.bz2
portage-utils-92de436359da8f14b7dbef5f62af959095b79d06.zip
use the return value of getline
This allows us to avoid calling strlen to get a value getline already calculated. We can also pass this value on to rmspace to let it trim space for us.
Diffstat (limited to 'qlop.c')
-rw-r--r--qlop.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/qlop.c b/qlop.c
index 390865a..f2f97c6 100644
--- a/qlop.c
+++ b/qlop.c
@@ -240,7 +240,7 @@ _q_static void
show_emerge_history(char listflag, int argc, char **argv, const char *logfile)
{
FILE *fp;
- size_t buflen;
+ size_t buflen, linelen;
char *buf, merged;
char *p, *q;
int i;
@@ -252,8 +252,8 @@ show_emerge_history(char listflag, int argc, char **argv, const char *logfile)
}
buf = NULL;
- while (getline(&buf, &buflen, fp) != -1) {
- if (strlen(buf) < 30)
+ while ((linelen = getline(&buf, &buflen, fp)) != -1) {
+ if (linelen < 30)
continue;
for (i = 0; i < argc; ++i)
@@ -262,8 +262,7 @@ show_emerge_history(char listflag, int argc, char **argv, const char *logfile)
if (argc && i == argc)
continue;
- if ((p = strchr(buf, '\n')) != NULL)
- *p = 0;
+ rmspace_len(buf, linelen);
if ((p = strchr(buf, ':')) == NULL)
continue;
*p = 0;
@@ -327,7 +326,7 @@ _q_static void
show_sync_history(const char *logfile)
{
FILE *fp;
- size_t buflen, len;
+ size_t buflen, linelen;
char *buf, *p;
time_t t;
@@ -338,10 +337,9 @@ show_sync_history(const char *logfile)
buf = NULL;
/* Just find the finish lines. */
- while (getline(&buf, &buflen, fp) != -1) {
- len = strlen(buf);
+ while ((linelen = getline(&buf, &buflen, fp)) != -1) {
/* This cuts out like ~10% of the log. */
- if (len < 35)
+ if (linelen < 35)
continue;
/* Make sure there's a timestamp in here. */
@@ -353,8 +351,7 @@ show_sync_history(const char *logfile)
continue;
p += 19;
- if (buf[len - 1] == '\n')
- buf[len - 1] = '\0';
+ rmspace_len(buf, linelen);
t = (time_t)atol(buf);