[PATCH] who.c minor size reduction

Tito farmatito at tiscali.it
Sun Nov 11 12:29:03 UTC 2007


Hi,
this size reduces size of who.c by removing a variable.
The patch is tested and works for me.

Bloat o meter says:
scripts/bloat-o-meter busybox_old busybox_unstripped
function                                             old     new   delta
who_main                                             279     271      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-8)               Total: -8 bytes

BTW: a silly question, why we don't remove the check for USER_PROCESS  in this line:

          if (ut->ut_user[0] && ut->ut_type == USER_PROCESS) 

         so that we get the output of who -a for free and reduce
         size at the same time. Currently there is no way
         to do this. Output would be:

./busybox who
USER       TTY      IDLE      TIME            HOST
reboot     ~        ?         Nov 11 10:06:20
runlevel   ~        ?         Nov 11 10:06:20
LOGIN      tty1     03:17     Nov 11 10:06:47
tito       tty2     00:01     Nov 11 13:22:31
LOGIN      tty3     03:17     Nov 11 10:06:47
LOGIN      tty4     03:17     Nov 11 10:06:47
LOGIN      tty5     03:17     Nov 11 10:06:47
LOGIN      tty6     03:17     Nov 11 10:06:47

        Just an idea.....

Ciao,
Tito


 diff -uN coreutils/who_orig.c coreutils/who.c
--- coreutils/who_orig.c        2007-11-11 10:55:36.000000000 +0100
+++ coreutils/who.c     2007-11-11 13:18:53.000000000 +0100
@@ -55,7 +55,6 @@
        printf("USER       TTY      IDLE      TIME            HOST\n");
        while ((ut = getutent()) != NULL) {
                if (ut->ut_user[0] && ut->ut_type == USER_PROCESS) {
-                       time_t thyme = ut->ut_tv.tv_sec;

                        /* ut->ut_line is device name of tty - "/dev/" */
                        name = concat_path_file("/dev", ut->ut_line);
@@ -66,7 +65,7 @@
                        /* 15 chars for time:   Nov 10 19:33:20 */
                        printf("%-10s %-8s %-9s %-15.15s %s\n",
                                        ut->ut_user, ut->ut_line, str6,
-                                       ctime(&thyme) + 4, ut->ut_host);
+                                       ctime(&ut->ut_tv.tv_sec) + 4, ut->ut_host);
                        if (ENABLE_FEATURE_CLEAN_UP)
                                free(name);
                }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: who.patch
Type: text/x-diff
Size: 729 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/busybox/attachments/20071111/dd4e4fc2/attachment-0002.bin 


More information about the busybox mailing list