aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2015-12-29 11:52:12 -0600
committerRob Landley <rob@landley.net>2015-12-29 11:52:12 -0600
commit4d3ad67ab37a25d0edfccdc34d29ec550e0802b6 (patch)
tree2ea5d17313d4efbd358add3d45580244c1190136
parent1bf844232802d2deec7a2e9bee355e4c26259101 (diff)
downloadtoybox-4d3ad67ab37a25d0edfccdc34d29ec550e0802b6.tar.gz
Add strafter() to lib.
-rw-r--r--lib/lib.c8
-rw-r--r--lib/lib.h1
-rw-r--r--toys/other/vmstat.c7
3 files changed, 11 insertions, 5 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 5ee7325c..c89aeb60 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -342,6 +342,14 @@ char *strlower(char *s)
return try;
}
+// strstr but returns pointer after match
+char *strafter(char *haystack, char *needle)
+{
+ char *s = strstr(haystack, needle);
+
+ return s ? s+strlen(needle) : s;
+}
+
// Remove trailing \n
char *chomp(char *s)
{
diff --git a/lib/lib.h b/lib/lib.h
index 5f70c8cc..235b208f 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -173,6 +173,7 @@ long atolx(char *c);
long atolx_range(char *numstr, long low, long high);
int stridx(char *haystack, char needle);
char *strlower(char *s);
+char *strafter(char *haystack, char *needle);
char *chomp(char *s);
int unescape(char c);
int strstart(char **a, char *b);
diff --git a/toys/other/vmstat.c b/toys/other/vmstat.c
index df35db12..ae856cf6 100644
--- a/toys/other/vmstat.c
+++ b/toys/other/vmstat.c
@@ -62,10 +62,7 @@ static void get_vmstat_proc(struct vmstat_proc *vmstat_proc)
xreadfile(name = vmstuff[i], toybuf, sizeof(toybuf));
continue;
- } else {
- if (!(p = strstr(toybuf, vmstuff[i]))) goto error;
- p += strlen(vmstuff[i]);
- }
+ } else if (!(p = strafter(toybuf, vmstuff[i]))) goto error;
if (1 != sscanf(p, "%"PRIu64"%n", new++, &j)) goto error;
p += j;
}
@@ -123,7 +120,7 @@ void vmstat_main(void)
if (!loop) {
char *s = toybuf;
- xreadfile("/proc/uptime", toybuf, sizeof(toybuf)-1);
+ xreadfile("/proc/uptime", toybuf, sizeof(toybuf));
while (*(s++) > ' ');
sscanf(s, "%"PRIu64, &units);
} else units = loop_delay;