]> granicus.if.org Git - procps-ng/commitdiff
library: trade 2 strstr & atoi calls for 1 sscanf call
authorJim Warner <james.warner@comcast.net>
Sun, 22 Aug 2021 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@dropbear.xyz>
Tue, 24 Aug 2021 10:52:10 +0000 (20:52 +1000)
Signed-off-by: Jim Warner <james.warner@comcast.net>
proc/readproc.c

index fc66d0cfd3702c75809f6cf6466408fcddb73958..6c986266d40931eda702cc64fd448be5aca1f5a4 100644 (file)
@@ -1077,11 +1077,8 @@ static void autogroup_fill (const char *path, proc_t *p) {
         close(fd);
         if (in > 0) {
             buf[in] = '\0';
-            if ((str = strstr(buf, "-")))
-                p->autogrp_id = atoi(++str);
-            if ((str = strstr(buf, "nice")))
-                p->autogrp_nice = atoi(str + sizeof("nice"));
-             // above sizeof includes null, skips space ahead of #
+            sscanf(buf, "/autogroup-%d nice %d"
+                , &p->autogrp_id, &p->autogrp_nice);
         }
     }
 }