hush: optional times builtin
function old new delta builtin_times - 108 +108 bltins1 360 372 +12 static.times_tbl - 9 +9 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 1/0 up/down: 129/0) Total: 129 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
c52dc0e836
commit
11f2e99c13
16
shell/ash.c
16
shell/ash.c
@ -13351,21 +13351,23 @@ static const unsigned char timescmd_str[] ALIGN1 = {
|
|||||||
static int FAST_FUNC
|
static int FAST_FUNC
|
||||||
timescmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
timescmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
||||||
{
|
{
|
||||||
unsigned long clk_tck, s, t;
|
unsigned clk_tck;
|
||||||
const unsigned char *p;
|
const unsigned char *p;
|
||||||
struct tms buf;
|
struct tms buf;
|
||||||
|
|
||||||
clk_tck = bb_clk_tck();
|
clk_tck = bb_clk_tck();
|
||||||
times(&buf);
|
|
||||||
|
|
||||||
|
times(&buf);
|
||||||
p = timescmd_str;
|
p = timescmd_str;
|
||||||
do {
|
do {
|
||||||
|
unsigned sec, frac;
|
||||||
|
unsigned long t;
|
||||||
t = *(clock_t *)(((char *) &buf) + p[1]);
|
t = *(clock_t *)(((char *) &buf) + p[1]);
|
||||||
s = t / clk_tck;
|
sec = t / clk_tck;
|
||||||
t = t % clk_tck;
|
frac = t % clk_tck;
|
||||||
out1fmt("%lum%lu.%03lus%c",
|
out1fmt("%um%u.%03us%c",
|
||||||
s / 60, s % 60,
|
sec / 60, sec % 60,
|
||||||
(t * 1000) / clk_tck,
|
(frac * 1000) / clk_tck,
|
||||||
p[0]);
|
p[0]);
|
||||||
p += 2;
|
p += 2;
|
||||||
} while (*p);
|
} while (*p);
|
||||||
|
50
shell/hush.c
50
shell/hush.c
@ -48,7 +48,7 @@
|
|||||||
* tilde expansion
|
* tilde expansion
|
||||||
* aliases
|
* aliases
|
||||||
* builtins mandated by standards we don't support:
|
* builtins mandated by standards we don't support:
|
||||||
* [un]alias, command, fc, getopts, times:
|
* [un]alias, command, fc, getopts:
|
||||||
* command -v CMD: print "/path/to/CMD"
|
* command -v CMD: print "/path/to/CMD"
|
||||||
* prints "CMD" for builtins
|
* prints "CMD" for builtins
|
||||||
* prints "alias ALIAS='EXPANSION'" for aliases
|
* prints "alias ALIAS='EXPANSION'" for aliases
|
||||||
@ -59,7 +59,6 @@
|
|||||||
* -p: use default $PATH
|
* -p: use default $PATH
|
||||||
* command BLTIN: disables special-ness (e.g. errors do not abort)
|
* command BLTIN: disables special-ness (e.g. errors do not abort)
|
||||||
* getopts: getopt() for shells
|
* getopts: getopt() for shells
|
||||||
* times: print getrusage(SELF/CHILDREN).ru_utime/ru_stime
|
|
||||||
* fc -l[nr] [BEG] [END]: list range of commands in history
|
* fc -l[nr] [BEG] [END]: list range of commands in history
|
||||||
* fc [-e EDITOR] [BEG] [END]: edit/rerun range of commands
|
* fc [-e EDITOR] [BEG] [END]: edit/rerun range of commands
|
||||||
* fc -s [PAT=REP] [CMD]: rerun CMD, replacing PAT with REP
|
* fc -s [PAT=REP] [CMD]: rerun CMD, replacing PAT with REP
|
||||||
@ -265,6 +264,11 @@
|
|||||||
//config: default y
|
//config: default y
|
||||||
//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
|
//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
|
||||||
//config:
|
//config:
|
||||||
|
//config:config HUSH_TIMES
|
||||||
|
//config: bool "times builtin"
|
||||||
|
//config: default y
|
||||||
|
//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
|
||||||
|
//config:
|
||||||
//config:config HUSH_READ
|
//config:config HUSH_READ
|
||||||
//config: bool "read builtin"
|
//config: bool "read builtin"
|
||||||
//config: default y
|
//config: default y
|
||||||
@ -325,6 +329,7 @@
|
|||||||
#if ENABLE_HUSH_CASE
|
#if ENABLE_HUSH_CASE
|
||||||
# include <fnmatch.h>
|
# include <fnmatch.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <sys/times.h>
|
||||||
#include <sys/utsname.h> /* for setting $HOSTNAME */
|
#include <sys/utsname.h> /* for setting $HOSTNAME */
|
||||||
|
|
||||||
#include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */
|
#include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */
|
||||||
@ -1011,6 +1016,9 @@ static int builtin_trap(char **argv) FAST_FUNC;
|
|||||||
#if ENABLE_HUSH_TYPE
|
#if ENABLE_HUSH_TYPE
|
||||||
static int builtin_type(char **argv) FAST_FUNC;
|
static int builtin_type(char **argv) FAST_FUNC;
|
||||||
#endif
|
#endif
|
||||||
|
#if ENABLE_HUSH_TIMES
|
||||||
|
static int builtin_times(char **argv) FAST_FUNC;
|
||||||
|
#endif
|
||||||
static int builtin_true(char **argv) FAST_FUNC;
|
static int builtin_true(char **argv) FAST_FUNC;
|
||||||
#if ENABLE_HUSH_UMASK
|
#if ENABLE_HUSH_UMASK
|
||||||
static int builtin_umask(char **argv) FAST_FUNC;
|
static int builtin_umask(char **argv) FAST_FUNC;
|
||||||
@ -1105,6 +1113,9 @@ static const struct built_in_command bltins1[] = {
|
|||||||
#if BASH_SOURCE
|
#if BASH_SOURCE
|
||||||
BLTIN("source" , builtin_source , NULL),
|
BLTIN("source" , builtin_source , NULL),
|
||||||
#endif
|
#endif
|
||||||
|
#if ENABLE_HUSH_TIMES
|
||||||
|
BLTIN("times" , builtin_times , NULL),
|
||||||
|
#endif
|
||||||
#if ENABLE_HUSH_TRAP
|
#if ENABLE_HUSH_TRAP
|
||||||
BLTIN("trap" , builtin_trap , "Trap signals"),
|
BLTIN("trap" , builtin_trap , "Trap signals"),
|
||||||
#endif
|
#endif
|
||||||
@ -10407,6 +10418,41 @@ static int FAST_FUNC builtin_return(char **argv)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ENABLE_HUSH_TIMES
|
||||||
|
static int FAST_FUNC builtin_times(char **argv UNUSED_PARAM)
|
||||||
|
{
|
||||||
|
static const uint8_t times_tbl[] ALIGN1 = {
|
||||||
|
' ', offsetof(struct tms, tms_utime),
|
||||||
|
'\n', offsetof(struct tms, tms_stime),
|
||||||
|
' ', offsetof(struct tms, tms_cutime),
|
||||||
|
'\n', offsetof(struct tms, tms_cstime),
|
||||||
|
0
|
||||||
|
};
|
||||||
|
const uint8_t *p;
|
||||||
|
unsigned clk_tck;
|
||||||
|
struct tms buf;
|
||||||
|
|
||||||
|
clk_tck = bb_clk_tck();
|
||||||
|
|
||||||
|
times(&buf);
|
||||||
|
p = times_tbl;
|
||||||
|
do {
|
||||||
|
unsigned sec, frac;
|
||||||
|
unsigned long t;
|
||||||
|
t = *(clock_t *)(((char *) &buf) + p[1]);
|
||||||
|
sec = t / clk_tck;
|
||||||
|
frac = t % clk_tck;
|
||||||
|
printf("%um%u.%03us%c",
|
||||||
|
sec / 60, sec % 60,
|
||||||
|
(frac * 1000) / clk_tck,
|
||||||
|
p[0]);
|
||||||
|
p += 2;
|
||||||
|
} while (*p);
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if ENABLE_HUSH_MEMLEAK
|
#if ENABLE_HUSH_MEMLEAK
|
||||||
static int FAST_FUNC builtin_memleak(char **argv UNUSED_PARAM)
|
static int FAST_FUNC builtin_memleak(char **argv UNUSED_PARAM)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user