trivial code shrink

function                                             old     new   delta
rdate_main                                           246     251      +5
show_entry                                           291     287      -4
daytime_stream                                        44      39      -5
packed_usage                                       30176   30168      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 5/-17)             Total: -12 bytes
   text	   data	    bss	    dec	    hex	filename
 929453	    932	  17684	 948069	  e7765	busybox_old
 929411	    932	  17684	 948027	  e773b	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2015-02-18 13:47:27 +01:00
parent 0cb981c5e2
commit 54e9585e10
4 changed files with 14 additions and 13 deletions

View File

@ -42,7 +42,7 @@ enum {
static void show_entry(struct utmp *ut, int state, time_t dur_secs) static void show_entry(struct utmp *ut, int state, time_t dur_secs)
{ {
unsigned days, hours, mins; unsigned days, hours, mins;
char duration[32]; char duration[sizeof("(%u+02:02)") + sizeof(int)*3];
char login_time[17]; char login_time[17];
char logout_time[8]; char logout_time[8];
const char *logout_str; const char *logout_str;
@ -53,7 +53,8 @@ static void show_entry(struct utmp *ut, int state, time_t dur_secs)
* but some systems have it wrong */ * but some systems have it wrong */
tmp = ut->ut_tv.tv_sec; tmp = ut->ut_tv.tv_sec;
safe_strncpy(login_time, ctime(&tmp), 17); safe_strncpy(login_time, ctime(&tmp), 17);
snprintf(logout_time, 8, "- %s", ctime(&dur_secs) + 11); tmp = dur_secs;
snprintf(logout_time, 8, "- %s", ctime(&tmp) + 11);
dur_secs = MAX(dur_secs - (time_t)ut->ut_tv.tv_sec, (time_t)0); dur_secs = MAX(dur_secs - (time_t)ut->ut_tv.tv_sec, (time_t)0);
/* unsigned int is easier to divide than time_t (which may be signed long) */ /* unsigned int is easier to divide than time_t (which may be signed long) */

View File

@ -1654,7 +1654,7 @@ static void FAST_FUNC daytime_stream(int s, servtab_t *sep UNUSED_PARAM)
{ {
time_t t; time_t t;
t = time(NULL); time(&t);
fdprintf(s, "%.24s\r\n", ctime(&t)); fdprintf(s, "%.24s\r\n", ctime(&t));
} }
static void FAST_FUNC daytime_dg(int s, servtab_t *sep) static void FAST_FUNC daytime_dg(int s, servtab_t *sep)

View File

@ -11,9 +11,9 @@
//usage:#define rdate_trivial_usage //usage:#define rdate_trivial_usage
//usage: "[-sp] HOST" //usage: "[-sp] HOST"
//usage:#define rdate_full_usage "\n\n" //usage:#define rdate_full_usage "\n\n"
//usage: "Get and possibly set the system date/time from a remote HOST\n" //usage: "Get and possibly set system time from a remote HOST\n"
//usage: "\n -s Set the system date/time (default)" //usage: "\n -s Set system time (default)"
//usage: "\n -p Print the date/time" //usage: "\n -p Print time"
#include "libbb.h" #include "libbb.h"
@ -36,7 +36,7 @@ static time_t askremotedate(const char *host)
fd = create_and_connect_stream_or_die(host, bb_lookup_port("time", "tcp", 37)); fd = create_and_connect_stream_or_die(host, bb_lookup_port("time", "tcp", 37));
if (safe_read(fd, &nett, 4) != 4) /* read time from server */ if (safe_read(fd, &nett, 4) != 4) /* read time from server */
bb_error_msg_and_die("%s did not send the complete time", host); bb_error_msg_and_die("%s: %s", host, "short read");
if (ENABLE_FEATURE_CLEAN_UP) if (ENABLE_FEATURE_CLEAN_UP)
close(fd); close(fd);

View File

@ -32,18 +32,18 @@
//usage: "\n -l,--local Clock is set to local time" //usage: "\n -l,--local Clock is set to local time"
//usage: "\n -u,--utc Clock is set to UTC time" //usage: "\n -u,--utc Clock is set to UTC time"
//usage: "\n -d,--device=DEV Specify the RTC device" //usage: "\n -d,--device=DEV Specify the RTC device"
//usage: "\n -m,--mode=MODE Set the sleep state (default: standby)" //usage: "\n -m,--mode=MODE Set sleep state (default: standby)"
//usage: "\n -s,--seconds=SEC Set the timeout in SEC seconds from now" //usage: "\n -s,--seconds=SEC Set timeout in SEC seconds from now"
//usage: "\n -t,--time=TIME Set the timeout to TIME seconds from epoch" //usage: "\n -t,--time=TIME Set timeout to TIME seconds from epoch"
//usage: ) //usage: )
//usage: IF_NOT_LONG_OPTS( //usage: IF_NOT_LONG_OPTS(
//usage: "\n -a Read clock mode from adjtime" //usage: "\n -a Read clock mode from adjtime"
//usage: "\n -l Clock is set to local time" //usage: "\n -l Clock is set to local time"
//usage: "\n -u Clock is set to UTC time" //usage: "\n -u Clock is set to UTC time"
//usage: "\n -d DEV Specify the RTC device" //usage: "\n -d DEV Specify the RTC device"
//usage: "\n -m MODE Set the sleep state (default: standby)" //usage: "\n -m MODE Set sleep state (default: standby)"
//usage: "\n -s SEC Set the timeout in SEC seconds from now" //usage: "\n -s SEC Set timeout in SEC seconds from now"
//usage: "\n -t TIME Set the timeout to TIME seconds from epoch" //usage: "\n -t TIME Set timeout to TIME seconds from epoch"
//usage: ) //usage: )
#include "libbb.h" #include "libbb.h"