diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-17 19:09:05 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-17 19:09:05 +0000 |
commit | 459be35234cc24b69309eb0ee22600024c73713e (patch) | |
tree | 15ac4122d9c42ec75ba68d342827e37fcb1306ed /util-linux/hwclock.c | |
parent | e79dd06782175d50f639180cde5b2c56933aa2ee (diff) | |
download | busybox-w32-459be35234cc24b69309eb0ee22600024c73713e.tar.gz busybox-w32-459be35234cc24b69309eb0ee22600024c73713e.tar.bz2 busybox-w32-459be35234cc24b69309eb0ee22600024c73713e.zip |
hwclock: size optimizations
libbb/time.c: new file, introducing monotonic_us()
pscan, traceroute, arping: use it instead of gettimeofday
ping, zcip: TODO
function old new delta
monotonic_us - 89 +89
find_pair 164 180 +16
.rodata 129747 129763 +16
refresh 1144 1152 +8
............
timeout 8 4 -4
static.start 8 4 -4
last 8 4 -4
parse_conf 1303 1284 -19
time_main 1149 1124 -25
gettimeofday_us 39 - -39
arping_main 2042 1969 -73
hwclock_main 594 501 -93
catcher 485 380 -105
traceroute_main 4300 4117 -183
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 8/11 up/down: 157/-562) Total: -405 bytes
Diffstat (limited to 'util-linux/hwclock.c')
-rw-r--r-- | util-linux/hwclock.c | 60 |
1 files changed, 27 insertions, 33 deletions
diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c index c4b793ef8..204a103c3 100644 --- a/util-linux/hwclock.c +++ b/util-linux/hwclock.c | |||
@@ -7,7 +7,6 @@ | |||
7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | //#include <sys/ioctl.h> | ||
11 | #include <sys/utsname.h> | 10 | #include <sys/utsname.h> |
12 | #include <getopt.h> | 11 | #include <getopt.h> |
13 | #include "libbb.h" | 12 | #include "libbb.h" |
@@ -98,49 +97,42 @@ static void write_rtc(time_t t, int utc) | |||
98 | close(rtc); | 97 | close(rtc); |
99 | } | 98 | } |
100 | 99 | ||
101 | static int show_clock(int utc) | 100 | static void show_clock(int utc) |
102 | { | 101 | { |
103 | struct tm *ptm; | 102 | //struct tm *ptm; |
104 | time_t t; | 103 | time_t t; |
105 | RESERVE_CONFIG_BUFFER(buffer, 64); | 104 | char *cp; |
106 | 105 | ||
107 | t = read_rtc(utc); | 106 | t = read_rtc(utc); |
108 | ptm = localtime(&t); /* Sets 'tzname[]' */ | 107 | //ptm = localtime(&t); /* Sets 'tzname[]' */ |
109 | 108 | ||
110 | safe_strncpy(buffer, ctime(&t), 64); | 109 | cp = ctime(&t); |
111 | if (buffer[0]) | 110 | if (cp[0]) |
112 | buffer[strlen(buffer) - 1] = 0; | 111 | cp[strlen(cp) - 1] = '\0'; |
113 | 112 | ||
114 | //printf("%s %.6f seconds %s\n", buffer, 0.0, utc ? "" : (ptm->tm_isdst ? tzname[1] : tzname[0])); | 113 | //printf("%s %.6f seconds %s\n", cp, 0.0, utc ? "" : (ptm->tm_isdst ? tzname[1] : tzname[0])); |
115 | printf( "%s %.6f seconds\n", buffer, 0.0); | 114 | printf("%s 0.000000 seconds\n", cp); |
116 | RELEASE_CONFIG_BUFFER(buffer); | ||
117 | |||
118 | return 0; | ||
119 | } | 115 | } |
120 | 116 | ||
121 | static int to_sys_clock(int utc) | 117 | static void to_sys_clock(int utc) |
122 | { | 118 | { |
123 | struct timeval tv = { 0, 0 }; | 119 | struct timeval tv; |
124 | const struct timezone tz = { timezone/60 - 60*daylight, 0 }; | 120 | const struct timezone tz = { timezone/60 - 60*daylight, 0 }; |
125 | 121 | ||
126 | tv.tv_sec = read_rtc(utc); | 122 | tv.tv_sec = read_rtc(utc); |
127 | 123 | tv.tv_usec = 0; | |
128 | if (settimeofday(&tv, &tz)) | 124 | if (settimeofday(&tv, &tz)) |
129 | bb_perror_msg_and_die("settimeofday() failed"); | 125 | bb_perror_msg_and_die("settimeofday() failed"); |
130 | |||
131 | return 0; | ||
132 | } | 126 | } |
133 | 127 | ||
134 | static int from_sys_clock(int utc) | 128 | static void from_sys_clock(int utc) |
135 | { | 129 | { |
136 | struct timeval tv = { 0, 0 }; | 130 | struct timeval tv; |
137 | struct timezone tz = { 0, 0 }; | ||
138 | |||
139 | if (gettimeofday(&tv, &tz)) | ||
140 | bb_perror_msg_and_die("gettimeofday() failed"); | ||
141 | 131 | ||
132 | gettimeofday(&tv, NULL); | ||
133 | //if (gettimeofday(&tv, NULL)) | ||
134 | // bb_perror_msg_and_die("gettimeofday() failed"); | ||
142 | write_rtc(tv.tv_sec, utc); | 135 | write_rtc(tv.tv_sec, utc); |
143 | return 0; | ||
144 | } | 136 | } |
145 | 137 | ||
146 | #ifdef CONFIG_FEATURE_HWCLOCK_ADJTIME_FHS | 138 | #ifdef CONFIG_FEATURE_HWCLOCK_ADJTIME_FHS |
@@ -182,8 +174,8 @@ static int check_utc(void) | |||
182 | #define HWCLOCK_OPT_SYSTOHC 0x10 | 174 | #define HWCLOCK_OPT_SYSTOHC 0x10 |
183 | #define HWCLOCK_OPT_RTCFILE 0x20 | 175 | #define HWCLOCK_OPT_RTCFILE 0x20 |
184 | 176 | ||
185 | int hwclock_main(int argc, char **argv ); | 177 | int hwclock_main(int argc, char **argv); |
186 | int hwclock_main(int argc, char **argv ) | 178 | int hwclock_main(int argc, char **argv) |
187 | { | 179 | { |
188 | unsigned opt; | 180 | unsigned opt; |
189 | int utc; | 181 | int utc; |
@@ -210,12 +202,14 @@ int hwclock_main(int argc, char **argv ) | |||
210 | utc = check_utc(); | 202 | utc = check_utc(); |
211 | 203 | ||
212 | if (opt & HWCLOCK_OPT_HCTOSYS) { | 204 | if (opt & HWCLOCK_OPT_HCTOSYS) { |
213 | return to_sys_clock(utc); | 205 | to_sys_clock(utc); |
206 | return 0; | ||
214 | } | 207 | } |
215 | else if (opt & HWCLOCK_OPT_SYSTOHC) { | 208 | if (opt & HWCLOCK_OPT_SYSTOHC) { |
216 | return from_sys_clock(utc); | 209 | from_sys_clock(utc); |
217 | } else { | 210 | return 0; |
218 | /* default HWCLOCK_OPT_SHOW */ | ||
219 | return show_clock(utc); | ||
220 | } | 211 | } |
212 | /* default HWCLOCK_OPT_SHOW */ | ||
213 | show_clock(utc); | ||
214 | return 0; | ||
221 | } | 215 | } |