aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2012-12-09 13:57:04 -0600
committerRob Landley <rob@landley.net>2012-12-09 13:57:04 -0600
commitd52e76d50879542702b89cc8cc873358232d2e3f (patch)
tree3ec9ca70a9b63c0e9423aeab1e119ef355fe4d87 /toys
parent7c6209d6c336df74984e62aa88679c06641ae309 (diff)
downloadtoybox-d52e76d50879542702b89cc8cc873358232d2e3f.tar.gz
Meddle.
The <1 has to come first in the option string, normalize whitespace, sprintf of %d maxes out at -2 billion ala 12 bytes with null terminator so we don't need a length check in a 4k buffer, use the "%*s" feature of printf to prepend whitespace for us, take advantage of c99 defining ! to return 0 or 1.
Diffstat (limited to 'toys')
-rw-r--r--toys/lsb/pidof.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/toys/lsb/pidof.c b/toys/lsb/pidof.c
index 8aeb33e4..533e922a 100644
--- a/toys/lsb/pidof.c
+++ b/toys/lsb/pidof.c
@@ -5,7 +5,7 @@
*
* http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/pidof.html
-USE_PIDOF(NEWTOY(pidof, "so:<1", TOYFLAG_USR|TOYFLAG_BIN))
+USE_PIDOF(NEWTOY(pidof, "<1so:", TOYFLAG_USR|TOYFLAG_BIN))
config PIDOF
bool "pidof"
@@ -27,28 +27,23 @@ GLOBALS(
static int print_pid(pid_t pid)
{
+ char * res;
+ int len;
+ sprintf(toybuf, "%d", pid);
+ len = strlen(toybuf);
+
+ // Check omit string
if (toys.optflags & FLAG_o)
{
- char * res;
- int len;
- snprintf(toybuf, sizeof(toybuf), "%d", pid);
- len = strlen(toybuf);
- res = strstr(TT.omit, toybuf);
- if (res &&
- (res == TT.omit || res[-1] == ',') &&
- (res[len] == ',' || res[len] == 0))
- // Found in omit string
- return 1;
+ res = strstr(TT.omit, toybuf);
+ if (res && (res == TT.omit || res[-1] == ',') &&
+ (res[len] == ',' || res[len] == 0)) return 1;
}
-
- xprintf("%s%ld", toys.exitval ? "" : " ", (long)pid);
+ xprintf("%*s", len+(!toys.exitval), toybuf);
toys.exitval = 0;
- if (toys.optflags & FLAG_s)
- return 0;
-
- return 1;
+ return !(toys.optflags & FLAG_s);
}
void pidof_main(void)