diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-03-07 00:07:42 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-03-07 00:07:42 +0000 |
commit | 41cca2b4f54a2c8dadd2469747aca91d891c0b15 (patch) | |
tree | 94e1513358497d9e73b1785c67869c0aff20507b | |
parent | c115fdbc800d7573d61db98c4697ed12078e7684 (diff) | |
download | busybox-w32-41cca2b4f54a2c8dadd2469747aca91d891c0b15.tar.gz busybox-w32-41cca2b4f54a2c8dadd2469747aca91d891c0b15.tar.bz2 busybox-w32-41cca2b4f54a2c8dadd2469747aca91d891c0b15.zip |
who: stop using static buffer, small size optimizations
-rw-r--r-- | coreutils/who.c | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/coreutils/who.c b/coreutils/who.c index 25d35fad9..a5d3b02eb 100644 --- a/coreutils/who.c +++ b/coreutils/who.c | |||
@@ -21,26 +21,28 @@ | |||
21 | #include <utmp.h> | 21 | #include <utmp.h> |
22 | #include <time.h> | 22 | #include <time.h> |
23 | 23 | ||
24 | static const char * idle_string (time_t t) | 24 | static void idle_string(char *str6, time_t t) |
25 | { | 25 | { |
26 | static char str[6]; | 26 | t = time(NULL) - t; |
27 | 27 | ||
28 | time_t s = time(NULL) - t; | 28 | /*if (t < 60) { |
29 | 29 | str6[0] = '.'; | |
30 | if (s < 60) | 30 | str6[1] = '\0'; |
31 | return "."; | 31 | return; |
32 | if (s < (24 * 60 * 60)) { | 32 | }*/ |
33 | sprintf(str, "%02d:%02d", | 33 | if (t >= 0 && t < (24 * 60 * 60)) { |
34 | (int) (s / (60 * 60)), | 34 | sprintf(str6, "%02d:%02d", |
35 | (int) ((s % (60 * 60)) / 60)); | 35 | (int) (t / (60 * 60)), |
36 | return str; | 36 | (int) ((t % (60 * 60)) / 60)); |
37 | return; | ||
37 | } | 38 | } |
38 | return "old"; | 39 | strcpy(str6, "old"); |
39 | } | 40 | } |
40 | 41 | ||
41 | int who_main(int argc, char **argv); | 42 | int who_main(int argc, char **argv); |
42 | int who_main(int argc, char **argv) | 43 | int who_main(int argc, char **argv) |
43 | { | 44 | { |
45 | char str6[6]; | ||
44 | struct utmp *ut; | 46 | struct utmp *ut; |
45 | struct stat st; | 47 | struct stat st; |
46 | char *name; | 48 | char *name; |
@@ -57,12 +59,18 @@ int who_main(int argc, char **argv) | |||
57 | 59 | ||
58 | /* ut->ut_line is device name of tty - "/dev/" */ | 60 | /* ut->ut_line is device name of tty - "/dev/" */ |
59 | name = concat_path_file("/dev", ut->ut_line); | 61 | name = concat_path_file("/dev", ut->ut_line); |
60 | printf("%-10s %-8s %-8s %-12.12s %s\n", ut->ut_user, ut->ut_line, | 62 | str6[0] = '?'; |
61 | (stat(name, &st)) ? "?" : idle_string(st.st_atime), | 63 | str6[1] = '\0'; |
62 | ctime(&thyme) + 4, ut->ut_host); | 64 | if (stat(name, &st) == 0) |
63 | if (ENABLE_FEATURE_CLEAN_UP) free(name); | 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); | ||
64 | } | 71 | } |
65 | } | 72 | } |
66 | if (ENABLE_FEATURE_CLEAN_UP) endutent(); | 73 | if (ENABLE_FEATURE_CLEAN_UP) |
74 | endutent(); | ||
67 | return 0; | 75 | return 0; |
68 | } | 76 | } |