Changeset 1765 in MondoRescue for branches/2.2.5/mindi-busybox/coreutils/who.c


Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (16 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.5/mindi-busybox/coreutils/who.c

    r821 r1765  
    1212 *
    1313 * Copyright (c) 2002 AYR Networks, Inc.
     14 *
     15 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
     16 *
    1417 *----------------------------------------------------------------------
    1518 */
    1619
    17 #include "busybox.h"
     20#include "libbb.h"
    1821#include <utmp.h>
    1922#include <time.h>
    2023
    21 static const char * idle_string (time_t t)
     24static void idle_string(char *str6, time_t t)
    2225{
    23     static char str[6];
    24    
    25     time_t s = time(NULL) - t;
     26    t = time(NULL) - t;
    2627
    27     if (s < 60)
    28         return ".";
    29     if (s < (24 * 60 * 60)) {
    30         sprintf (str, "%02d:%02d",
    31                 (int) (s / (60 * 60)),
    32                 (int) ((s % (60 * 60)) / 60));
    33         return str;
     28    /*if (t < 60) {
     29        str6[0] = '.';
     30        str6[1] = '\0';
     31        return;
     32    }*/
     33    if (t >= 0 && t < (24 * 60 * 60)) {
     34        sprintf(str6, "%02d:%02d",
     35                (int) (t / (60 * 60)),
     36                (int) ((t % (60 * 60)) / 60));
     37        return;
    3438    }
    35     return "old";
     39    strcpy(str6, "old");
    3640}
    3741
     42int who_main(int argc, char **argv);
    3843int who_main(int argc, char **argv)
    3944{
     45    char str6[6];
    4046    struct utmp *ut;
    4147    struct stat st;
    4248    char *name;
    43    
     49
    4450    if (argc > 1) {
    4551        bb_show_usage();
    4652    }
    47    
     53
    4854    setutent();
    4955    printf("USER       TTY      IDLE      TIME           HOST\n");
     
    5460            /* ut->ut_line is device name of tty - "/dev/" */
    5561            name = concat_path_file("/dev", ut->ut_line);
    56             printf("%-10s %-8s %-8s  %-12.12s   %s\n", ut->ut_user, ut->ut_line,
    57                                     (stat(name, &st)) ?  "?" : idle_string(st.st_atime),
    58                                     ctime(&thyme) + 4, ut->ut_host);
    59             if (ENABLE_FEATURE_CLEAN_UP) free(name);
     62            str6[0] = '?';
     63            str6[1] = '\0';
     64            if (stat(name, &st) == 0)
     65                idle_string(str6, st.st_atime);
     66            printf("%-10s %-8s %-9s %-14.14s %s\n",
     67                    ut->ut_user, ut->ut_line, str6,
     68                    ctime(&thyme) + 4, ut->ut_host);
     69            if (ENABLE_FEATURE_CLEAN_UP)
     70                free(name);
    6071        }
    6172    }
    62     if (ENABLE_FEATURE_CLEAN_UP) endutent();
     73    if (ENABLE_FEATURE_CLEAN_UP)
     74        endutent();
    6375    return 0;
    6476}
Note: See TracChangeset for help on using the changeset viewer.