[hackers] [ubase] Use SLIST instead of TAILQ for pidof(8) || sin

From: <git_AT_suckless.org>
Date: Wed, 7 Oct 2015 14:57:29 +0200 (CEST)

commit a8f95b2f9a8e85193b8ebd53a7e4aeae12e02480
Author: sin <sin_AT_2f30.org>
AuthorDate: Wed Oct 7 14:53:41 2015 +0200
Commit: sin <sin_AT_2f30.org>
CommitDate: Wed Oct 7 13:57:24 2015 +0100

    Use SLIST instead of TAILQ for pidof(8)

diff --git a/pidof.c b/pidof.c
index 1df0a54..c98bf92 100644
--- a/pidof.c
+++ b/pidof.c
_AT_@ -15,10 +15,10 @@
 
 struct pidentry {
         pid_t pid;
- TAILQ_ENTRY(pidentry) entry;
+ SLIST_ENTRY(pidentry) entry;
 };
 
-static TAILQ_HEAD(omitpid_head, pidentry) omitpid_head;
+static SLIST_HEAD(, pidentry) omitpid_head;
 
 static void
 usage(void)
_AT_@ -36,7 +36,7 @@ main(int argc, char *argv[])
         char cmdline[BUFSIZ], *cmd, *cmdbase = NULL, *p, *arg = NULL;
         int i, found = 0;
         int sflag = 0, oflag = 0;
- struct pidentry *pe, *tmp;
+ struct pidentry *pe;
 
         ARGBEGIN {
         case 's':
_AT_@ -53,7 +53,7 @@ main(int argc, char *argv[])
         if (!argc)
                 return 1;
 
- TAILQ_INIT(&omitpid_head);
+ SLIST_INIT(&omitpid_head);
 
         for (p = strtok(arg, ","); p; p = strtok(NULL, ",")) {
                 pe = emalloc(sizeof(*pe));
_AT_@ -61,7 +61,7 @@ main(int argc, char *argv[])
                         pe->pid = getppid();
                 else
                         pe->pid = estrtol(p, 10);
- TAILQ_INSERT_TAIL(&omitpid_head, pe, entry);
+ SLIST_INSERT_HEAD(&omitpid_head, pe, entry);
         }
 
         if (!(dp = opendir("/proc")))
_AT_@ -72,7 +72,7 @@ main(int argc, char *argv[])
                         continue;
                 pid = estrtol(entry->d_name, 10);
                 if (oflag) {
- TAILQ_FOREACH(pe, &omitpid_head, entry)
+ SLIST_FOREACH(pe, &omitpid_head, entry)
                                 if (pe->pid == pid)
                                         break;
                         if (pe)
_AT_@ -110,11 +110,5 @@ out:
 
         closedir(dp);
 
- for (pe = TAILQ_FIRST(&omitpid_head); pe; pe = tmp) {
- tmp = TAILQ_NEXT(pe, entry);
- TAILQ_REMOVE(&omitpid_head, pe, entry);
- free(pe);
- }
-
         return 0;
 }
Received on Wed Oct 07 2015 - 14:57:29 CEST

This archive was generated by hypermail 2.3.0 : Wed Oct 07 2015 - 15:00:15 CEST