hush: rename o_quoted to has_quoted_part; small code shrink
[oweals/busybox.git] / util-linux / ipcs.c
index 489480c85b674e675abb18d7af9cd558d12ffcf2..14df652805917caf7f554cea16ff5cc10c98e8e1 100644 (file)
@@ -5,15 +5,9 @@
  * 01 Sept 2004 - Rodney Radford <rradford@mindspring.com>
  * Adapted for busybox from util-linux-2.12a.
  *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
 
-#include "busybox.h"
-#include <errno.h>
-#include <time.h>
-#include <pwd.h>
-#include <grp.h>
-
 /* X/OPEN tells us to use <sys/{types,ipc,sem}.h> for semctl() */
 /* X/OPEN tells us to use <sys/{types,ipc,msg}.h> for msgctl() */
 /* X/OPEN tells us to use <sys/{types,ipc,shm}.h> for shmctl() */
@@ -23,7 +17,7 @@
 #include <sys/msg.h>
 #include <sys/shm.h>
 
-
+#include "libbb.h"
 
 /*-------------------------------------------------------------------*/
 /* SHM_DEST and SHM_LOCKED are defined in kernel headers,
@@ -74,7 +68,7 @@ struct shm_info {
 union semun {
        int val;
        struct semid_ds *buf;
-       unsigned short int *array;
+       unsigned short *array;
        struct seminfo *__buf;
 };
 #endif
@@ -105,27 +99,23 @@ static void print_perms(int id, struct ipc_perm *ipcp)
 
        printf("%-10d %-10o", id, ipcp->mode & 0777);
 
-       if ((pw = getpwuid(ipcp->cuid)))
-               printf(" %-10s", pw->pw_name);
-       else
-               printf(" %-10d", ipcp->cuid);
-       if ((gr = getgrgid(ipcp->cgid)))
-               printf(" %-10s", gr->gr_name);
-       else
-               printf(" %-10d", ipcp->cgid);
-
-       if ((pw = getpwuid(ipcp->uid)))
-               printf(" %-10s", pw->pw_name);
-       else
-               printf(" %-10d", ipcp->uid);
-       if ((gr = getgrgid(ipcp->gid)))
-               printf(" %-10s\n", gr->gr_name);
-       else
-               printf(" %-10d\n", ipcp->gid);
+       pw = getpwuid(ipcp->cuid);
+       if (pw) printf(" %-10s", pw->pw_name);
+       else    printf(" %-10d", ipcp->cuid);
+       gr = getgrgid(ipcp->cgid);
+       if (gr) printf(" %-10s", gr->gr_name);
+       else    printf(" %-10d", ipcp->cgid);
+
+       pw = getpwuid(ipcp->uid);
+       if (pw) printf(" %-10s", pw->pw_name);
+       else    printf(" %-10d", ipcp->uid);
+       gr = getgrgid(ipcp->gid);
+       if (gr) printf(" %-10s\n", gr->gr_name);
+       else    printf(" %-10d\n", ipcp->gid);
 }
 
 
-static void do_shm(void)
+static NOINLINE void do_shm(void)
 {
        int maxid, shmid, id;
        struct shmid_ds shmseg;
@@ -252,7 +242,7 @@ static void do_shm(void)
 }
 
 
-static void do_sem(void)
+static NOINLINE void do_sem(void)
 {
        int maxid, semid, id;
        struct semid_ds semary;
@@ -358,7 +348,7 @@ static void do_sem(void)
 }
 
 
-static void do_msg(void)
+static NOINLINE void do_msg(void)
 {
        int maxid, msqid, id;
        struct msqid_ds msgque;
@@ -565,11 +555,11 @@ static void print_sem(int semid)
                }
                printf("%-10d %-10d %-10d %-10d %-10d\n", i, val, ncnt, zcnt, pid);
        }
-       puts("");
+       bb_putchar('\n');
 }
 
-int ipcs_main(int argc, char **argv);
-int ipcs_main(int argc, char **argv)
+int ipcs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int ipcs_main(int argc UNUSED_PARAM, char **argv)
 {
        int id = 0;
        unsigned flags = 0;
@@ -580,7 +570,7 @@ int ipcs_main(int argc, char **argv)
 #define flag_sem       (1<<2)
 #define flag_shm       (1<<3)
 
-       opt = getopt32(argc, argv, "i:aqsmtcplu", &opt_i);
+       opt = getopt32(argv, "i:aqsmtcplu", &opt_i);
        if (opt & 0x1) { // -i
                id = xatoi(opt_i);
                flags |= flag_print;
@@ -598,34 +588,34 @@ int ipcs_main(int argc, char **argv)
        if (flags & flag_print) {
                if (flags & flag_shm) {
                        print_shm(id);
-                       fflush_stdout_and_exit(0);
+                       fflush_stdout_and_exit(EXIT_SUCCESS);
                }
                if (flags & flag_sem) {
                        print_sem(id);
-                       fflush_stdout_and_exit(0);
+                       fflush_stdout_and_exit(EXIT_SUCCESS);
                }
                if (flags & flag_msg) {
                        print_msg(id);
-                       fflush_stdout_and_exit(0);
+                       fflush_stdout_and_exit(EXIT_SUCCESS);
                }
                bb_show_usage();
        }
 
        if (!(flags & (flag_shm | flag_msg | flag_sem)))
                flags |= flag_msg | flag_shm | flag_sem;
-       puts("");
+       bb_putchar('\n');
 
        if (flags & flag_shm) {
                do_shm();
-               puts("");
+               bb_putchar('\n');
        }
        if (flags & flag_sem) {
                do_sem();
-               puts("");
+               bb_putchar('\n');
        }
        if (flags & flag_msg) {
                do_msg();
-               puts("");
+               bb_putchar('\n');
        }
-       fflush_stdout_and_exit(0);
+       fflush_stdout_and_exit(EXIT_SUCCESS);
 }