X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=coreutils%2Fdate.c;h=767e0d4a29296f9c224a1013921f4387b82bdec1;hb=68c048fb23bd8b0831bbd02ec66900b12390cf19;hp=2720a3507833682de8d058c6d4745b3fdc1aa1d1;hpb=e4070cb0d7586037c6fcf0f0f00d8d5b97f649d3;p=oweals%2Fbusybox.git diff --git a/coreutils/date.c b/coreutils/date.c index 2720a3507..767e0d4a2 100644 --- a/coreutils/date.c +++ b/coreutils/date.c @@ -7,7 +7,7 @@ * iso-format handling added by Robert Griebl * bugfixes and cleanup by Bernhard Reutner-Fischer * - * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. + * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ /* This 'date' command supports only 2 time setting formats, @@ -19,44 +19,13 @@ /* Input parsing code is always bulky - used heavy duty libc stuff as much as possible, missed out a lot of bounds checking */ -/* Default input handling to save surprising some people */ - -/* GNU coreutils 6.9 man page: - * date [OPTION]... [+FORMAT] - * date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]] - * -d, --date=STRING - * display time described by STRING, not `now' - * -f, --file=DATEFILE - * like --date once for each line of DATEFILE - * -r, --reference=FILE - * display the last modification time of FILE - * -R, --rfc-2822 - * output date and time in RFC 2822 format. - * Example: Mon, 07 Aug 2006 12:34:56 -0600 - * --rfc-3339=TIMESPEC - * output date and time in RFC 3339 format. - * TIMESPEC='date', 'seconds', or 'ns' - * Date and time components are separated by a single space: - * 2006-08-07 12:34:56-06:00 - * -s, --set=STRING - * set time described by STRING - * -u, --utc, --universal - * print or set Coordinated Universal Time - * - * Busybox: - * long options are not supported - * -f is not supported - * -I seems to roughly match --rfc-3339, but -I has _optional_ param - * (thus "-I seconds" doesn't work, only "-Iseconds"), - * and does not support -Ins - * -D FMT is a bbox extension for _input_ conversion of -d DATE - */ +//applet:IF_DATE(APPLET(date, BB_DIR_BIN, BB_SUID_DROP)) //kbuild:lib-$(CONFIG_DATE) += date.o //config:config DATE //config: bool "date" -//config: default n +//config: default y //config: help //config: date is used to set the system date or display the //config: current time in the given format. @@ -69,10 +38,12 @@ //config: Enable option (-I) to output an ISO-8601 compliant //config: date/time string. //config: +//config:# defaults to "no": stat's nanosecond field is a bit non-portable //config:config FEATURE_DATE_NANO //config: bool "Support %[num]N nanosecond format specifier" -//config: default y -//config: depends on DATE +//config: default n +//config: depends on DATE # syscall(__NR_clock_gettime) +//config: select PLATFORM_LINUX //config: help //config: Support %[num]N format specifier. Adds ~250 bytes of code. //config: @@ -92,7 +63,84 @@ //config: the same format. With it on, 'date DATE' additionally supports //config: MMDDhhmm[[YY]YY][.ss] format. +/* GNU coreutils 6.9 man page: + * date [OPTION]... [+FORMAT] + * date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]] + * -d, --date=STRING + * display time described by STRING, not `now' + * -f, --file=DATEFILE + * like --date once for each line of DATEFILE + * -r, --reference=FILE + * display the last modification time of FILE + * -R, --rfc-2822 + * output date and time in RFC 2822 format. + * Example: Mon, 07 Aug 2006 12:34:56 -0600 + * --rfc-3339=TIMESPEC + * output date and time in RFC 3339 format. + * TIMESPEC='date', 'seconds', or 'ns' + * Date and time components are separated by a single space: + * 2006-08-07 12:34:56-06:00 + * -s, --set=STRING + * set time described by STRING + * -u, --utc, --universal + * print or set Coordinated Universal Time + * + * Busybox: + * long options are not supported + * -f is not supported + * -I seems to roughly match --rfc-3339, but -I has _optional_ param + * (thus "-I seconds" doesn't work, only "-Iseconds"), + * and does not support -Ins + * -D FMT is a bbox extension for _input_ conversion of -d DATE + */ + +//usage:#define date_trivial_usage +//usage: "[OPTIONS] [+FMT] [TIME]" +//usage:#define date_full_usage "\n\n" +//usage: "Display time (using +FMT), or set time\n" +//usage: IF_NOT_LONG_OPTS( +//usage: "\n [-s] TIME Set time to TIME" +//usage: "\n -u Work in UTC (don't convert to local time)" +//usage: "\n -R Output RFC-2822 compliant date string" +//usage: ) IF_LONG_OPTS( +//usage: "\n [-s,--set] TIME Set time to TIME" +//usage: "\n -u,--utc Work in UTC (don't convert to local time)" +//usage: "\n -R,--rfc-2822 Output RFC-2822 compliant date string" +//usage: ) +//usage: IF_FEATURE_DATE_ISOFMT( +//usage: "\n -I[SPEC] Output ISO-8601 compliant date string" +//usage: "\n SPEC='date' (default) for date only," +//usage: "\n 'hours', 'minutes', or 'seconds' for date and" +//usage: "\n time to the indicated precision" +//usage: ) +//usage: IF_NOT_LONG_OPTS( +//usage: "\n -r FILE Display last modification time of FILE" +//usage: "\n -d TIME Display TIME, not 'now'" +//usage: ) IF_LONG_OPTS( +//usage: "\n -r,--reference FILE Display last modification time of FILE" +//usage: "\n -d,--date TIME Display TIME, not 'now'" +//usage: ) +//usage: IF_FEATURE_DATE_ISOFMT( +//usage: "\n -D FMT Use FMT for -d TIME conversion" +//usage: ) +//usage: "\n" +//usage: "\nRecognized TIME formats:" +//usage: "\n hh:mm[:ss]" +//usage: "\n [YYYY.]MM.DD-hh:mm[:ss]" +//usage: "\n YYYY-MM-DD hh:mm[:ss]" +//usage: "\n [[[[[YY]YY]MM]DD]hh]mm[.ss]" +//usage: IF_FEATURE_DATE_COMPAT( +//usage: "\n 'date TIME' form accepts MMDDhhmm[[YY]YY][.ss] instead" +//usage: ) +//usage: +//usage:#define date_example_usage +//usage: "$ date\n" +//usage: "Wed Apr 12 18:52:41 MDT 2000\n" + #include "libbb.h" +#if ENABLE_FEATURE_DATE_NANO +# include +#endif enum { OPT_RFC2822 = (1 << 0), /* R */ @@ -204,13 +252,19 @@ int date_main(int argc UNUSED_PARAM, char **argv) xstat(filename, &statbuf); ts.tv_sec = statbuf.st_mtime; #if ENABLE_FEATURE_DATE_NANO - ts.tv_nsec = statbuf.st_mtimensec; //or st_atim.tv_nsec? + ts.tv_nsec = statbuf.st_mtim.tv_nsec; + /* Some toolchains use .st_mtimensec instead of st_mtim.tv_nsec. + * If you need #define _SVID_SOURCE 1 to enable st_mtim.tv_nsec, + * drop a mail to project mailing list please + */ #endif } else { #if ENABLE_FEATURE_DATE_NANO - clock_gettime(CLOCK_REALTIME, &ts); + /* libc has incredibly messy way of doing this, + * typically requiring -lrt. We just skip all this mess */ + syscall(__NR_clock_gettime, CLOCK_REALTIME, &ts); #else - time(&ts.tv_nsec); + time(&ts.tv_sec); #endif } localtime_r(&ts.tv_sec, &tm_time); @@ -231,7 +285,9 @@ int date_main(int argc UNUSED_PARAM, char **argv) } /* Correct any day of week and day of year etc. fields */ - tm_time.tm_isdst = -1; /* Be sure to recheck dst */ + /* Be sure to recheck dst (but not if date is time_t format) */ + if (date_str[0] != '@') + tm_time.tm_isdst = -1; ts.tv_sec = validate_tm_time(date_str, &tm_time); maybe_set_utc(opt); @@ -295,7 +351,7 @@ int date_main(int argc UNUSED_PARAM, char **argv) scale = 1; pres = 9; if (n) { - pres = xatoi_u(p); + pres = xatoi_positive(p); if (pres == 0) pres = 9; m = 9 - pres;