Print this page
2849 uptime should use locale settings for current time

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/whodo/whodo.c
          +++ new/usr/src/cmd/whodo/whodo.c
↓ open down ↓ 127 lines elided ↑ open up ↑
 128  128  
 129  129  static struct   uproc   *findhash(pid_t);
 130  130  static time_t   findidle(char *);
 131  131  static void     clnarglist(char *);
 132  132  static void     showproc(struct uproc *);
 133  133  static void     showtotals(struct uproc *);
 134  134  static void     calctotals(struct uproc *);
 135  135  static char     *getty(dev_t);
 136  136  static void     prttime(time_t, char *);
 137  137  static void     prtat(time_t *);
 138      -static void     checkampm(char *);
 139  138  
 140  139  static char     *prog;
 141  140  static int      header = 1;     /* true if -h flag: don't print heading */
 142  141  static int      lflag = 0;      /* true if -l flag: w command format */
 143  142  static char     *sel_user;      /* login of particular user selected */
 144  143  static time_t   now;            /* current time of day */
 145  144  static time_t   uptime;         /* time of last reboot & elapsed time since */
 146  145  static int      nusers;         /* number of users logged in now */
 147  146  static time_t   idle;           /* number of minutes user is idle */
 148  147  static time_t   jobtime;        /* total cpu time visible */
↓ open down ↓ 135 lines elided ↑ open up ↑
 284  283                              "  %d user(s)\n", LC_TIME), nusers);
 285  284                          (void) printf(dcgettext(NULL, "User     tty           "
 286  285                              "login@  idle   JCPU   PCPU  what\n", LC_TIME));
 287  286                  } else {        /* standard whodo header */
 288  287                          char date_buf[100];
 289  288  
 290  289                          /*
 291  290                           * print current time and date
 292  291                           */
 293  292                          (void) strftime(date_buf, sizeof (date_buf),
 294      -                            dcgettext(NULL, "%C", LC_TIME), localtime(&now));
      293 +                            "%+", localtime(&now));
 295  294                          (void) printf("%s\n", date_buf);
 296  295  
 297  296                          /*
 298  297                           * print system name
 299  298                           */
 300  299                          (void) uname(&uts);
 301  300                          (void) printf("%s\n", uts.nodename);
 302  301                  }
 303  302          }
 304  303  
↓ open down ↓ 456 lines elided ↑ open up ↑
 761  760   */
 762  761  static void
 763  762  prtat(time_t *time)
 764  763  {
 765  764          struct tm *p;
 766  765  
 767  766          p = localtime(time);
 768  767          if (now - *time <= 18 * HR) {
 769  768                  char timestr[50];
 770  769                  (void) strftime(timestr, sizeof (timestr),
 771      -                    dcgettext(NULL, " %l:%M""%p", LC_TIME), p);
 772      -                checkampm(timestr);
      770 +                    " %R  ", p);
 773  771                  (void) printf("%s", timestr);
 774  772          } else if (now - *time <= 7 * DAY) {
 775  773                  char weekdaytime[20];
 776  774  
 777  775                  (void) strftime(weekdaytime, sizeof (weekdaytime),
 778      -                    dcgettext(NULL, "%a%l%p", LC_TIME), p);
 779      -                checkampm(weekdaytime);
      776 +                    "%a%H  ", p);
 780  777                  (void) printf(" %s", weekdaytime);
 781  778          } else {
 782  779                  char monthtime[20];
 783  780  
 784  781                  (void) strftime(monthtime, sizeof (monthtime),
 785      -                    dcgettext(NULL, "%e%b%y", LC_TIME), p);
      782 +                    "%e%b%y", p);
 786  783                  (void) printf(" %s", monthtime);
 787  784          }
 788  785  }
 789  786  
 790  787  /*
 791  788   * find & return number of minutes current tty has been idle
 792  789   */
 793  790  static time_t
 794  791  findidle(char *devname)
 795  792  {
↓ open down ↓ 27 lines elided ↑ open up ↑
 823  820          for (c = arglist; *c == NULL; c++) {
 824  821                  if ((*c < ' ') || (*c > 0176)) {
 825  822                          if (err++ > 5) {
 826  823                                  *arglist = NULL;
 827  824                                  break;
 828  825                          }
 829  826                          *c = '?';
 830  827                  }
 831  828          }
 832  829  }
 833      -
 834      -/* replaces all occurences of AM/PM with am/pm */
 835      -static void
 836      -checkampm(char *str)
 837      -{
 838      -        char *ampm;
 839      -        while ((ampm = strstr(str, "AM")) != NULL ||
 840      -            (ampm = strstr(str, "PM")) != NULL) {
 841      -                *ampm = tolower(*ampm);
 842      -                *(ampm+1) = tolower(*(ampm+1));
 843      -        }
 844      -}
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX