[Midnightbsd-cvs] src [7250] trunk/bin/date: make date(1) behave like GNU date when the -r option cant be interpreted as a number.
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Fri Aug 14 17:44:00 EDT 2015
Revision: 7250
http://svnweb.midnightbsd.org/src/?rev=7250
Author: laffer1
Date: 2015-08-14 17:43:59 -0400 (Fri, 14 Aug 2015)
Log Message:
-----------
make date(1) behave like GNU date when the -r option cant be interpreted as a number.
Modified Paths:
--------------
trunk/bin/date/Makefile
trunk/bin/date/date.1
trunk/bin/date/date.c
trunk/bin/date/extern.h
trunk/bin/date/netdate.c
Modified: trunk/bin/date/Makefile
===================================================================
--- trunk/bin/date/Makefile 2015-08-14 14:56:56 UTC (rev 7249)
+++ trunk/bin/date/Makefile 2015-08-14 21:43:59 UTC (rev 7250)
@@ -1,7 +1,9 @@
# @(#)Makefile 8.1 (Berkeley) 5/31/93
-# $FreeBSD: src/bin/date/Makefile,v 1.11 2003/06/13 07:04:01 markm Exp $
-# $MidnightBSD: src/bin/date/Makefile,v 1.2 2006/07/07 13:54:43 laffer1 Exp $
+# $FreeBSD: stable/10/bin/date/Makefile 262951 2014-03-09 17:04:31Z jmmv $
+# $MidnightBSD$
+.include <bsd.own.mk>
+
PROG= date
SRCS= date.c netdate.c vary.c
Modified: trunk/bin/date/date.1
===================================================================
--- trunk/bin/date/date.1 2015-08-14 14:56:56 UTC (rev 7249)
+++ trunk/bin/date/date.1 2015-08-14 21:43:59 UTC (rev 7250)
@@ -33,7 +33,7 @@
.\" $FreeBSD: src/bin/date/date.1,v 1.72 2005/02/13 22:25:09 ru Exp $
.\" $MidnightBSD: src/bin/date/date.1,v 1.3 2008/06/30 02:45:42 laffer1 Exp $
.\"
-.Dd June 3, 2010
+.Dd May 7, 2015
.Dt DATE 1
.Os
.Sh NAME
@@ -41,8 +41,8 @@
.Nd display or set date and time
.Sh SYNOPSIS
.Nm
-.Op Fl ju
-.Op Fl r Ar seconds
+.Op Fl jRu
+.Op Fl r Ar seconds | Ar filename
.Oo
.Fl v
.Sm off
@@ -59,7 +59,7 @@
.Ar MM Op Ar .ss
.Sm on
.Nm
-.Op Fl jnu
+.Op Fl jnRu
.Fl f Ar input_fmt new_date
.Op Cm + Ns Ar output_fmt
.Nm
@@ -131,6 +131,16 @@
.Fl n
option suppresses this behavior and causes the time to be set only on the
current machine.
+.It Fl R
+Use RFC 2822 date and time output format. This is equivalent to use
+.Dq Li %a, %d %b %Y \&%T %z
+as
+.Ar output_fmt
+while
+.Ev LC_TIME
+is set to the
+.Dq C
+locale .
.It Fl r Ar seconds
Print the date and time represented by
.Ar seconds ,
@@ -141,6 +151,9 @@
see
.Xr time 3 ) ,
and can be specified in decimal, octal, or hex.
+.It Fl r Ar filename
+Print the date and time of the last modification of
+.Ar filename .
.It Fl t Ar minutes_west
Set the system's value for minutes west of
.Tn GMT .
Modified: trunk/bin/date/date.c
===================================================================
--- trunk/bin/date/date.c 2015-08-14 14:56:56 UTC (rev 7249)
+++ trunk/bin/date/date.c 2015-08-14 21:43:59 UTC (rev 7250)
@@ -41,10 +41,11 @@
#endif
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD: src/bin/date/date.c,v 1.3 2008/06/30 02:45:42 laffer1 Exp $");
+__MBSDID("$MidnightBSD$");
#include <sys/param.h>
#include <sys/time.h>
+#include <sys/stat.h>
#include <ctype.h>
#include <err.h>
@@ -70,12 +71,14 @@
static void badformat(void);
static void usage(void);
+static const char *rfc2822_format = "%a, %d %b %Y %T %z";
+
int
main(int argc, char *argv[])
{
struct timezone tz;
int ch, rflag;
- int jflag, nflag;
+ int jflag, nflag, Rflag;
const char *format;
char buf[1024];
char *endptr, *fmt;
@@ -84,6 +87,7 @@
struct vary *v;
const struct vary *badv;
struct tm lt;
+ struct stat sb;
v = NULL;
fmt = NULL;
@@ -90,9 +94,9 @@
(void) setlocale(LC_TIME, "");
tz.tz_dsttime = tz.tz_minuteswest = 0;
rflag = 0;
- jflag = nflag = 0;
+ jflag = nflag = Rflag = 0;
set_timezone = 0;
- while ((ch = getopt(argc, argv, "d:f:jnr:t:uv:")) != -1)
+ while ((ch = getopt(argc, argv, "d:f:jnRr:t:uv:")) != -1)
switch((char)ch) {
case 'd': /* daylight savings time */
tz.tz_dsttime = strtol(optarg, &endptr, 10) ? 1 : 0;
@@ -109,11 +113,18 @@
case 'n': /* don't set network */
nflag = 1;
break;
+ case 'R': /* RFC 2822 datetime format */
+ Rflag = 1;
+ break;
case 'r': /* user specified seconds */
rflag = 1;
tval = strtoq(optarg, &tmp, 0);
- if (*tmp != 0)
- usage();
+ if (*tmp != 0) {
+ if (stat(optarg, &sb) == 0)
+ tval = sb.st_mtim.tv_sec;
+ else
+ usage();
+ }
break;
case 't': /* minutes west of UTC */
/* error check; don't allow "PST" */
@@ -138,7 +149,7 @@
* If -d or -t, set the timezone or daylight savings time; this
* doesn't belong here; the kernel should not know about either.
*/
- if (set_timezone && settimeofday((struct timeval *)NULL, &tz))
+ if (set_timezone && settimeofday(NULL, &tz) != 0)
err(1, "settimeofday (timezone)");
if (!rflag && time(&tval) == -1)
@@ -146,6 +157,9 @@
format = "%+";
+ if (Rflag)
+ format = rfc2822_format;
+
/* allow the operands in any order */
if (*argv && **argv == '+') {
format = *argv + 1;
@@ -170,6 +184,14 @@
usage();
}
vary_destroy(v);
+
+ if (format == rfc2822_format)
+ /*
+ * When using RFC 2822 datetime format, don't honor the
+ * locale.
+ */
+ setlocale(LC_TIME, "C");
+
(void)strftime(buf, sizeof(buf), format, <);
(void)printf("%s\n", buf);
if (fflush(stdout))
@@ -274,14 +296,14 @@
/* set the time */
if (nflag || netsettime(tval)) {
utx.ut_type = OLD_TIME;
- gettimeofday(&utx.ut_tv, NULL);
+ (void)gettimeofday(&utx.ut_tv, NULL);
pututxline(&utx);
tv.tv_sec = tval;
tv.tv_usec = 0;
- if (settimeofday(&tv, (struct timezone *)NULL))
+ if (settimeofday(&tv, NULL) != 0)
err(1, "settimeofday (timeval)");
utx.ut_type = NEW_TIME;
- gettimeofday(&utx.ut_tv, NULL);
+ (void)gettimeofday(&utx.ut_tv, NULL);
pututxline(&utx);
}
@@ -302,7 +324,7 @@
usage(void)
{
(void)fprintf(stderr, "%s\n%s\n",
- "usage: date [-jnu] [-d dst] [-r seconds] [-t west] "
+ "usage: date [-jnRu] [-d dst] [-r seconds] [-t west] "
"[-v[+|-]val[ymwdHMS]] ... ",
" "
"[-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format]");
Modified: trunk/bin/date/extern.h
===================================================================
--- trunk/bin/date/extern.h 2015-08-14 14:56:56 UTC (rev 7249)
+++ trunk/bin/date/extern.h 2015-08-14 21:43:59 UTC (rev 7250)
@@ -27,8 +27,9 @@
* SUCH DAMAGE.
*
* @(#)extern.h 8.1 (Berkeley) 5/31/93
- * $FreeBSD: src/bin/date/extern.h,v 1.7 2004/04/06 20:06:45 markm Exp $
- * $MidnightBSD$
+ * $FreeBSD: stable/10/bin/date/extern.h 241737 2012-10-19 14:49:42Z ed $
*/
+extern int retval;
+
int netsettime(time_t);
Modified: trunk/bin/date/netdate.c
===================================================================
--- trunk/bin/date/netdate.c 2015-08-14 14:56:56 UTC (rev 7249)
+++ trunk/bin/date/netdate.c 2015-08-14 21:43:59 UTC (rev 7250)
@@ -26,7 +26,6 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
-/* $FreeBSD: src/bin/date/netdate.c,v 1.18 2004/04/06 20:06:45 markm Exp $ */
#if 0
#ifndef lint
@@ -35,7 +34,7 @@
#endif
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD: src/bin/date/netdate.c,v 1.3 2007/07/23 12:22:02 alex Exp $");
+__FBSDID("$FreeBSD: stable/10/bin/date/netdate.c 244538 2012-12-21 15:54:13Z kevlo $");
#include <sys/param.h>
#include <sys/time.h>
@@ -56,8 +55,6 @@
#define WAITACK 2 /* seconds */
#define WAITDATEACK 5 /* seconds */
-extern int retval;
-
/*
* Set the date in the machines controlled by timedaemons by communicating the
* new date to the local timedaemon. If the timedaemon is in the master state,
@@ -88,7 +85,7 @@
dest.sin_addr.s_addr = htonl((u_long)INADDR_ANY);
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0) {
- if (errno != EPROTONOSUPPORT)
+ if (errno != EAFNOSUPPORT)
warn("timed");
return (retval = 2);
}
More information about the Midnightbsd-cvs
mailing list