CVS commit: src/lib/libutil

2021-05-16 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sun May 16 19:42:35 UTC 2021

Modified Files:
src/lib/libutil: parsedate.3

Log Message:
PR bin/56042

Fix typos (2nd acst should have been acdt), 0550 for ist should be 0530
(5.5 hours is not 5 hours and 50 minutes...).

Comment out the zp4 zp5 and zp6 zone names.   They are supposedly supported
by the source (they're in the table) but cannot work, as the parsedate
lexer doesn't allow a "word" to start with an alpha and also contain
digits.   Maybe (just maybe) that could be fixed sometime, but since these
have never worked, and no-one has ever seemed to miss them, and they're the
only words which are of that form, for now, just stop pretending they work.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/lib/libutil/parsedate.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.3
diff -u src/lib/libutil/parsedate.3:1.25 src/lib/libutil/parsedate.3:1.26
--- src/lib/libutil/parsedate.3:1.25	Mon Oct 19 15:08:39 2020
+++ src/lib/libutil/parsedate.3	Sun May 16 19:42:35 2021
@@ -1,4 +1,4 @@
-.\" $NetBSD: parsedate.3,v 1.25 2020/10/19 15:08:39 kre Exp $
+.\" $NetBSD: parsedate.3,v 1.26 2021/05/16 19:42:35 kre Exp $
 .\"
 .\" Copyright (c) 2006 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd October 19, 2020
+.Dd May 16, 2021
 .Dt PARSEDATE 3
 .Os
 .Sh NAME
@@ -239,10 +239,10 @@ Timezone names:
 .Dv eet (+0200) ,
 .Dv bt (+0300) ,
 .Dv it (+0330) ,
-.Dv zp4 (+0400) ,
-.Dv zp5 (+0500) ,
-.Dv ist (+0550) ,
-.Dv zp6 (+0600) ,
+.\".Dv zp4 (+0400) ,
+.\".Dv zp5 (+0500) ,
+.Dv ist (+0530) ,
+.\".Dv zp6 (+0600) ,
 .Dv ict (+0700) ,
 .Dv wast (+0800) ,
 .Dv wadt (+0900) ,
@@ -255,7 +255,7 @@ Timezone names:
 .Dv cast (+0930) ,
 .Dv cadt (+1030) ,
 .Dv acst (+0930) ,
-.Dv acst (+1030) ,
+.Dv acdt (+1030) ,
 .Dv east (+1000) ,
 .Dv eadt (+1100) ,
 .Dv aest (+1000) ,



CVS commit: src/lib/libutil

2020-10-30 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Fri Oct 30 22:03:11 UTC 2020

Modified Files:
src/lib/libutil: parsedate.y

Log Message:
PR lib/46542

Add checks to detect overflow, and also detect other invalid
(out of range) inputs for parsedate().

There could be more, and some of what is being added is not
perfect, but many calculation overflows will be detected now
(and cause an error return) and some of the most bizarre
inputs that were previously accepted no longer will be.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/lib/libutil/parsedate.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.y
diff -u src/lib/libutil/parsedate.y:1.35 src/lib/libutil/parsedate.y:1.36
--- src/lib/libutil/parsedate.y:1.35	Mon Oct 19 17:47:45 2020
+++ src/lib/libutil/parsedate.y	Fri Oct 30 22:03:11 2020
@@ -14,12 +14,13 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: parsedate.y,v 1.35 2020/10/19 17:47:45 kre Exp $");
+__RCSID("$NetBSD: parsedate.y,v 1.36 2020/10/30 22:03:11 kre Exp $");
 #endif
 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -95,6 +96,15 @@ struct dateinfo {
 		int	yyRelMonth;
 	} yyRel[MAXREL];
 };
+
+static int RelVal(struct dateinfo *, time_t, time_t, int, int);
+
+#define CheckRelVal(a, b, c, d, e) do {\
+		if (!RelVal((a), (b), (c), (d), (e))) {		\
+			YYREJECT;\
+		}		\
+	} while (0)
+
 %}
 
 %union {
@@ -191,6 +201,8 @@ at_number:
 
 time:
 	  tUNUMBER tMERIDIAN {
+		if ($1 > 24)
+			YYREJECT;
 		param->yyMinutes = 0;
 		param->yySeconds = 0;
 		if ($2 == MER_NOON || $2 == MER_MN) {
@@ -209,6 +221,8 @@ time:
 		}
 	  }
 	| tUNUMBER ':' tUNUMBER o_merid {
+		if ($1 > 24 || $3 >= 60)
+			YYREJECT;
 		param->yyMinutes = $3;
 		param->yySeconds = 0;
 		if ($4 == MER_NOON || $4 == MER_MN) {
@@ -227,6 +241,8 @@ time:
 		}
 	  }
 	| tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid {
+		if ($1 > 24 || $3 >= 60 || $5 > 60)
+			YYREJECT;
 		param->yyMinutes = $3;
 		param->yySeconds = $5;
 		if ($6 == MER_NOON || $6 == MER_MN) {
@@ -245,6 +261,8 @@ time:
 		}
 	  }
 	| tUNUMBER ':' tUNUMBER ':' tUNUMBER '.' tUNUMBER {
+		if ($1 > 24 || $3 >= 60 || $5 > 60)
+			YYREJECT;
 		param->yyHour = $1;
 		param->yyMinutes = $3;
 		param->yySeconds = $5;
@@ -252,6 +270,8 @@ time:
 		/* XXX: Do nothing with fractional secs ($7) */
 	  }
 	| tUNUMBER ':' tUNUMBER ':' tUNUMBER ',' tUNUMBER {
+		if ($1 > 24 || $3 >= 60 || $5 > 60)
+			YYREJECT;
 		param->yyHour = $1;
 		param->yyMinutes = $3;
 		param->yySeconds = $5;
@@ -280,6 +300,10 @@ time:
 
 time_numericzone:
 	  tUNUMBER ':' tUNUMBER tSNUMBER {
+		if ($4 < -(47 * 100 + 59) || $4 > (47 * 100 + 59))
+			YYREJECT;
+		if ($1 > 24 || $3 > 59)
+			YYREJECT;
 		param->yyHour = $1;
 		param->yyMinutes = $3;
 		param->yyMeridian = MER24;
@@ -287,6 +311,10 @@ time_numericzone:
 		param->yyTimezone = - ($4 % 100 + ($4 / 100) * 60);
 	  }
 	| tUNUMBER ':' tUNUMBER ':' tUNUMBER tSNUMBER {
+		if ($6 < -(47 * 100 + 59) || $6 > (47 * 100 + 59))
+			YYREJECT;
+		if ($1 > 24 || $3 > 59 || $5 > 60)
+			YYREJECT;
 		param->yyHour = $1;
 		param->yyMinutes = $3;
 		param->yySeconds = $5;
@@ -303,6 +331,8 @@ zone:
 	| tSNUMBER	{
 			  if (param->yyHaveDate == 0 && param->yyHaveTime == 0)
 YYREJECT;
+			  if ($1 < -(47 * 100 + 59) || $1 > (47 * 100 + 59))
+YYREJECT;
 			  param->yyTimezone = - ($1 % 100 + ($1 / 100) * 60);
 			  param->yyDSTmode = DSTmaybe;
 			}
@@ -316,15 +346,21 @@ day:
 
 date:
 	  tUNUMBER '/' tUNUMBER {
+		if ($1 > 12 || $3 > 31 || $1 == 0 || $3 == 0)
+			YYREJECT;
 		param->yyMonth = $1;
 		param->yyDay = $3;
 	  }
 	| tUNUMBER '/' tUNUMBER '/' tUNUMBER {
 		if ($1 >= 100) {
+			if ($3 > 12 || $5 > 31 || $3 == 0 || $5 == 0)
+YYREJECT;
 			param->yyYear = $1;
 			param->yyMonth = $3;
 			param->yyDay = $5;
 		} else {
+			if ($1 >= 12 || $3 > 31 || $1 == 0 || $3 == 0)
+YYREJECT;
 			param->yyMonth = $1;
 			param->yyDay = $3;
 			param->yyYear = $5;
@@ -332,39 +368,55 @@ date:
 	  }
 	| tUNUMBER tSNUMBER tSNUMBER {
 		/* ISO 8601 format.  -mm-dd.  */
+		if ($2 >= 0 || $2 < -12 || $3 >= 0 || $3 < -31)
+			YYREJECT;
 		param->yyYear = $1;
 		param->yyHaveFullYear = 1;
 		param->yyMonth = -$2;
 		param->yyDay = -$3;
 	  }
 	| tUNUMBER tMONTH tSNUMBER {
+		if ($3 > 0 || $1 == 0 || $1 > 31)
+			YYREJECT;
 		/* e.g. 17-JUN-1992.  */
 		param->yyDay = $1;
 		param->yyMonth = $2;
 		param->yyYear = -$3;
 	  }
 	| tMONTH tUNUMBER {
+		if ($2 == 0 || $2 > 31)
+			YYREJECT;
 		param->yyMonth = $1;
 		param->yyDay = $2;
 	  }
 	| tMONTH tUNUMBER ',' tUNUMBER {
+		if ($2 == 0 || $2 > 31)
+			YYREJECT;
 		param->yyMonth = $1;
 		param->yyDay = $2;
 		param->yyYear = $4;
 	  }
 	| tUNUMBER tMONTH {
+		if ($1 == 0 || $1 > 31)
+			YYREJECT;
 		param->yyMonth = $2;
 		param->yyDay = $1;
 	  }
 	| tUNUMBER tMONTH tUNUMBER {
-		param->yyMonth = $2;
+		if ($1 > 31 && $3 > 

CVS commit: src/lib/libutil

2020-10-19 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon Oct 19 17:47:45 UTC 2020

Modified Files:
src/lib/libutil: parsedate.y

Log Message:
Check the year field of a tentative ISO-8601 date format for overflow
before committing to it being an 8601 format date, rather than after
(or the fall back grammar parser doesn't start with a clean slate).

This isn't likely to ever bother anyone, the chances of encountering
something that looks just like an 8601 format date, but with a year
field so large it overflows a long are kind of slim.   If it did happen
the chances that the string could be correctly parsed (into something
different) by the grammar are even slimmer. But better to do it properly.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/lib/libutil/parsedate.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.y
diff -u src/lib/libutil/parsedate.y:1.34 src/lib/libutil/parsedate.y:1.35
--- src/lib/libutil/parsedate.y:1.34	Mon Oct 19 15:08:17 2020
+++ src/lib/libutil/parsedate.y	Mon Oct 19 17:47:45 2020
@@ -14,7 +14,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: parsedate.y,v 1.34 2020/10/19 15:08:17 kre Exp $");
+__RCSID("$NetBSD: parsedate.y,v 1.35 2020/10/19 17:47:45 kre Exp $");
 #endif
 
 #include 
@@ -1081,6 +1081,7 @@ parsedate(const char *p, const time_t *n
 	const unsigned char *pp = (const unsigned char *)p;
 	char *ep;	/* starts as "expected, becomes "end ptr" */
 	static char format[] = "-dd-ddTdd:dd:dd";
+	time_t yr;
 
 	while (isdigit(*pp))
 		pp++;
@@ -1121,6 +1122,11 @@ parsedate(const char *p, const time_t *n
 	if (*pp != '\0' && !isspace(*pp))
 		break;
 
+	errno = 0;
+	yr = (time_t)strtol(p, , 10);
+	if (errno != 0)			/* out of range (can be big number) */
+		break;			/* the ones below are all 2 digits */
+
 	/*
 	 * This is good enough to commit to there being an ISO format
 	 * timestamp leading the input string.   We permit standard
@@ -1135,10 +1141,7 @@ parsedate(const char *p, const time_t *n
 		param.yyHaveZone = 1;
 	}
 
-	errno = 0;
-	param.yyYear = (time_t)strtol(p, , 10);
-	if (errno != 0)			/* out of range (can be big number) */
-		break;			/* the ones below are all 2 digits */
+	param.yyYear = yr;
 	param.yyMonth = (time_t)strtol(ep + 1, , 10);
 	param.yyDay = (time_t)strtol(ep + 1, , 10);
 	param.yyHour = (time_t)strtol(ep + 1, , 10);



CVS commit: src/lib/libutil

2020-10-19 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon Oct 19 15:08:17 UTC 2020

Modified Files:
src/lib/libutil: parsedate.y

Log Message:
For touch -d (which uses parsedate()) POSIX specifies that the
ISO-8601 format -mm-ddTHH:MM:SS[radix_and+frac][Z]
be accepted.

We didn't handle that, as in parsedate(), 'T' represents the
military timezone designator, not a padding separator between
date & time as POSIX specified it.

The way parsedate() is written, fixing this in the grammar/lexer
would be hard without deleting support for T as a zone indicator
(it is *my* timezone!).

So, instead of doing that, parse an ISO-8901 string which occurs
right at the start of the input (not even any preceding white space)
by hand, before invoking the grammar, and so not involving the lexer.
This is sufficient to make touch -d conform.

After doing that, we still need to allow earlier valid inputs,
where an ISO-8601 format (using space as the separator, but without
the 'Z' (Zulu, or UTC) suffix) followed by an arbitrary timezone
designation, and other modifiers (eg: "+5 minutes" work.  So we
call the grammar on whatever is left of the input after the 8601
string has been consumed.   This all "just works" with one exception,
a format like "-mm-dd hh:mm:ss +0700" would have the grammar parse
just "+0700" which by itself would be meaningless, and so wasn't
handled.Add a grammar rule & processing to Handle it.

Also note that while POSIX specifies "at least 4" digits in the 
field, we implement "at least one" so years from 0-999 continue to be
parsed as they always have (nb: these were, and continue to be, treated
as absolute year numbers, year 10 is year 10, not 2010).  Years > 2 billion
(give or take) cannot be represented in the tm_year field of a struct tm,
so there's a limit on the max number of digits as well.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/lib/libutil/parsedate.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.y
diff -u src/lib/libutil/parsedate.y:1.33 src/lib/libutil/parsedate.y:1.34
--- src/lib/libutil/parsedate.y:1.33	Mon Oct 19 15:05:53 2020
+++ src/lib/libutil/parsedate.y	Mon Oct 19 15:08:17 2020
@@ -14,7 +14,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: parsedate.y,v 1.33 2020/10/19 15:05:53 kre Exp $");
+__RCSID("$NetBSD: parsedate.y,v 1.34 2020/10/19 15:08:17 kre Exp $");
 #endif
 
 #include 
@@ -300,6 +300,12 @@ zone:
 	  tZONE		{ param->yyTimezone = $1; param->yyDSTmode = DSToff; }
 	| tDAYZONE	{ param->yyTimezone = $1; param->yyDSTmode = DSTon; }
 	| tZONE tDST	{ param->yyTimezone = $1; param->yyDSTmode = DSTon; }
+	| tSNUMBER	{
+			  if (param->yyHaveDate == 0 && param->yyHaveTime == 0)
+YYREJECT;
+			  param->yyTimezone = - ($1 % 100 + ($1 / 100) * 60);
+			  param->yyDSTmode = DSTmaybe;
+			}
 ;
 
 day:
@@ -1066,6 +1072,85 @@ parsedate(const char *p, const time_t *n
 param.yyHaveTime = 0;
 param.yyHaveZone = 0;
 
+/*
+ * This one is too hard to parse using a grammar (the lexer would
+ * confuse the 'T' with the Mil format timezone designator)
+ * so handle it as a special case.
+ */
+do {
+	const unsigned char *pp = (const unsigned char *)p;
+	char *ep;	/* starts as "expected, becomes "end ptr" */
+	static char format[] = "-dd-ddTdd:dd:dd";
+
+	while (isdigit(*pp))
+		pp++;
+
+	if (pp == (const unsigned char *)p)
+		break;
+
+	for (ep = format; *ep; ep++, pp++) {
+		switch (*ep) {
+		case 'd':
+			if (isdigit(*pp))
+continue;
+			break;
+		case 'T':
+			if (*pp == 'T' || *pp == 't' || *pp == ' ')
+continue;
+			break;
+		default:
+			if (*pp == *ep)
+continue;
+			break;
+		}
+		break;
+	}
+	if (*ep != '\0')
+		break;
+	if (*pp == '.' || *pp == ',') {
+		if (!isdigit(pp[1]))
+			break;
+		while (isdigit(*++pp))
+			continue;
+	}
+	if (*pp == 'Z' || *pp == 'z')
+		pp++;
+	else if (isdigit(*pp))
+		break;
+
+	if (*pp != '\0' && !isspace(*pp))
+		break;
+
+	/*
+	 * This is good enough to commit to there being an ISO format
+	 * timestamp leading the input string.   We permit standard
+	 * parsedate() modifiers to follow but not precede this string.
+	 */
+	param.yyHaveTime = 1;
+	param.yyHaveDate = 1;
+	param.yyHaveFullYear = 1;
+
+	if (pp[-1] == 'Z' || pp[-1] == 'z') {
+		param.yyTimezone = 0;
+		param.yyHaveZone = 1;
+	}
+
+	errno = 0;
+	param.yyYear = (time_t)strtol(p, , 10);
+	if (errno != 0)			/* out of range (can be big number) */
+		break;			/* the ones below are all 2 digits */
+	param.yyMonth = (time_t)strtol(ep + 1, , 10);
+	param.yyDay = (time_t)strtol(ep + 1, , 10);
+	param.yyHour = (time_t)strtol(ep + 1, , 10);
+	param.yyMinutes = (time_t)strtol(ep + 1, , 10);
+	param.yySeconds = (time_t)strtol(ep + 1, , 10);
+	/* ignore any fractional seconds, no way to return them in a time_t */
+
+	param.yyMeridian = MER24;
+
+	p = (const char *)pp;
+} while (0);
+
 if 

CVS commit: src/lib/libutil

2020-10-19 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon Oct 19 15:08:39 UTC 2020

Modified Files:
src/lib/libutil: parsedate.3

Log Message:
Catch the parsedate man page up with recent updates, ans also include
some general improvements I've had kicking around for a long time, but
never got around to committing.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/lib/libutil/parsedate.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.3
diff -u src/lib/libutil/parsedate.3:1.24 src/lib/libutil/parsedate.3:1.25
--- src/lib/libutil/parsedate.3:1.24	Wed Mar 22 18:17:42 2017
+++ src/lib/libutil/parsedate.3	Mon Oct 19 15:08:39 2020
@@ -1,4 +1,4 @@
-.\" $NetBSD: parsedate.3,v 1.24 2017/03/22 18:17:42 kre Exp $
+.\" $NetBSD: parsedate.3,v 1.25 2020/10/19 15:08:39 kre Exp $
 .\"
 .\" Copyright (c) 2006 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd March 22, 2017
+.Dd October 19, 2020
 .Dt PARSEDATE 3
 .Os
 .Sh NAME
@@ -42,7 +42,7 @@
 .Sh DESCRIPTION
 The
 .Fn parsedate
-function parses a datetime from
+function parses a date and time from
 .Ar datestr
 described in English relative to an optional
 .Ar time
@@ -65,9 +65,28 @@ The
 .Ar datestr
 is a sequence of white-space separated items.
 The white-space is optional if the concatenated items are not ambiguous.
+The string contains data which can specify a base time (used in
+conjunction with the
+.Ar time
+parameter, totally replacing that parameter's value if sufficient data
+appears in
+.Ar datestr
+to do so), and data specifying an offset from the base time.
+Both of those are optional.
+If no data specifies the base time, then
+.Nm
+simply uses the value given by
+.Ar \&*time
+.Pq "or now" .
+If there is no offset data then no offset is applied.
 An empty
+.Ar datestr ,
+or a
 .Ar datestr
-is equivalent to midnight today (the beginning of this day).
+containing nothing but whitespace,
+is equivalent to midnight at the start of the day specified by
+.Ar \&*time
+.Pq "or today" .
 .Pp
 The following words have the indicated numeric meanings:
 .Dv last =
@@ -147,6 +166,11 @@ The months:
 .Dv november ,
 .Dv december ,
 and common abbreviations for them.
+When a month name (or its ordinal number) is given,
+the number of some particular day of that month is required to accompany it.
+This is generally true of any data that specifies a period
+with a duration longer than a day, so simply specifying a year,
+or a month, is invalid, as also is specifying a year and a month.
 .Pp
 The days of the week:
 .Dv sunday ,
@@ -157,6 +181,9 @@ The days of the week:
 .Dv friday ,
 .Dv saturday ,
 and common abbreviations for them.
+Weekday names are typically ignored if any other data
+is given to specify the date, even if the name given
+is not the day on which the specified date occurred.
 .Pp
 Time units:
 .Dv year ,
@@ -239,20 +266,27 @@ Timezone names:
 .Dv nzdt (+1300) ,
 .Dv idle (+1200) .
 .Pp
-The timezone names specify an offset from Coordinated Universal Time (UTC)
+The timezone names simply specify an offset from
+Coordinated Universal Time (UTC)
 and do not imply validating the time/date to be reasonable in any zone
 that happens to use the abbreviation specified.
 .Pp
 A variety of unambiguous dates are recognized:
 .Bl -tag -compact -width "20 Jun 1994"
 .It 9/10/69
-For years between 70-99 we assume 1900+ and for years between 0-69
+For years between 69-99 we assume 1900+ and for years between 0-68
 we assume 2000+.
 .It 2006-11-17
 An ISO-8601 date.
-.It 69-09-10
+Note that when using the ISO-8601 format date and time with the
+.Sq T
+designator to separate date and time-of-day,
+this must appear at the start of the input string,
+with no preceding whitespace.
+Other modifiers may optionally follow.
+.It 67-09-10
 The year in an ISO-8601 date is always taken literally,
-so this is the year 69, not 2069.
+so this is the year 67, not 2067.
 .It 10/1/2000
 October 1, 2000; the common, but bizarre, US format.
 .It 20 Jun 1994
@@ -261,7 +295,14 @@ October 1, 2000; the common, but bizarre
 Other common abbreviations.
 .It 1/11
 The year can be omitted.
-This is the US month/day format.
+A missing year is taken from the
+.Ar \&*time
+value, or
+.Dq now
+if
+.Ar time
+is NULL.
+Again, this is the US month/day format (the 11th of January).
 .El
 .Pp
 Standard e-mail (RFC822, RFC2822, etc)
@@ -269,18 +310,28 @@ formats and the output from
 .Xr date 1 ,
 and
 .Xr asctime 3
-are all supported as input.
+are all supported as input,
+as is cvs date format (where years < 100 are treated as
+20th century).
 .Pp
-As well as times:
+Times can also be specified in common forms:
 .Bl -tag -compact -width 12:11:01.12
 .It 10:01
 .It 10:12pm
 .It 12:11:01.12
 .It 12:21-0500
 .El

CVS commit: src/lib/libutil

2020-10-19 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon Oct 19 15:05:53 UTC 2020

Modified Files:
src/lib/libutil: parsedate.y

Log Message:
POSIX requires that when converting 2 digit year representations to
actual specific years, values from 69-99 be treated as 20th century,
and values from 0-68 be treated as 21st century.  This allows for those
unfortunate enough to reside in a timezone west of Greenwich to convert
the epoch (or a time very close to it) to text, write that with just two
digits, and correctly convert it back to a time near the epoch, rather
than to something in 2069.

We used to split things so 0-69 were 21st century, and 70-99 were 20th.
Change that (this requires a change in the parsedate ATF tests which
test this specific boundary).

While here, add support for another POSIX requirement, that the radix
char before fractional seconds can be either a ',' or a '.'.  We used
to allow only '.', add support for ','.   This is something of a meaningless
change, as parsedate() returns a time_t in which there is no way to
represent fractional seconds, so there's little point in ever specifying
them regardless of what char is used for the "decimal point" - they will
be ignored anyway.But at least fractional seconds using a ',' as the
radix char will no longer cause the conversion to fail (or do something else
bizarre).


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/lib/libutil/parsedate.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.y
diff -u src/lib/libutil/parsedate.y:1.32 src/lib/libutil/parsedate.y:1.33
--- src/lib/libutil/parsedate.y:1.32	Wed Mar 22 18:17:42 2017
+++ src/lib/libutil/parsedate.y	Mon Oct 19 15:05:53 2020
@@ -14,7 +14,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: parsedate.y,v 1.32 2017/03/22 18:17:42 kre Exp $");
+__RCSID("$NetBSD: parsedate.y,v 1.33 2020/10/19 15:05:53 kre Exp $");
 #endif
 
 #include 
@@ -249,7 +249,14 @@ time:
 		param->yyMinutes = $3;
 		param->yySeconds = $5;
 		param->yyMeridian = MER24;
-		/* XXX: Do nothing with millis */
+		/* XXX: Do nothing with fractional secs ($7) */
+	  }
+	| tUNUMBER ':' tUNUMBER ':' tUNUMBER ',' tUNUMBER {
+		param->yyHour = $1;
+		param->yyMinutes = $3;
+		param->yySeconds = $5;
+		param->yyMeridian = MER24;
+		/* XXX: Do nothing with fractional seconds ($7) */
 	  }
 	| tTIME {
 		param->yyHour = $1;
@@ -664,7 +671,8 @@ RelVal(struct dateinfo *param, time_t v,
  * e.g. convert 70 to 1970.
  * Input Year is either:
  *  - A negative number, which means to use its absolute value (why?)
- *  - A number from 0 to 99, which means a year from 1900 to 1999, or
+ *  - A number from 0 to 68, which means a year from 2000 to 2068, 
+ *  - A number from 69 to 99, which means a year from 1969 to 1999, or
  *  - The actual year (>=100).
  * Returns the full year.
  */
@@ -674,7 +682,7 @@ AdjustYear(time_t Year)
 /* XXX Y2K */
 if (Year < 0)
 	Year = -Year;
-if (Year < 70)
+if (Year < 69)	/* POSIX compliant, 0..68 is 2000's, 69-99 1900's */
 	Year += 2000;
 else if (Year < 100)
 	Year += 1900;



CVS commit: src/lib/libutil

2020-07-30 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Thu Jul 30 21:23:36 UTC 2020

Modified Files:
src/lib/libutil: snprintb.3

Log Message:
Fix grammar.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/lib/libutil/snprintb.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/snprintb.3
diff -u src/lib/libutil/snprintb.3:1.23 src/lib/libutil/snprintb.3:1.24
--- src/lib/libutil/snprintb.3:1.23	Sat Dec  7 12:47:07 2019
+++ src/lib/libutil/snprintb.3	Thu Jul 30 21:23:36 2020
@@ -1,4 +1,4 @@
-.\" $NetBSD: snprintb.3,v 1.23 2019/12/07 12:47:07 wiz Exp $
+.\" $NetBSD: snprintb.3,v 1.24 2020/07/30 21:23:36 uwe Exp $
 .\"
 .\" Copyright (c) 1998 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -63,7 +63,7 @@ If the buffer
 is too small to hold the formatted output,
 .Fn snprintb
 will fill as much as it can, and return the number of bytes
-that would have written if the buffer was long enough excluding the
+that it would have written if the buffer were long enough excluding the
 terminating NUL.
 .Pp
 The decoding directive string



CVS commit: src/lib/libutil

2020-03-30 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Mon Mar 30 08:24:36 UTC 2020

Modified Files:
src/lib/libutil: pidlock.c

Log Message:
fail to create a pidfile if hostname contains '/'


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libutil/pidlock.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/pidlock.c
diff -u src/lib/libutil/pidlock.c:1.16 src/lib/libutil/pidlock.c:1.17
--- src/lib/libutil/pidlock.c:1.16	Sat Apr  7 16:17:17 2012
+++ src/lib/libutil/pidlock.c	Mon Mar 30 08:24:36 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pidlock.c,v 1.16 2012/04/07 16:17:17 christos Exp $ */
+/*	$NetBSD: pidlock.c,v 1.17 2020/03/30 08:24:36 ryo Exp $ */
 
 /*
  * Copyright 1996, 1997 by Curt Sampson .
@@ -24,7 +24,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: pidlock.c,v 1.16 2012/04/07 16:17:17 christos Exp $");
+__RCSID("$NetBSD: pidlock.c,v 1.17 2020/03/30 08:24:36 ryo Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include 
@@ -67,6 +67,12 @@ pidlock(const char *lockfile, int flags,
 		return -1;
 	hostname[sizeof(hostname) - 1] = '\0';
 
+	/* avoid '/' in hostname, as it may contain arbitrary characters */
+	for (p = hostname; *p != '\0'; p++) {
+		if (*p == '/')
+			*p = '_';
+	}
+
 	/*
 	 * Build a path to the temporary file.
 	 * We use the path with the PID and hostname appended.



CVS commit: src/lib/libutil

2019-12-07 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sat Dec  7 12:47:07 UTC 2019

Modified Files:
src/lib/libutil: snprintb.3

Log Message:
Remove trailing whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/lib/libutil/snprintb.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/snprintb.3
diff -u src/lib/libutil/snprintb.3:1.22 src/lib/libutil/snprintb.3:1.23
--- src/lib/libutil/snprintb.3:1.22	Fri Dec  6 19:31:52 2019
+++ src/lib/libutil/snprintb.3	Sat Dec  7 12:47:07 2019
@@ -1,4 +1,4 @@
-.\" $NetBSD: snprintb.3,v 1.22 2019/12/06 19:31:52 christos Exp $
+.\" $NetBSD: snprintb.3,v 1.23 2019/12/07 12:47:07 wiz Exp $
 .\"
 .\" Copyright (c) 1998 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -191,7 +191,7 @@ or
 have not matched.
 .Ar FMT
 may contain a
-.Ft uintmax_t 
+.Ft uintmax_t
 format specification that prints the value that
 did not match, since the field can be more than 32 bits wide.
 .El



CVS commit: src/lib/libutil

2019-12-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Dec  6 19:31:52 UTC 2019

Modified Files:
src/lib/libutil: snprintb.3

Log Message:
Correct the man page, and say that the printf(3) format characters need
to be uintmax_t.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/lib/libutil/snprintb.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/snprintb.3
diff -u src/lib/libutil/snprintb.3:1.21 src/lib/libutil/snprintb.3:1.22
--- src/lib/libutil/snprintb.3:1.21	Mon Apr 29 03:55:38 2019
+++ src/lib/libutil/snprintb.3	Fri Dec  6 14:31:52 2019
@@ -1,4 +1,4 @@
-.\" $NetBSD: snprintb.3,v 1.21 2019/04/29 07:55:38 kre Exp $
+.\" $NetBSD: snprintb.3,v 1.22 2019/12/06 19:31:52 christos Exp $
 .\"
 .\" Copyright (c) 1998 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd April 27, 2019
+.Dd December 6, 2019
 .Dt SNPRINTB 3
 .Os
 .Sh NAME
@@ -190,8 +190,10 @@ or
 .Sq \&=
 have not matched.
 .Ar FMT
-may contain an integer format specification that prints the value that
-did not match.
+may contain a
+.Ft uintmax_t 
+format specification that prints the value that
+did not match, since the field can be more than 32 bits wide.
 .El
 .Pp
 Finally, each field is delimited by a NUL
@@ -307,7 +309,7 @@ F\e30\e010\e0\e
 :\e064ALIGN=4PB\e0\e
 :\e070ALIGN=64PB\e0\e
 :\e074ALIGN=256PB\e0\e
-*ALIGN=2^%d\e0\e
+*ALIGN=2^%jd\e0\e
 "
 snprintb(buf, buflen, MAP_FMT, 0x0d001234)
 \(rA "0xd001234"



CVS commit: src/lib/libutil

2019-04-27 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sat Apr 27 17:58:51 UTC 2019

Modified Files:
src/lib/libutil: snprintb.3

Log Message:
Remove trailing whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/lib/libutil/snprintb.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/snprintb.3
diff -u src/lib/libutil/snprintb.3:1.19 src/lib/libutil/snprintb.3:1.20
--- src/lib/libutil/snprintb.3:1.19	Sat Apr 27 17:48:13 2019
+++ src/lib/libutil/snprintb.3	Sat Apr 27 17:58:51 2019
@@ -1,4 +1,4 @@
-.\" $NetBSD: snprintb.3,v 1.19 2019/04/27 17:48:13 christos Exp $
+.\" $NetBSD: snprintb.3,v 1.20 2019/04/27 17:58:51 wiz Exp $
 .\"
 .\" Copyright (c) 1998 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -183,7 +183,7 @@ This provides a
 case that prints
 .Ar FMT
 using
-.Xr printf 3 
+.Xr printf 3
 when other
 .Sq \&:
 or



CVS commit: src/lib/libutil

2019-04-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Apr 27 17:48:13 UTC 2019

Modified Files:
src/lib/libutil: snprintb.3

Log Message:
remove dup line


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/lib/libutil/snprintb.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/snprintb.3
diff -u src/lib/libutil/snprintb.3:1.18 src/lib/libutil/snprintb.3:1.19
--- src/lib/libutil/snprintb.3:1.18	Sat Apr 27 13:46:08 2019
+++ src/lib/libutil/snprintb.3	Sat Apr 27 13:48:13 2019
@@ -1,4 +1,4 @@
-.\" $NetBSD: snprintb.3,v 1.18 2019/04/27 17:46:08 christos Exp $
+.\" $NetBSD: snprintb.3,v 1.19 2019/04/27 17:48:13 christos Exp $
 .\"
 .\" Copyright (c) 1998 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -271,7 +271,6 @@ multi-field formatting with a default ca
 .Bd -literal -offset indent
 #define MAP_FMT	"\e177\e020\e
 b\e0SHARED\e0\e
-b\e0SHARED\e0\e
 b\e1PRIVATE\e0\e
 b\e2COPY\e0\e
 b\e4FIXED\e0\e



CVS commit: src/lib/libutil

2019-04-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Apr 27 17:46:08 UTC 2019

Modified Files:
src/lib/libutil: snprintb.3

Log Message:
Document the '*' field and give a more complex example with F and *.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/lib/libutil/snprintb.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/snprintb.3
diff -u src/lib/libutil/snprintb.3:1.17 src/lib/libutil/snprintb.3:1.18
--- src/lib/libutil/snprintb.3:1.17	Sun Oct 22 12:59:18 2017
+++ src/lib/libutil/snprintb.3	Sat Apr 27 13:46:08 2019
@@ -1,4 +1,4 @@
-.\" $NetBSD: snprintb.3,v 1.17 2017/10/22 16:59:18 abhinav Exp $
+.\" $NetBSD: snprintb.3,v 1.18 2019/04/27 17:46:08 christos Exp $
 .\"
 .\" Copyright (c) 1998 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd May 7, 2009
+.Dd April 27, 2019
 .Dt SNPRINTB 3
 .Os
 .Sh NAME
@@ -177,6 +177,21 @@ Operates like the
 .Sq \&=
 operator, but omits the leading
 .Sq \&= .
+.It Cm *FMT
+This provides a
+.Dq default
+case that prints
+.Ar FMT
+using
+.Xr printf 3 
+when other
+.Sq \&:
+or
+.Sq \&=
+have not matched.
+.Ar FMT
+may contain an integer format specification that prints the value that
+did not match.
 .El
 .Pp
 Finally, each field is delimited by a NUL
@@ -246,6 +261,61 @@ snprintb(buf, buflen,
 \(rA "0x800f0701"
 .Ed
 .Pp
+A more complex example from
+.In sys/mman.h
+that uses the both bit position
+.Sq b
+formatting as well as the
+.Sq F
+multi-field formatting with a default case:
+.Bd -literal -offset indent
+#define MAP_FMT	"\e177\e020\e
+b\e0SHARED\e0\e
+b\e0SHARED\e0\e
+b\e1PRIVATE\e0\e
+b\e2COPY\e0\e
+b\e4FIXED\e0\e
+b\e5RENAME\e0\e
+b\e6NORESERVE\e0\e
+b\e7INHERIT\e0\e
+b\e11HASSEMAPHORE\e0\e
+b\e12TRYFIXED\e0\e
+b\e13WIRED\e0\e
+F\e14\e1\e
+:\e0FILE\e0\e
+:\e1ANONYMOUS\e0\e
+b\e15STACK\e0\e
+F\e30\e010\e
+:\e000ALIGN=NONE\e0\e
+:\e012ALIGN=1KB\e0\e
+:\e013ALIGN=2KB\e0\e
+:\e014ALIGN=4KB\e0\e
+:\e015ALIGN=8KB\e0\e
+:\e016ALIGN=16KB\e0\e
+:\e017ALIGN=32KB\e0\e
+:\e020ALIGN=64KB\e0\e
+:\e021ALIGN=128KB\e0\e
+:\e022ALIGN=256KB\e0\e
+:\e023ALIGN=512KB\e0\e
+:\e024ALIGN=1MB\e0\e
+:\e030ALIGN=16MB\e0\e
+:\e034ALIGN=256MB\e0\e
+:\e040ALIGN=4GB\e0\e
+:\e044ALIGN=64GB\e0\e
+:\e050ALIGN=1TB\e0\e
+:\e054ALIGN=16TB\e0\e
+:\e060ALIGN=256TB\e0\e
+:\e064ALIGN=4PB\e0\e
+:\e070ALIGN=64PB\e0\e
+:\e074ALIGN=256PB\e0\e
+*ALIGN=2^%d\e0\e
+"
+snprintb(buf, buflen, MAP_FMT, 0x0d001234)
+\(rA "0xd001234"
+snprintb(buf, buflen, MAP_FMT, 0x2e00)
+\(rA "0xd001234<0x2e00
+.Ed
+.Pp
 An example using snprintb_m:
 .Bd -literal -offset indent
 snprintb_m(buf, buflen,



CVS commit: src/lib/libutil

2018-12-28 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Fri Dec 28 18:44:11 UTC 2018

Modified Files:
src/lib/libutil: getfsspecname.3

Log Message:
Document "ROOT." syntax before documenting a generic .


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libutil/getfsspecname.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/getfsspecname.3
diff -u src/lib/libutil/getfsspecname.3:1.6 src/lib/libutil/getfsspecname.3:1.7
--- src/lib/libutil/getfsspecname.3:1.6	Sat Oct  6 13:09:53 2018
+++ src/lib/libutil/getfsspecname.3	Fri Dec 28 18:44:11 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: getfsspecname.3,v 1.6 2018/10/06 13:09:53 jmcneill Exp $
+.\"	$NetBSD: getfsspecname.3,v 1.7 2018/12/28 18:44:11 alnsn Exp $
 .\"
 .\" Copyright (c) 2012 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -28,7 +28,7 @@
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
 .\"
-.Dd October 6, 2018
+.Dd December 28, 2018
 .Dt GETFSSPECNAME 3
 .Os
 .Sh NAME
@@ -58,16 +58,6 @@ up to len
 .Pp
 If the
 .Fa spec
-argument is not of the form
-.Dq NAME=wedgename ,
-.Fa spec
-is copied
-to
-.Fa buf
-and returned.
-.Pp
-If the
-.Fa spec
 argument starts with
 .Dq ROOT. ,
 a path in the form
@@ -85,6 +75,18 @@ is the characters following
 in the
 .Fa spec
 argument.
+.Pp
+If the
+.Fa spec
+argument is not of the form
+.Dq NAME=wedgename
+and it doesn't start with
+.Dq ROOT. ,
+.Fa spec
+is copied
+to
+.Fa buf
+and returned.
 .Sh RETURN VALUES
 On success the absolute pathname of the underlying wedge device is returned,
 or the original



CVS commit: src/lib/libutil

2018-12-27 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Thu Dec 27 21:35:48 UTC 2018

Modified Files:
src/lib/libutil: getfsspecname.c

Log Message:
No need to quadruple a buffer because strunvis(3) doesn't expand.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/libutil/getfsspecname.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/getfsspecname.c
diff -u src/lib/libutil/getfsspecname.c:1.7 src/lib/libutil/getfsspecname.c:1.8
--- src/lib/libutil/getfsspecname.c:1.7	Sat Oct  6 23:48:00 2018
+++ src/lib/libutil/getfsspecname.c	Thu Dec 27 21:35:48 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: getfsspecname.c,v 1.7 2018/10/06 23:48:00 christos Exp $	*/
+/*	$NetBSD: getfsspecname.c,v 1.8 2018/12/27 21:35:48 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: getfsspecname.c,v 1.7 2018/10/06 23:48:00 christos Exp $");
+__RCSID("$NetBSD: getfsspecname.c,v 1.8 2018/12/27 21:35:48 alnsn Exp $");
 
 #include 
 #include 
@@ -108,7 +108,7 @@ getfsspecname(char *buf, size_t bufsiz, 
 #ifdef COMPAT_DKWEDGE
 search:
 #endif
-	vname = malloc(strlen(name) * 4 + 1);
+	vname = malloc(strlen(name) + 1);
 	if (vname == NULL) {
 		savee = errno;
 		strlcpy(buf, "malloc failed", bufsiz);



CVS commit: src/lib/libutil

2018-10-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Oct  6 23:48:00 UTC 2018

Modified Files:
src/lib/libutil: getfsspecname.c

Log Message:
use the right type.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libutil/getfsspecname.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/getfsspecname.c
diff -u src/lib/libutil/getfsspecname.c:1.6 src/lib/libutil/getfsspecname.c:1.7
--- src/lib/libutil/getfsspecname.c:1.6	Sat Oct  6 09:09:53 2018
+++ src/lib/libutil/getfsspecname.c	Sat Oct  6 19:48:00 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: getfsspecname.c,v 1.6 2018/10/06 13:09:53 jmcneill Exp $	*/
+/*	$NetBSD: getfsspecname.c,v 1.7 2018/10/06 23:48:00 christos Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: getfsspecname.c,v 1.6 2018/10/06 13:09:53 jmcneill Exp $");
+__RCSID("$NetBSD: getfsspecname.c,v 1.7 2018/10/06 23:48:00 christos Exp $");
 
 #include 
 #include 
@@ -68,7 +68,7 @@ getfsspecname(char *buf, size_t bufsiz, 
 	 */
 	if (strncasecmp(name, "ROOT.", 5) == 0 && strchr(name, ':') == NULL) {
 		static const int mib_root[] = { CTL_KERN, KERN_ROOT_DEVICE };
-		static const int mib_rootlen = __arraycount(mib_root);
+		static const unsigned int mib_rootlen = __arraycount(mib_root);
 
 		strlcpy(buf, "/dev/", bufsiz);
 		len = bufsiz - 5;



CVS commit: src/lib/libutil

2018-06-24 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Jun 24 09:30:26 UTC 2018

Modified Files:
src/lib/libutil: pty.c

Log Message:
Fix stack use after scope in libutil/pty

The pt variable's elements are used after the end of the pt scope.
A move of pt to outer scope fixes this.

Detected with MKSANITIZER/ASan with tmux(1), a forkpty(3) user.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/lib/libutil/pty.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/pty.c
diff -u src/lib/libutil/pty.c:1.31 src/lib/libutil/pty.c:1.32
--- src/lib/libutil/pty.c:1.31	Fri Feb 20 16:44:06 2009
+++ src/lib/libutil/pty.c	Sun Jun 24 09:30:26 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: pty.c,v 1.31 2009/02/20 16:44:06 christos Exp $	*/
+/*	$NetBSD: pty.c,v 1.32 2018/06/24 09:30:26 kamil Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)pty.c	8.3 (Berkeley) 5/16/94";
 #else
-__RCSID("$NetBSD: pty.c,v 1.31 2009/02/20 16:44:06 christos Exp $");
+__RCSID("$NetBSD: pty.c,v 1.32 2018/06/24 09:30:26 kamil Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -70,6 +70,7 @@ openpty(int *amaster, int *aslave, char 
 	mode_t mode;
 	struct group grs, *grp;
 	char grbuf[1024];
+	struct ptmget pt;
 
 	_DIAGASSERT(amaster != NULL);
 	_DIAGASSERT(aslave != NULL);
@@ -78,7 +79,6 @@ openpty(int *amaster, int *aslave, char 
 	/* winp may be NULL */
 
 	if ((master = open("/dev/ptm", O_RDWR)) != -1) {
-		struct ptmget pt;
 		if (ioctl(master, TIOCPTMGET, ) != -1) {
 			(void)close(master);
 			master = pt.cfd;



CVS commit: src/lib/libutil

2018-06-23 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Jun 24 01:53:14 UTC 2018

Modified Files:
src/lib/libutil: passwd.c

Log Message:
Prevent underflow buffer read in trim_whitespace() in libutil/passwd.c

If a string is empty or contains only white characters, the algorithm of
removal of white characters at the end of the passed string will read
buffer at index -1 and keep iterating backward.

Detected with MKSANITIZER/ASan when executing passwd(1).


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/lib/libutil/passwd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/passwd.c
diff -u src/lib/libutil/passwd.c:1.52 src/lib/libutil/passwd.c:1.53
--- src/lib/libutil/passwd.c:1.52	Mon Jun 25 22:32:47 2012
+++ src/lib/libutil/passwd.c	Sun Jun 24 01:53:14 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: passwd.c,v 1.52 2012/06/25 22:32:47 abs Exp $	*/
+/*	$NetBSD: passwd.c,v 1.53 2018/06/24 01:53:14 kamil Exp $	*/
 
 /*
  * Copyright (c) 1987, 1993, 1994, 1995
@@ -31,7 +31,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: passwd.c,v 1.52 2012/06/25 22:32:47 abs Exp $");
+__RCSID("$NetBSD: passwd.c,v 1.53 2018/06/24 01:53:14 kamil Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include 
@@ -503,13 +503,21 @@ trim_whitespace(char *line)
 
 	_DIAGASSERT(line != NULL);
 
+	/* Handle empty string */
+	if (*line == '\0')
+		return;
+
 	/* Remove leading spaces */
 	p = line;
 	while (isspace((unsigned char) *p))
 		p++;
 	memmove(line, p, strlen(p) + 1);
 
-	/* Remove trailing spaces */
+	/* Handle empty string after removal of whitespace characters */
+	if (*line == '\0')
+		return;
+
+	/* Remove trailing spaces, line must not be empty string here */
 	p = line + strlen(line) - 1;
 	while (isspace((unsigned char) *p))
 		p--;



CVS commit: src/lib/libutil

2018-04-05 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Thu Apr  5 11:07:00 UTC 2018

Modified Files:
src/lib/libutil: opendisk.3

Log Message:
Use mdoc macros.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/lib/libutil/opendisk.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/opendisk.3
diff -u src/lib/libutil/opendisk.3:1.15 src/lib/libutil/opendisk.3:1.16
--- src/lib/libutil/opendisk.3:1.15	Wed Apr  4 04:43:46 2018
+++ src/lib/libutil/opendisk.3	Thu Apr  5 11:07:00 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: opendisk.3,v 1.15 2018/04/04 04:43:46 kre Exp $
+.\"	$NetBSD: opendisk.3,v 1.16 2018/04/05 11:07:00 wiz Exp $
 .\"
 .\" Copyright (c) 1997, 2001 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -200,7 +200,7 @@ may also set
 to any value specified by the
 .Xr open 2
 function.
-.PP
+.Pp
 The
 .Fn opendisk1
 function may also set
@@ -216,7 +216,7 @@ The
 .Fn opendisk
 function first appeared in
 .Nx 1.3 .
-.br
+.Pp
 The
 .Fn opendisk1
 function first appeared in



CVS commit: src/lib/libutil

2017-10-22 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Mon Oct 23 01:05:10 UTC 2017

Modified Files:
src/lib/libutil: pidlock.3

Log Message:
Sort errors.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libutil/pidlock.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/pidlock.3
diff -u src/lib/libutil/pidlock.3:1.12 src/lib/libutil/pidlock.3:1.13
--- src/lib/libutil/pidlock.3:1.12	Mon Mar  9 19:24:27 2009
+++ src/lib/libutil/pidlock.3	Mon Oct 23 01:05:10 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: pidlock.3,v 1.12 2009/03/09 19:24:27 joerg Exp $
+.\"	$NetBSD: pidlock.3,v 1.13 2017/10/23 01:05:10 wiz Exp $
 .\"
 .\" Copyright 1996, 1997 by Curt Sampson 
 .\"
@@ -152,16 +152,16 @@ can set
 .Va errno
 to the following values on failure:
 .Bl -tag -width Er
-.It Bq Er EWOULDBLOCK
-Another running process has a lock and the
-.Dv PIDLOCK_NONBLOCK
-flag was specified.
 .It Bq Er EFTYPE
 The
 .Fa tty
 specified in
 .Fn ttylock
 is not a character special device.
+.It Bq Er EWOULDBLOCK
+Another running process has a lock and the
+.Dv PIDLOCK_NONBLOCK
+flag was specified.
 .El
 .\" .Sh SEE ALSO
 .Sh HISTORY



CVS commit: src/lib/libutil

2017-10-22 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Sun Oct 22 16:59:18 UTC 2017

Modified Files:
src/lib/libutil: snprintb.3

Log Message:
Add snprintb_m to the NAME section.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libutil/snprintb.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/snprintb.3
diff -u src/lib/libutil/snprintb.3:1.16 src/lib/libutil/snprintb.3:1.17
--- src/lib/libutil/snprintb.3:1.16	Wed Aug  7 23:22:28 2013
+++ src/lib/libutil/snprintb.3	Sun Oct 22 16:59:18 2017
@@ -1,4 +1,4 @@
-.\" $NetBSD: snprintb.3,v 1.16 2013/08/07 23:22:28 pgoyette Exp $
+.\" $NetBSD: snprintb.3,v 1.17 2017/10/22 16:59:18 abhinav Exp $
 .\"
 .\" Copyright (c) 1998 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -31,7 +31,8 @@
 .Dt SNPRINTB 3
 .Os
 .Sh NAME
-.Nm snprintb
+.Nm snprintb ,
+.Nm snprintb_m
 .Nd bitmask output conversion
 .Sh LIBRARY
 .Lb libutil



CVS commit: src/lib/libutil

2017-10-22 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Sun Oct 22 16:55:32 UTC 2017

Modified Files:
src/lib/libutil: pidfile.3

Log Message:
Add missing functions to the NAME section


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/lib/libutil/pidfile.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/pidfile.3
diff -u src/lib/libutil/pidfile.3:1.15 src/lib/libutil/pidfile.3:1.16
--- src/lib/libutil/pidfile.3:1.15	Mon Apr 11 08:49:57 2016
+++ src/lib/libutil/pidfile.3	Sun Oct 22 16:55:32 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: pidfile.3,v 1.15 2016/04/11 08:49:57 wiz Exp $
+.\"	$NetBSD: pidfile.3,v 1.16 2017/10/22 16:55:32 abhinav Exp $
 .\"
 .\" Copyright (c) 1999, 2016 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -31,7 +31,10 @@
 .Dt PIDFILE 3
 .Os
 .Sh NAME
-.Nm pidfile
+.Nm pidfile ,
+.Nm pidfile_lock ,
+.Nm pidfile_read ,
+.Nm pidfile_clean
 .Nd write a daemon pid file
 .Sh LIBRARY
 .Lb libutil



CVS commit: src/lib/libutil

2017-03-30 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Thu Mar 30 20:00:21 UTC 2017

Modified Files:
src/lib/libutil: util.3

Log Message:
Use Sy to highlight the table header.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/lib/libutil/util.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/util.3
diff -u src/lib/libutil/util.3:1.25 src/lib/libutil/util.3:1.26
--- src/lib/libutil/util.3:1.25	Thu Mar 30 19:56:36 2017
+++ src/lib/libutil/util.3	Thu Mar 30 20:00:21 2017
@@ -1,4 +1,4 @@
-.\" $NetBSD: util.3,v 1.25 2017/03/30 19:56:36 abhinav Exp $
+.\" $NetBSD: util.3,v 1.26 2017/03/30 20:00:21 abhinav Exp $
 .\"
 .\" Copyright (c) 2001 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -57,7 +57,7 @@ library and the associated functions are
 directory.
 .Sh LIST OF FUNCTIONS
 .Bl -column ".Xr sockaddr_snprintf 3" -compact
-.It Sy Name	Description
+.It Sy Name Ta Sy Description
 .It Xr disklabel_dkcksum 3 Ta compute the checksum for a disklabel
 .It Xr disklabel_scan 3 Ta scan a buffer for a valid disklabel
 .It Xr efun 3 Ta error checked utility functions



CVS commit: src/lib/libutil

2017-03-30 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Thu Mar 30 19:56:36 UTC 2017

Modified Files:
src/lib/libutil: util.3

Log Message:
Add missing functions


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/lib/libutil/util.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/util.3
diff -u src/lib/libutil/util.3:1.24 src/lib/libutil/util.3:1.25
--- src/lib/libutil/util.3:1.24	Mon Aug 29 12:39:50 2011
+++ src/lib/libutil/util.3	Thu Mar 30 19:56:36 2017
@@ -1,4 +1,4 @@
-.\" $NetBSD: util.3,v 1.24 2011/08/29 12:39:50 jruoho Exp $
+.\" $NetBSD: util.3,v 1.25 2017/03/30 19:56:36 abhinav Exp $
 .\"
 .\" Copyright (c) 2001 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd August 29, 2011
+.Dd March 31, 2017
 .Dt UTIL 3
 .Os
 .Sh NAME
@@ -60,12 +60,20 @@ directory.
 .It Sy Name	Description
 .It Xr disklabel_dkcksum 3 Ta compute the checksum for a disklabel
 .It Xr disklabel_scan 3 Ta scan a buffer for a valid disklabel
+.It Xr efun 3 Ta error checked utility functions
 .It Xr forkpty 3 Ta tty utility function
 .It Xr getbootfile 3 Ta get the name of the booted kernel file
+.It Xr getbyteorder 3 Ta get the current byte order
+.It Xr getdiskrawname 3 Ta get the the block/character device name for a disk
+.It Xr getfsspecname 3 Ta get the underlying wedge name from a label
+.It Xr getfstypename 3 Ta convert a partition file system type integer to a wedge
+partition type name
 .It Xr getlabeloffset 3 Ta get the sector number and offset of the disklabel
 .It Xr getlabelsector 3 Ta get the sector number and offset of the disklabel
 .It Xr getmaxpartitions 3 Ta get the maximum number of partitions allowed per disk
+.It Xr getmntopts 3 Ta scan mount options
 .It Xr getrawpartition 3 Ta get the system ``raw'' partition
+.It Xr kinfo_getvmmap 3 Ta get per-process memory map information
 .It Xr login 3 Ta login utility function
 .It Xr login_cap 3 Ta query login.conf database about a user class
 .It Xr login_close 3 Ta query login.conf database about a user class
@@ -85,6 +93,7 @@ directory.
 .It Xr openpty 3 Ta tty utility function
 .It Xr pidfile 3 Ta write a daemon pid file
 .It Xr pidlock 3 Ta locks based on files containing PIDs
+.It Xr proc_compare 3 Ta compare two processes' interactivity
 .It Xr pw_abort 3 Ta passwd file update function
 .It Xr pw_copy 3 Ta utility function for interactive passwd file updates
 .It Xr pw_edit 3 Ta utility function for interactive passwd file updates
@@ -97,6 +106,7 @@ directory.
 .It Xr pw_prompt 3 Ta utility function for interactive passwd file updates
 .It Xr pw_scan 3 Ta utility function for interactive passwd file updates
 .It Xr pw_setprefix 3 Ta passwd file update function
+.It Xr raise_default_signal 3 Ta raise the default signal handler
 .It Xr secure_path 3 Ta determine if a file appears to be ``secure''
 .It Xr setclasscontext 3 Ta query login.conf database about a user class
 .It Xr setusercontext 3 Ta query login.conf database about a user class



CVS commit: src/lib/libutil

2017-03-30 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Thu Mar 30 19:41:41 UTC 2017

Modified Files:
src/lib/libutil: getmntopts.3

Log Message:
Add getmntoptstr, getmntoptnum, and freemntopts to the NAME section
Fix couple of sentences

getmntoptstr, getmntoptnum, and freemntopts need to be linked to the 
getmntopts(3)
man page as well. Will do in a later commit after doing a relase build test.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libutil/getmntopts.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/getmntopts.3
diff -u src/lib/libutil/getmntopts.3:1.12 src/lib/libutil/getmntopts.3:1.13
--- src/lib/libutil/getmntopts.3:1.12	Tue Aug 24 12:05:01 2010
+++ src/lib/libutil/getmntopts.3	Thu Mar 30 19:41:41 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: getmntopts.3,v 1.12 2010/08/24 12:05:01 christos Exp $
+.\"	$NetBSD: getmntopts.3,v 1.13 2017/03/30 19:41:41 abhinav Exp $
 .\"
 .\" Copyright (c) 1994
 .\"	The Regents of the University of California.  All rights reserved.
@@ -33,7 +33,10 @@
 .Dt GETMNTOPTS 3
 .Os
 .Sh NAME
-.Nm getmntopts
+.Nm getmntopts ,
+.Nm getmntoptstr ,
+.Nm getmntoptnum ,
+.Nm freemntopts
 .Nd scan mount options
 .Sh LIBRARY
 .Lb libutil
@@ -181,7 +184,7 @@ returns
 .Pp
 The
 .Fn getmntoptnum
-returns the long value of the named option, if such a value was set in the
+function returns the long value of the named option, if such a value was set in the
 option string.
 If the value was not set, or could not be converted from a string to a
 long, then if the external integer value
@@ -197,7 +200,7 @@ returns \-1.
 .Pp
 The
 .Fn freemntopts
-frees the storage used by
+function frees the storage used by
 .Fn getmntopts .
 .Sh RETURN VALUES
 .Fn getmntopts



CVS commit: src/lib/libutil

2017-03-30 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Thu Mar 30 19:23:06 UTC 2017

Modified Files:
src/lib/libutil: getdiskrawname.3

Log Message:
Add getdiskcookedname to the NAME section
Fix couple of typos.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libutil/getdiskrawname.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/getdiskrawname.3
diff -u src/lib/libutil/getdiskrawname.3:1.2 src/lib/libutil/getdiskrawname.3:1.3
--- src/lib/libutil/getdiskrawname.3:1.2	Sun Apr  8 16:06:23 2012
+++ src/lib/libutil/getdiskrawname.3	Thu Mar 30 19:23:06 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: getdiskrawname.3,v 1.2 2012/04/08 16:06:23 wiz Exp $
+.\"	$NetBSD: getdiskrawname.3,v 1.3 2017/03/30 19:23:06 abhinav Exp $
 .\"
 .\" Copyright (c) 2012 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -32,7 +32,8 @@
 .Dt GETDISKRAWNAME 3
 .Os
 .Sh NAME
-.Nm getdiskrawname
+.Nm getdiskrawname ,
+.Nm getdiskcookedname
 .Nd get the the block/character device name for a disk
 .Sh LIBRARY
 .Lb libutil
@@ -47,13 +48,13 @@ The
 .Fn getdiskrawname
 function converts the
 .Fa name
-argument thar contains a path to a disk block device node to the
+argument that contains a path to a disk block device node to the
 path that contains the corresponding character device node.
 The
 .Fn getdiskcookedname
 function converts the
 .Fa name
-argument thar contains a path to a disk character device node to the
+argument that contains a path to a disk character device node to the
 path that contains the corresponding block device node.
 .Sh RETURN VALUES
 On success the absolute pathname of the underlying device node is returned.



CVS commit: src/lib/libutil

2017-03-22 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Mar 22 18:17:42 UTC 2017

Modified Files:
src/lib/libutil: parsedate.3 parsedate.y

Log Message:
parsedate.y:  meaningless KNF of a comment (no code changes)
parsedate.3:  add an item in BUGS noting the weirdness of "next"

The real purpose of this commit is to supply the following message
which should be used for the immediately previous commit, replacing
its commit message (the two are similar, but definitely not the
same).   With thanks to gdt@ for pointing out one of the (many) errors
in the previous message (and noting others I had already seen).



Make parsedate handle "12 noon" and "12 midnight" (including when the
time given is "12:00" or "12:00:00") - but only for exactly 12 o'clock.
"12:00:01" is am or pm, not noon or midnight.

"12 am" remains as an alias for "12 midnight", and "12 pm" for noon,
though both are strictly (pedanticly) invalid (and meaningless.)

Note that "12 midnight" (or "12 am") means 00:00:00 (ie: midnight at
the start of the day, not at the end.)


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/lib/libutil/parsedate.3
cvs rdiff -u -r1.31 -r1.32 src/lib/libutil/parsedate.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.3
diff -u src/lib/libutil/parsedate.3:1.23 src/lib/libutil/parsedate.3:1.24
--- src/lib/libutil/parsedate.3:1.23	Wed Mar 22 01:49:36 2017
+++ src/lib/libutil/parsedate.3	Wed Mar 22 18:17:42 2017
@@ -1,4 +1,4 @@
-.\" $NetBSD: parsedate.3,v 1.23 2017/03/22 01:49:36 kre Exp $
+.\" $NetBSD: parsedate.3,v 1.24 2017/03/22 18:17:42 kre Exp $
 .\"
 .\" Copyright (c) 2006 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -417,4 +417,16 @@ but late 16th century is a rough guide)
 are suspicious at best,
 and depending upon context,
 often just plain wrong.
+.It 6
+Despite what is stated above,
+.Dq next
+is actually 2.
+The input
+.Dq "next January" ,
+instead of producing a timestamp for January of the
+following year, produces one for January 2nd, of the
+current year.
+Use caution with
+.Dq next
+it rarely does what humans expect.
 .El

Index: src/lib/libutil/parsedate.y
diff -u src/lib/libutil/parsedate.y:1.31 src/lib/libutil/parsedate.y:1.32
--- src/lib/libutil/parsedate.y:1.31	Wed Mar 22 01:49:36 2017
+++ src/lib/libutil/parsedate.y	Wed Mar 22 18:17:42 2017
@@ -14,7 +14,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: parsedate.y,v 1.31 2017/03/22 01:49:36 kre Exp $");
+__RCSID("$NetBSD: parsedate.y,v 1.32 2017/03/22 18:17:42 kre Exp $");
 #endif
 
 #include 
@@ -659,14 +659,15 @@ RelVal(struct dateinfo *param, time_t v,
 	param->yyRel[i].yyRelVal = v;
 }
 
-
-/* Adjust year from a value that might be abbreviated, to a full value.
+/*
+ * Adjust year from a value that might be abbreviated, to a full value.
  * e.g. convert 70 to 1970.
  * Input Year is either:
  *  - A negative number, which means to use its absolute value (why?)
  *  - A number from 0 to 99, which means a year from 1900 to 1999, or
  *  - The actual year (>=100).
- * Returns the full year. */
+ * Returns the full year.
+ */
 static time_t
 AdjustYear(time_t Year)
 {



CVS commit: src/lib/libutil

2017-03-21 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Mar 22 01:49:37 UTC 2017

Modified Files:
src/lib/libutil: parsedate.3 parsedate.y

Log Message:
Make parsedate handle "12 noon" and "12 midnight" (including when
the time is "12:00" or "12:00:00) - but only for exactly 12 o'clock.
"12:00:01" is am or pm, not noon or midnight.

"12 am" remains as an alias for "12 midnight", and "12 pm" for midnight,
though both are strictly invalid (and meaningless.)

Note that "12 pm" means 00:00:00 (ie: midnight at the start of the
day, not at the end.)


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/lib/libutil/parsedate.3
cvs rdiff -u -r1.30 -r1.31 src/lib/libutil/parsedate.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.3
diff -u src/lib/libutil/parsedate.3:1.22 src/lib/libutil/parsedate.3:1.23
--- src/lib/libutil/parsedate.3:1.22	Fri Dec 23 06:01:41 2016
+++ src/lib/libutil/parsedate.3	Wed Mar 22 01:49:36 2017
@@ -1,4 +1,4 @@
-.\" $NetBSD: parsedate.3,v 1.22 2016/12/23 06:01:41 abhinav Exp $
+.\" $NetBSD: parsedate.3,v 1.23 2017/03/22 01:49:36 kre Exp $
 .\"
 .\" Copyright (c) 2006 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd December 7, 2015
+.Dd March 22, 2017
 .Dt PARSEDATE 3
 .Os
 .Sh NAME
@@ -393,9 +393,21 @@ otherwise
 years less than 100 mean 1900 +
 .Fa year .
 .It 3
+The
+.Fn parsedate
+function accepts
+.Dq "12 am"
+where
+.Dq "12 midnight"
+is correct, and similarly
+.Dq "12 pm"
+for
+.Dq "12 noon" .
+The correct forms are also accepted.
+.It 4
 There are various weird cases that are hard to explain,
 but are nevertheless considered correct.
-.It 4
+.It 5
 It is very hard to specify years BC,
 and in any case,
 conversions of times before the

Index: src/lib/libutil/parsedate.y
diff -u src/lib/libutil/parsedate.y:1.30 src/lib/libutil/parsedate.y:1.31
--- src/lib/libutil/parsedate.y:1.30	Wed Mar 22 00:59:06 2017
+++ src/lib/libutil/parsedate.y	Wed Mar 22 01:49:36 2017
@@ -14,7 +14,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: parsedate.y,v 1.30 2017/03/22 00:59:06 kre Exp $");
+__RCSID("$NetBSD: parsedate.y,v 1.31 2017/03/22 01:49:36 kre Exp $");
 #endif
 
 #include 
@@ -64,10 +64,10 @@ typedef enum _DSTMODE {
 } DSTMODE;
 
 /*
-**  Meridian:  am, pm, or 24-hour style.
+**  Meridian:  am, pm, or 24-hour style (plus "noon" and "midnight").
 */
 typedef enum _MERIDIAN {
-MERam, MERpm, MER24
+MERam, MERpm, MER24, MER_NOON, MER_MN
 } MERIDIAN;
 
 
@@ -191,22 +191,58 @@ at_number:
 
 time:
 	  tUNUMBER tMERIDIAN {
-		param->yyHour = $1;
 		param->yyMinutes = 0;
 		param->yySeconds = 0;
-		param->yyMeridian = $2;
+		if ($2 == MER_NOON || $2 == MER_MN) {
+			if ($1 == 12) {
+switch ($2) {
+case MER_NOON: param->yyHour = 12; break;
+case MER_MN  : param->yyHour = 0;  break;
+default:	/* impossible */;  break;
+}
+param->yyMeridian = MER24;
+			} else
+YYREJECT;
+		} else {
+			param->yyHour = $1;
+			param->yyMeridian = $2;
+		}
 	  }
 	| tUNUMBER ':' tUNUMBER o_merid {
-		param->yyHour = $1;
 		param->yyMinutes = $3;
 		param->yySeconds = 0;
-		param->yyMeridian = $4;
+		if ($4 == MER_NOON || $4 == MER_MN) {
+			if ($1 == 12 && $3 == 0) {
+switch ($4) {
+case MER_NOON: param->yyHour = 12; break;
+case MER_MN  : param->yyHour = 0;  break;
+default:	/* impossible */;  break;
+}
+param->yyMeridian = MER24;
+			} else
+YYREJECT;
+		} else {
+			param->yyHour = $1;
+			param->yyMeridian = $4;
+		}
 	  }
 	| tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid {
-		param->yyHour = $1;
 		param->yyMinutes = $3;
 		param->yySeconds = $5;
-		param->yyMeridian = $6;
+		if ($6 == MER_NOON || $6 == MER_MN) {
+			if ($1 == 12 && $3 == 0 && $5 == 0) {
+switch ($6) {
+case MER_NOON: param->yyHour = 12; break;
+case MER_MN  : param->yyHour = 0;  break;
+default:	/* impossible */;  break;
+}
+param->yyMeridian = MER24;
+			} else
+YYREJECT;
+		} else {
+			param->yyHour = $1;
+			param->yyMeridian = $6;
+		}
 	  }
 	| tUNUMBER ':' tUNUMBER ':' tUNUMBER '.' tUNUMBER {
 		param->yyHour = $1;
@@ -223,7 +259,16 @@ time:
 		/* Tues midnight --> Weds 00:00, midnight Tues -> Tues 00:00 */
 		if ($1 == 0 && param->yyHaveDay)
 			param->yyDayNumber++;
-	}
+	  }
+	| tUNUMBER tTIME {
+		if ($1 == 12 && ($2 == 0 || $2 == 12)) {
+			param->yyHour = $2;
+			param->yyMinutes = 0;
+			param->yySeconds = 0;
+			param->yyMeridian = MER24;
+		} else
+			YYREJECT;
+	  }
 ;
 
 time_numericzone:
@@ -362,6 +407,7 @@ number:
 o_merid:
 	  /* empty */		{ $$ = MER24; }
 	| tMERIDIAN		{ $$ = $1; }
+	| tTIME			{ $$ = $1 == 0 ? MER_MN : MER_NOON; }
 ;
 
 %%



CVS commit: src/lib/libutil

2017-03-21 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Mar 22 00:59:06 UTC 2017

Modified Files:
src/lib/libutil: parsedate.y

Log Message:
Fix PR lib/52101 -- 12:30 am is 00:30:00 and 12:30 pm is 12:30:00


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/lib/libutil/parsedate.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.y
diff -u src/lib/libutil/parsedate.y:1.29 src/lib/libutil/parsedate.y:1.30
--- src/lib/libutil/parsedate.y:1.29	Sun Jun 26 07:09:24 2016
+++ src/lib/libutil/parsedate.y	Wed Mar 22 00:59:06 2017
@@ -14,7 +14,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: parsedate.y,v 1.29 2016/06/26 07:09:24 kre Exp $");
+__RCSID("$NetBSD: parsedate.y,v 1.30 2017/03/22 00:59:06 kre Exp $");
 #endif
 
 #include 
@@ -654,7 +654,9 @@ Convert(
 
 tm.tm_sec = Seconds;
 tm.tm_min = Minutes;
-tm.tm_hour = Hours + (Meridian == MERpm ? 12 : 0);
+tm.tm_hour = ((Hours == 12 && Meridian != MER24) ? 0 : Hours) +
+	(Meridian == MERpm ? 12 : 0);
+
 tm.tm_mday = Day;
 tm.tm_mon = Month - 1;
 tm.tm_year = Year - 1900;



CVS commit: src/lib/libutil

2017-01-28 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Sun Jan 29 05:13:55 UTC 2017

Modified Files:
src/lib/libutil: opendisk.3

Log Message:
new lookup order will be in 7.1 before 8.0


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libutil/opendisk.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/opendisk.3
diff -u src/lib/libutil/opendisk.3:1.13 src/lib/libutil/opendisk.3:1.14
--- src/lib/libutil/opendisk.3:1.13	Tue Jun  7 11:20:45 2016
+++ src/lib/libutil/opendisk.3	Sun Jan 29 05:13:55 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: opendisk.3,v 1.13 2016/06/07 11:20:45 wiz Exp $
+.\"	$NetBSD: opendisk.3,v 1.14 2017/01/29 05:13:55 snj Exp $
 .\"
 .\" Copyright (c) 1997, 2001 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -184,7 +184,7 @@ function first appeared in
 The lookup order of
 .Fn opendisk
 was changed in
-.Nx 8
+.Nx 7.1
 to first look in
 .Pa /dev
 in order to avoid opening random files in the current working directory.



CVS commit: src/lib/libutil

2016-12-29 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Dec 29 18:30:55 UTC 2016

Modified Files:
src/lib/libutil: Makefile sockaddr_snprintf.c

Log Message:
Make this portable to other OSs


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/lib/libutil/Makefile
cvs rdiff -u -r1.13 -r1.14 src/lib/libutil/sockaddr_snprintf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/Makefile
diff -u src/lib/libutil/Makefile:1.79 src/lib/libutil/Makefile:1.80
--- src/lib/libutil/Makefile:1.79	Sun Apr 10 15:05:50 2016
+++ src/lib/libutil/Makefile	Thu Dec 29 13:30:55 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.79 2016/04/10 19:05:50 roy Exp $
+#	$NetBSD: Makefile,v 1.80 2016/12/29 18:30:55 christos Exp $
 #	@(#)Makefile	8.1 (Berkeley) 6/4/93
 
 USE_SHLIBDIR=	yes
@@ -35,6 +35,10 @@ MAN=	efun.3 \
 	snprintb.3 sockaddr_snprintf.3 stat_flags.3 strpct.3 ttyaction.3 \
 	ttymsg.3 util.3
 
+CPPFLAGS.sockaddr_snprintf.c+=-DHAVE_UTIL_H
+CPPFLAGS.sockaddr_snprintf.c+=-DHAVE_NETATALK_AT_H
+CPPFLAGS.sockaddr_snprintf.c+=-DHAVE_NET_IF_DL_H
+
 YPREFIX=__pd
 .PATH:	${NETBSDSRCDIR}/lib/libc/gen
 

Index: src/lib/libutil/sockaddr_snprintf.c
diff -u src/lib/libutil/sockaddr_snprintf.c:1.13 src/lib/libutil/sockaddr_snprintf.c:1.14
--- src/lib/libutil/sockaddr_snprintf.c:1.13	Wed Jun  1 18:58:52 2016
+++ src/lib/libutil/sockaddr_snprintf.c	Thu Dec 29 13:30:55 2016
@@ -1,7 +1,7 @@
-/*	$NetBSD: sockaddr_snprintf.c,v 1.13 2016/06/01 22:58:52 christos Exp $	*/
+/*	$NetBSD: sockaddr_snprintf.c,v 1.14 2016/12/29 18:30:55 christos Exp $	*/
 
 /*-
- * Copyright (c) 2004 The NetBSD Foundation, Inc.
+ * Copyright (c) 2004, 2016 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -28,26 +28,47 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: sockaddr_snprintf.c,v 1.13 2016/06/01 22:58:52 christos Exp $");
+__RCSID("$NetBSD: sockaddr_snprintf.c,v 1.14 2016/12/29 18:30:55 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
+#include 
 #include 
 #include 
 #include 
 
 #include 
+#ifdef HAVE_NETATALK_AT_H
 #include 
+#endif
+#ifdef HAVE_NET_IF_DL_H
 #include 
+#endif
 
 #include 
 #include 
 #include 
 #include 
+#ifdef HAVE_UTIL_H
 #include 
+#endif
+#ifdef HAVE_LIBUTIL_H
+#include 
+#endif
 #include 
 
+#ifdef BSD4_4
+# define SALEN(sa)	((sa)->sa ## _len)
+#else
+# define SALEN(sa)	((unsigned)sizeof(*sa))
+#endif
+
+#ifdef HAVE_NETATALK_AT_H
 static int
 debug_at(char *str, size_t len, const struct sockaddr_at *sat)
 {
@@ -56,19 +77,20 @@ debug_at(char *str, size_t len, const st
 	"sat_range.r_netrange.nr_phase=%u, "
 	"sat_range.r_netrange.nr_firstnet=%u, "
 	"sat_range.r_netrange.nr_lastnet=%u",
-	sat->sat_len, sat->sat_family, sat->sat_port,
+	SALEN(sat), sat->sat_family, sat->sat_port,
 	sat->sat_addr.s_net, sat->sat_addr.s_node,
 	sat->sat_range.r_netrange.nr_phase,
 	sat->sat_range.r_netrange.nr_firstnet,
 	sat->sat_range.r_netrange.nr_lastnet);
 }
+#endif
 
 static int
 debug_in(char *str, size_t len, const struct sockaddr_in *sin)
 {
 	return snprintf(str, len, "sin_len=%u, sin_family=%u, sin_port=%u, "
 	"sin_addr.s_addr=%08x",
-	sin->sin_len, sin->sin_family, sin->sin_port,
+	SALEN(sin), sin->sin_family, sin->sin_port,
 	sin->sin_addr.s_addr);
 }
 
@@ -81,7 +103,7 @@ debug_in6(char *str, size_t len, const s
 	"sin6_flowinfo=%u, "
 	"sin6_addr=%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:"
 	"%02x:%02x:%02x:%02x:%02x:%02x, sin6_scope_id=%u",
-	sin6->sin6_len, sin6->sin6_family, sin6->sin6_port,
+	SALEN(sin6), sin6->sin6_family, sin6->sin6_port,
 	sin6->sin6_flowinfo, s[0x0], s[0x1], s[0x2], s[0x3], s[0x4], s[0x5],
 	s[0x6], s[0x7], s[0x8], s[0x9], s[0xa], s[0xb], s[0xc], s[0xd],
 	s[0xe], s[0xf], sin6->sin6_scope_id);
@@ -91,10 +113,11 @@ static int
 debug_un(char *str, size_t len, const struct sockaddr_un *sun)
 {
 	return snprintf(str, len, "sun_len=%u, sun_family=%u, sun_path=%*s",
-	sun->sun_len, sun->sun_family, (int)sizeof(sun->sun_path),
+	SALEN(sun), sun->sun_family, (int)sizeof(sun->sun_path),
 	sun->sun_path);
 }
 
+#ifdef HAVE_NET_IF_DL_H
 static int
 debug_dl(char *str, size_t len, const struct sockaddr_dl *sdl)
 {
@@ -103,27 +126,34 @@ debug_dl(char *str, size_t len, const st
 	return snprintf(str, len, "sdl_len=%u, sdl_family=%u, sdl_index=%u, "
 	"sdl_type=%u, sdl_nlen=%u, sdl_alen=%u, sdl_slen=%u, sdl_data="
 	"%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
-	sdl->sdl_len, sdl->sdl_family, sdl->sdl_index,
+	SALEN(sdl), sdl->sdl_family, sdl->sdl_index,
 	sdl->sdl_type, 

CVS commit: src/lib/libutil

2016-06-26 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sun Jun 26 07:09:24 UTC 2016

Modified Files:
src/lib/libutil: parsedate.3 parsedate.y

Log Message:
Remove dawn/sunup/sunset/sundown (sunrise was never there...)
If 06:00 or 18:00 are wanted, just say "06:00" (etc).  If these
are ever added back, they really should determine location, and
calculate actual sunrise/sunset times for the location and date.
That's not likely to happen...


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/lib/libutil/parsedate.3
cvs rdiff -u -r1.28 -r1.29 src/lib/libutil/parsedate.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.3
diff -u src/lib/libutil/parsedate.3:1.20 src/lib/libutil/parsedate.3:1.21
--- src/lib/libutil/parsedate.3:1.20	Thu Dec 10 21:32:35 2015
+++ src/lib/libutil/parsedate.3	Sun Jun 26 07:09:24 2016
@@ -1,4 +1,4 @@
-.\" $NetBSD: parsedate.3,v 1.20 2015/12/10 21:32:35 wiz Exp $
+.\" $NetBSD: parsedate.3,v 1.21 2016/06/26 07:09:24 kre Exp $
 .\"
 .\" Copyright (c) 2006 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -131,11 +131,7 @@ The following words are recognized in En
 .Dv p.m. ,
 .Dv midnight ,
 .Dv mn ,
-.Dv noon ,
-.Dv dawn ,
-.Dv sunup ,
-.Dv sunset ,
-.Dv sundown .
+.Dv noon .
 .Pp
 The months:
 .Dv january ,

Index: src/lib/libutil/parsedate.y
diff -u src/lib/libutil/parsedate.y:1.28 src/lib/libutil/parsedate.y:1.29
--- src/lib/libutil/parsedate.y:1.28	Tue May  3 18:14:54 2016
+++ src/lib/libutil/parsedate.y	Sun Jun 26 07:09:24 2016
@@ -14,7 +14,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: parsedate.y,v 1.28 2016/05/03 18:14:54 kre Exp $");
+__RCSID("$NetBSD: parsedate.y,v 1.29 2016/06/26 07:09:24 kre Exp $");
 #endif
 
 #include 
@@ -587,10 +587,6 @@ static const TABLE TimeNames[] = {
 { "mn",		tTIME,		 0 },
 { "noon",		tTIME,		12 },
 { "midday",		tTIME,		12 },
-{ "dawn",		tTIME,		 6 },
-{ "sunup",		tTIME,		 6 },
-{ "sunset",		tTIME,		18 },
-{ "sundown",	tTIME,		18 },
 { NULL,		0,		 0 }
 };
 



CVS commit: src/lib/libutil

2016-06-07 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Tue Jun  7 11:20:45 UTC 2016

Modified Files:
src/lib/libutil: opendisk.3

Log Message:
Fix typo. Sort errors.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libutil/opendisk.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/opendisk.3
diff -u src/lib/libutil/opendisk.3:1.12 src/lib/libutil/opendisk.3:1.13
--- src/lib/libutil/opendisk.3:1.12	Mon Jun  6 17:50:19 2016
+++ src/lib/libutil/opendisk.3	Tue Jun  7 11:20:45 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: opendisk.3,v 1.12 2016/06/06 17:50:19 christos Exp $
+.\"	$NetBSD: opendisk.3,v 1.13 2016/06/07 11:20:45 wiz Exp $
 .\"
 .\" Copyright (c) 1997, 2001 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -116,7 +116,7 @@ and a suffix of
 .El
 .El
 .Pp
-If the above fails, than the original
+If the above fails, then the original
 .Fa path
 is tried using the following two variations:
 .Pp
@@ -150,6 +150,11 @@ may set
 .Va errno
 to one of the following values:
 .Bl -tag -width Er
+.It Bq Er EFAULT
+.Fa buf
+was the
+.Dv NULL
+pointer.
 .It Bq Er EINVAL
 .Dv O_CREAT
 was set in
@@ -157,11 +162,6 @@ was set in
 or
 .Xr getrawpartition 3
 didn't return a valid partition.
-.It Bq Er EFAULT
-.Fa buf
-was the
-.Dv NULL
-pointer.
 .El
 .Pp
 The



CVS commit: src/lib/libutil

2016-06-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jun  6 17:50:19 UTC 2016

Modified Files:
src/lib/libutil: opendisk.3 opendisk.c

Log Message:
PR/51216: Instead of trying to open files in the current working
directory first for paths that don't contain "/", first try the
/dev paths to avoid confusion with files in the working directory
that happen to match disk names.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/lib/libutil/opendisk.3
cvs rdiff -u -r1.13 -r1.14 src/lib/libutil/opendisk.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/opendisk.3
diff -u src/lib/libutil/opendisk.3:1.11 src/lib/libutil/opendisk.3:1.12
--- src/lib/libutil/opendisk.3:1.11	Wed Apr 30 09:10:52 2008
+++ src/lib/libutil/opendisk.3	Mon Jun  6 13:50:19 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: opendisk.3,v 1.11 2008/04/30 13:10:52 martin Exp $
+.\"	$NetBSD: opendisk.3,v 1.12 2016/06/06 17:50:19 christos Exp $
 .\"
 .\" Copyright (c) 1997, 2001 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd December 11, 2001
+.Dd June 6, 2016
 .Dt OPENDISK 3
 .Os
 .Sh NAME
@@ -71,20 +71,6 @@ are tried.
 attempts to open the following variations of
 .Fa path ,
 in order:
-.Bl -tag -width "/dev/rpathX"
-.It Pa path
-The pathname as given.
-.It Pa path Ns Em X
-.Fa path
-with a suffix of
-.Sq Em X ,
-where
-.Sq Em X
-represents the raw partition of the device, as determined by
-.Xr getrawpartition 3 ,
-usually
-.Dq c .
-.El
 .Pp
 If
 .Fa path
@@ -93,13 +79,12 @@ slash
 .Pq Dq / ,
 the following variations are attempted:
 .Pp
-.Bl -dash -offset indent
+.Bl -dash -compact
 .It
 If
 .Fa iscooked
 is zero:
-.Pp
-.Bl -tag -width "/dev/rpathX"
+.Bl -tag -compact -width "/dev/rpathX"
 .It Pa /dev/rpath
 .Fa path
 with a prefix of
@@ -116,7 +101,7 @@ and a suffix of
 If
 .Fa iscooked
 is non-zero:
-.Bl -tag -width "/dev/rpathX"
+.Bl -tag -compact -width "/dev/rpathX"
 .It Pa /dev/path
 .Fa path
 with a prefix of
@@ -130,6 +115,31 @@ and a suffix of
 (q.v.).
 .El
 .El
+.Pp
+If the above fails, than the original
+.Fa path
+is tried using the following two variations:
+.Pp
+.Bl -dash -compact
+.It
+The
+.Fa iscooked
+value is ignored:
+.Bl -tag -compact -width "/dev/rpathX"
+.It Pa path
+The pathname as given.
+.It Pa path Ns Em X
+.Fa path
+with a suffix of
+.Sq Em X ,
+where
+.Sq Em X
+represents the raw partition of the device, as determined by
+.Xr getrawpartition 3 ,
+usually
+.Dq c .
+.El
+.El
 .Sh RETURN VALUES
 An open file descriptor, or -1 if the
 .Xr open 2
@@ -170,3 +180,11 @@ The
 .Fn opendisk
 function first appeared in
 .Nx 1.3 .
+.Pp
+The lookup order of
+.Fn opendisk
+was changed in
+.Nx 8
+to first look in
+.Pa /dev
+in order to avoid opening random files in the current working directory.

Index: src/lib/libutil/opendisk.c
diff -u src/lib/libutil/opendisk.c:1.13 src/lib/libutil/opendisk.c:1.14
--- src/lib/libutil/opendisk.c:1.13	Mon Sep 29 17:04:52 2014
+++ src/lib/libutil/opendisk.c	Mon Jun  6 13:50:19 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: opendisk.c,v 1.13 2014/09/29 21:04:52 christos Exp $	*/
+/*	$NetBSD: opendisk.c,v 1.14 2016/06/06 17:50:19 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -35,13 +35,14 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: opendisk.c,v 1.13 2014/09/29 21:04:52 christos Exp $");
+__RCSID("$NetBSD: opendisk.c,v 1.14 2016/06/06 17:50:19 christos Exp $");
 #endif
 
 #include 
 
 #include 
 #include 
+#include 
 #include 
 #ifndef HAVE_NBTOOL_CONFIG_H
 #include 
@@ -52,48 +53,62 @@ __RCSID("$NetBSD: opendisk.c,v 1.13 2014
 #include 
 #include 
 
+static int __printflike(5, 6)
+opd(char *buf, size_t len, int (*ofn)(const char *, int, ...),
+int flags, const char *fmt, ...)
+{
+	va_list ap;
+
+	va_start(ap, fmt);
+	vsnprintf(buf, len, fmt, ap);
+	va_end(ap);
+
+	return (*ofn)(buf, flags, 0);
+}
+
 static int
 __opendisk(const char *path, int flags, char *buf, size_t buflen, int iscooked,
 	int (*ofn)(const char *, int, ...))
 {
-	int f, rawpart;
+	int f, part;
 
 	if (buf == NULL) {
 		errno = EFAULT;
-		return (-1);
+		return -1;
 	}
-	snprintf(buf, buflen, "%s", path);
 
 	if ((flags & O_CREAT) != 0) {
 		errno = EINVAL;
-		return (-1);
+		return -1;
 	}
 
-	rawpart = getrawpartition();
-	if (rawpart < 0)
-		return (-1);	/* sysctl(3) in getrawpartition sets errno */
-
-	f = ofn(buf, flags, 0);
-	if (f != -1 || errno != ENOENT)
-		return (f);
-
-	snprintf(buf, buflen, "%s%c", path, 'a' + rawpart);
-	f = ofn(buf, flags, 0);
-	if (f != -1 || errno != ENOENT)
-		return (f);
-
-	if (strchr(path, '/') != NULL)
-		return (-1);
+	part = getrawpartition();
+	if (part < 0)
+		return -1;	/* sysctl(3) in getrawpartition sets errno */
+	part += 'a';
+
+	/*
+	 * If we are passed a plain 

CVS commit: src/lib/libutil

2016-06-01 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jun  1 22:58:52 UTC 2016

Modified Files:
src/lib/libutil: sockaddr_snprintf.c

Log Message:
Use NULL instead of 0.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libutil/sockaddr_snprintf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/sockaddr_snprintf.c
diff -u src/lib/libutil/sockaddr_snprintf.c:1.12 src/lib/libutil/sockaddr_snprintf.c:1.13
--- src/lib/libutil/sockaddr_snprintf.c:1.12	Wed Apr  6 14:08:16 2016
+++ src/lib/libutil/sockaddr_snprintf.c	Wed Jun  1 18:58:52 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: sockaddr_snprintf.c,v 1.12 2016/04/06 18:08:16 christos Exp $	*/
+/*	$NetBSD: sockaddr_snprintf.c,v 1.13 2016/06/01 22:58:52 christos Exp $	*/
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: sockaddr_snprintf.c,v 1.12 2016/04/06 18:08:16 christos Exp $");
+__RCSID("$NetBSD: sockaddr_snprintf.c,v 1.13 2016/06/01 22:58:52 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include 
@@ -166,7 +166,7 @@ sockaddr_snprintf(char * const sbuf, con
 			sdl->sdl_index);
 		} else {
 			(void)strlcpy(abuf, link_ntoa(sdl), sizeof(abuf));
-			if ((w = strchr(addr, ':')) != 0) {
+			if ((w = strchr(addr, ':')) != NULL) {
 			*w++ = '\0';
 			addr = w;
 			}



CVS commit: src/lib/libutil

2016-05-03 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue May  3 18:14:55 UTC 2016

Modified Files:
src/lib/libutil: parsedate.y

Log Message:
Make relative date changes ("+ 2 months") etc, work a little more sanely.

OK christos@


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/lib/libutil/parsedate.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.y
diff -u src/lib/libutil/parsedate.y:1.27 src/lib/libutil/parsedate.y:1.28
--- src/lib/libutil/parsedate.y:1.27	Thu Dec 31 10:52:06 2015
+++ src/lib/libutil/parsedate.y	Tue May  3 18:14:54 2016
@@ -14,7 +14,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: parsedate.y,v 1.27 2015/12/31 10:52:06 dholland Exp $");
+__RCSID("$NetBSD: parsedate.y,v 1.28 2016/05/03 18:14:54 kre Exp $");
 #endif
 
 #include 
@@ -42,6 +42,8 @@ __RCSID("$NetBSD: parsedate.y,v 1.27 201
 #define HOUR(x)		((time_t)((x) * 60))
 #define SECSPERDAY	(24L * 60L * 60L)
 
+#define	MAXREL	16	/* hours mins secs days weeks months years - maybe twice each ...*/
+
 #define USE_LOCAL_TIME	9 /* special case for Convert() and yyTimezone */
 
 /*
@@ -88,8 +90,10 @@ struct dateinfo {
 	time_t	yySeconds;	/* Second of minute [0-60] */
 	time_t	yyYear;		/* Year, see also yyHaveFullYear */
 	MERIDIAN yyMeridian;	/* Interpret yyHour as AM/PM/24 hour clock */
-	time_t	yyRelMonth;
-	time_t	yyRelSeconds;
+	struct {
+		time_t	yyRelVal;
+		int	yyRelMonth;
+	} yyRel[MAXREL];
 };
 %}
 
@@ -309,21 +313,21 @@ date:
 rel:
 	  relunit
 	| relunit tAGO {
-		param->yyRelSeconds = -param->yyRelSeconds;
-		param->yyRelMonth = -param->yyRelMonth;
+		param->yyRel[param->yyHaveRel].yyRelVal =
+		-param->yyRel[param->yyHaveRel].yyRelVal;
 	  }
 ;
 
 relunit:
-	  tUNUMBER tMINUTE_UNIT	{ param->yyRelSeconds += $1 * $2 * 60L; }
-	| tSNUMBER tMINUTE_UNIT	{ param->yyRelSeconds += $1 * $2 * 60L; }
-	| tMINUTE_UNIT		{ param->yyRelSeconds += $1 * 60L; }
-	| tSNUMBER tSEC_UNIT	{ param->yyRelSeconds += $1; }
-	| tUNUMBER tSEC_UNIT	{ param->yyRelSeconds += $1; }
-	| tSEC_UNIT		{ param->yyRelSeconds++;  }
-	| tSNUMBER tMONTH_UNIT	{ param->yyRelMonth += $1 * $2; }
-	| tUNUMBER tMONTH_UNIT	{ param->yyRelMonth += $1 * $2; }
-	| tMONTH_UNIT		{ param->yyRelMonth += $1; }
+	  tUNUMBER tMINUTE_UNIT	{ RelVal(param, $1 * $2 * 60L, 0); }
+	| tSNUMBER tMINUTE_UNIT	{ RelVal(param, $1 * $2 * 60L, 0); }
+	| tMINUTE_UNIT		{ RelVal(param, $1 * 60L, 0); }
+	| tSNUMBER tSEC_UNIT	{ RelVal(param, $1, 0); }
+	| tUNUMBER tSEC_UNIT	{ RelVal(param, $1, 0); }
+	| tSEC_UNIT		{ RelVal(param, 1L, 0);  }
+	| tSNUMBER tMONTH_UNIT	{ RelVal(param, $1 * $2, 1); }
+	| tUNUMBER tMONTH_UNIT	{ RelVal(param, $1 * $2, 1); }
+	| tMONTH_UNIT		{ RelVal(param, $1, 1); }
 ;
 
 number:
@@ -362,6 +366,17 @@ o_merid:
 
 %%
 
+static short DaysInMonth[12] = {
+31, 28, 31, 30, 31, 30,
+31, 31, 30, 31, 30, 31
+};
+
+/*
+ * works with tm.tm_year (ie: rel to 1900)
+ */
+#define	isleap(yr)  (((yr) & 3) == 0 && (((yr) % 100) != 0 || \
+			((1900+(yr)) % 400) == 0))
+
 /* Month and day table. */
 static const TABLE MonthDayTable[] = {
 { "january",	tMONTH,  1 },
@@ -571,6 +586,7 @@ static const TABLE TimeNames[] = {
 { "midnight",	tTIME,		 0 },
 { "mn",		tTIME,		 0 },
 { "noon",		tTIME,		12 },
+{ "midday",		tTIME,		12 },
 { "dawn",		tTIME,		 6 },
 { "sunup",		tTIME,		 6 },
 { "sunset",		tTIME,		18 },
@@ -580,7 +596,6 @@ static const TABLE TimeNames[] = {
 
 
 
-
 /* ARGSUSED */
 static int
 yyerror(struct dateinfo *param, const char **inp, const char *s __unused)
@@ -588,6 +603,20 @@ yyerror(struct dateinfo *param, const ch
   return 0;
 }
 
+/*
+ * Save a relative value, if it fits
+ */
+static void
+RelVal(struct dateinfo *param, time_t v, int type)
+{
+	int i;
+
+	if ((i = param->yyHaveRel) >= MAXREL)
+		return;
+	param->yyRel[i].yyRelMonth = type;
+	param->yyRel[i].yyRelVal = v;
+}
+
 
 /* Adjust year from a value that might be abbreviated, to a full value.
  * e.g. convert 70 to 1970.
@@ -729,6 +758,7 @@ RelativeMonth(
 struct tm	tm;
 time_t	Month;
 time_t	Then;
+int		Day;
 
 if (RelMonth == 0)
 	return 0;
@@ -748,6 +778,9 @@ RelativeMonth(
 Month = 12 * (tm.tm_year + 1900) + tm.tm_mon + RelMonth;
 tm.tm_year = (Month / 12) - 1900;
 tm.tm_mon = Month % 12;
+if (tm.tm_mday > (Day = DaysInMonth[tm.tm_mon] +
+	((tm.tm_mon==1) ? isleap(tm.tm_year) : 0)))
+	tm.tm_mday = Day;
 errno = 0;
 Then = mktime();
 if (Then == -1 && errno != 0)
@@ -939,6 +972,7 @@ parsedate(const char *p, const time_t *n
 time_t		tod, rm;
 struct dateinfo	param;
 int			saved_errno;
+int			i;
 
 saved_errno = errno;
 errno = 0;
@@ -972,8 +1006,6 @@ parsedate(const char *p, const time_t *n
 param.yyMinutes = 0;
 param.yySeconds = 0;
 param.yyMeridian = MER24;
-param.yyRelSeconds = 0;
-param.yyRelMonth = 0;
 param.yyHaveDate = 

CVS commit: src/lib/libutil

2016-04-12 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Tue Apr 12 20:40:43 UTC 2016

Modified Files:
src/lib/libutil: pidfile.c

Log Message:
Removed botched debug left over.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libutil/pidfile.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/pidfile.c
diff -u src/lib/libutil/pidfile.c:1.13 src/lib/libutil/pidfile.c:1.14
--- src/lib/libutil/pidfile.c:1.13	Tue Apr 12 20:36:35 2016
+++ src/lib/libutil/pidfile.c	Tue Apr 12 20:40:43 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: pidfile.c,v 1.13 2016/04/12 20:36:35 roy Exp $	*/
+/*	$NetBSD: pidfile.c,v 1.14 2016/04/12 20:40:43 roy Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2016 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: pidfile.c,v 1.13 2016/04/12 20:36:35 roy Exp $");
+__RCSID("$NetBSD: pidfile.c,v 1.14 2016/04/12 20:40:43 roy Exp $");
 #endif
 
 #include 
@@ -193,7 +193,7 @@ pidfile_lock(const char *path)
 
 	/* If path has changed (no good reason), clean up the old pidfile. */
 	if (pidfile_fd != -1 && strcmp(pidfile_path, path) != 0)
-		r = pidfile_clean();
+		pidfile_clean();
 
 	if (pidfile_fd == -1) {
 		pidfile_fd = open(path,



CVS commit: src/lib/libutil

2016-04-12 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Tue Apr 12 20:36:35 UTC 2016

Modified Files:
src/lib/libutil: pidfile.c

Log Message:
Fix pidfile location path rules to match prior version.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libutil/pidfile.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/pidfile.c
diff -u src/lib/libutil/pidfile.c:1.12 src/lib/libutil/pidfile.c:1.13
--- src/lib/libutil/pidfile.c:1.12	Sun Apr 10 19:05:50 2016
+++ src/lib/libutil/pidfile.c	Tue Apr 12 20:36:35 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: pidfile.c,v 1.12 2016/04/10 19:05:50 roy Exp $	*/
+/*	$NetBSD: pidfile.c,v 1.13 2016/04/12 20:36:35 roy Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2016 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: pidfile.c,v 1.12 2016/04/10 19:05:50 roy Exp $");
+__RCSID("$NetBSD: pidfile.c,v 1.13 2016/04/12 20:36:35 roy Exp $");
 #endif
 
 #include 
@@ -139,13 +139,12 @@ pidfile_read(const char *path)
 	ssize_t n;
 	pid_t pid;
 
-	if (path == NULL) {
-		if (pidfile_path[0] != '\0')
-			path = pidfile_path;
-		else if (pidfile_varrun_path(dpath, sizeof(dpath), NULL) == -1)
+	if (path == NULL && pidfile_path[0] != '\0')
+		path = pidfile_path;
+	if (path == NULL || strchr(path, '/') == NULL) {
+		if (pidfile_varrun_path(dpath, sizeof(dpath), path) == -1)
 			return -1;
-		else
-			path = dpath;
+		path = dpath;
 	}
 
 	if ((fd = open(path, O_RDONLY | O_CLOEXEC | O_NONBLOCK)) == -1)
@@ -187,14 +186,14 @@ pidfile_lock(const char *path)
 	}
 
 	if (path == NULL || strchr(path, '/') == NULL) {
-		if (pidfile_varrun_path(dpath, sizeof(dpath), NULL) == -1)
+		if (pidfile_varrun_path(dpath, sizeof(dpath), path) == -1)
 			return -1;
 		path = dpath;
 	}
 
 	/* If path has changed (no good reason), clean up the old pidfile. */
-	if (strcmp(pidfile_path, path) != 0)
-		pidfile_cleanup();
+	if (pidfile_fd != -1 && strcmp(pidfile_path, path) != 0)
+		r = pidfile_clean();
 
 	if (pidfile_fd == -1) {
 		pidfile_fd = open(path,



CVS commit: src/lib/libutil

2016-04-11 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Mon Apr 11 08:49:57 UTC 2016

Modified Files:
src/lib/libutil: pidfile.3

Log Message:
Add serial commas. Fix minus. Sort SEE ALSO. Fix xref.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/lib/libutil/pidfile.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/pidfile.3
diff -u src/lib/libutil/pidfile.3:1.14 src/lib/libutil/pidfile.3:1.15
--- src/lib/libutil/pidfile.3:1.14	Sun Apr 10 19:05:50 2016
+++ src/lib/libutil/pidfile.3	Mon Apr 11 08:49:57 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: pidfile.3,v 1.14 2016/04/10 19:05:50 roy Exp $
+.\"	$NetBSD: pidfile.3,v 1.15 2016/04/11 08:49:57 wiz Exp $
 .\"
 .\" Copyright (c) 1999, 2016 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -98,7 +98,7 @@ and return the process ID it contains.
 .Fn pidfile_clean
 will
 .Xr ftruncate 2 ,
-.Xr close 2
+.Xr close 2 ,
 and
 .Xr unlink 2
 the last opening pid file if, and only if, the current process wrote it.
@@ -109,15 +109,15 @@ This function should be called if the pr
 .Fn pidfile
 and
 .Fn pidfile_clean
-returns 0 on success and -1 on failure.
+returns 0 on success and \-1 on failure.
 .Pp
 .Fn pidfile_lock
 returns 0 on success.
 Otherwise, the process ID who owns the lock is returned and if that
-cannot be derived then -1 is returned.
+cannot be derived then \-1 is returned.
 .Pp
 .Fn pidfile_read
-returns the process ID if known, otherwise -1.
+returns the process ID if known, otherwise \-1.
 .Sh ERRORS
 The
 .Fn pidfile
@@ -132,8 +132,8 @@ daemon is already running.
 Specified pidfile's name is too long.
 .El
 .Sh SEE ALSO
-.Xr atexit 3 ,
-.Xr flock 2
+.Xr flock 2 ,
+.Xr atexit 3
 .Sh HISTORY
 The
 .Fn pidfile
@@ -144,7 +144,7 @@ Support for creating pid files in any ar
 .Pp
 The
 .Fn pidfile_lock ,
-.Fn pidfile_read
+.Fn pidfile_read ,
 and
 .Fn pidfile_clean
 function calls appeared in
@@ -160,11 +160,11 @@ However, programs that use the
 .Xr _exit 2
 function (for example, in signal handlers)
 will not trigger this behaviour and should call
-.Xr pidfile_clean.
+.Fn pidfile_clean .
 Like-wise, if the program creates a pid file before
 .Xr fork 2 Ns ing
 a child to take over, it should use the
 .Xr _exit 2
 function instead of returning or using the
-.Xr exit 2
+.Xr exit 3
 function to ensure the pid file is not cleaned.



CVS commit: src/lib/libutil

2016-04-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Apr  6 18:08:16 UTC 2016

Modified Files:
src/lib/libutil: sockaddr_snprintf.c

Log Message:
pretty-print link addresses.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/lib/libutil/sockaddr_snprintf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/sockaddr_snprintf.c
diff -u src/lib/libutil/sockaddr_snprintf.c:1.11 src/lib/libutil/sockaddr_snprintf.c:1.12
--- src/lib/libutil/sockaddr_snprintf.c:1.11	Tue Dec 31 07:58:02 2013
+++ src/lib/libutil/sockaddr_snprintf.c	Wed Apr  6 14:08:16 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: sockaddr_snprintf.c,v 1.11 2013/12/31 12:58:02 mlelstv Exp $	*/
+/*	$NetBSD: sockaddr_snprintf.c,v 1.12 2016/04/06 18:08:16 christos Exp $	*/
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: sockaddr_snprintf.c,v 1.11 2013/12/31 12:58:02 mlelstv Exp $");
+__RCSID("$NetBSD: sockaddr_snprintf.c,v 1.12 2016/04/06 18:08:16 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include 
@@ -159,10 +159,17 @@ sockaddr_snprintf(char * const sbuf, con
 		break;
 	case AF_LINK:
 		sdl = ((const struct sockaddr_dl *)(const void *)sa);
-		(void)strlcpy(addr = abuf, link_ntoa(sdl), sizeof(abuf));
-		if ((w = strchr(addr, ':')) != 0) {
-			*w++ = '\0';
-			addr = w;
+		addr = abuf;
+		if (sdl->sdl_slen == 0 && sdl->sdl_nlen == 0
+		&& sdl->sdl_alen == 0) {
+			(void)snprintf(abuf, sizeof(abuf), "link#%hu",
+			sdl->sdl_index);
+		} else {
+			(void)strlcpy(abuf, link_ntoa(sdl), sizeof(abuf));
+			if ((w = strchr(addr, ':')) != 0) {
+			*w++ = '\0';
+			addr = w;
+			}
 		}
 		break;
 	default:



CVS commit: src/lib/libutil

2016-01-25 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jan 25 18:14:04 UTC 2016

Modified Files:
src/lib/libutil: getbootfile.c

Log Message:
prefer  instead of 


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libutil/getbootfile.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/getbootfile.c
diff -u src/lib/libutil/getbootfile.c:1.5 src/lib/libutil/getbootfile.c:1.6
--- src/lib/libutil/getbootfile.c:1.5	Mon Apr 28 16:23:02 2008
+++ src/lib/libutil/getbootfile.c	Mon Jan 25 13:14:04 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: getbootfile.c,v 1.5 2008/04/28 20:23:02 martin Exp $	*/
+/*	$NetBSD: getbootfile.c,v 1.6 2016/01/25 18:14:04 christos Exp $	*/
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -31,12 +31,12 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getbootfile.c,v 1.5 2008/04/28 20:23:02 martin Exp $");
+__RCSID("$NetBSD: getbootfile.c,v 1.6 2016/01/25 18:14:04 christos Exp $");
 #endif
 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 



CVS commit: src/lib/libutil

2015-12-31 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Dec 31 09:12:58 UTC 2015

Modified Files:
src/lib/libutil: parsedate.y

Log Message:
Reformat grammar part according to my standards for yacc grammars.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/lib/libutil/parsedate.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.y
diff -u src/lib/libutil/parsedate.y:1.24 src/lib/libutil/parsedate.y:1.25
--- src/lib/libutil/parsedate.y:1.24	Tue Dec  8 12:51:04 2015
+++ src/lib/libutil/parsedate.y	Thu Dec 31 09:12:57 2015
@@ -14,7 +14,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: parsedate.y,v 1.24 2015/12/08 12:51:04 christos Exp $");
+__RCSID("$NetBSD: parsedate.y,v 1.25 2015/12/31 09:12:57 dholland Exp $");
 #endif
 
 #include 
@@ -103,7 +103,10 @@ struct dateinfo {
 
 %type		tDAY tDAYZONE tMINUTE_UNIT tMONTH tMONTH_UNIT
 %type		tSEC_UNIT tSNUMBER tUNUMBER tZONE tTIME
-%type		tMERIDIAN o_merid
+%type		tMERIDIAN
+
+%type		at_number
+%type		o_merid
 
 %parse-param	{ struct dateinfo *param }
 %parse-param 	{ const char **yyInput }
@@ -112,289 +115,250 @@ struct dateinfo {
 
 %%
 
-spec	: /* NULL */
+spec:
+	  /* empty */
 	| spec item
-	;
+;
 
-item	: time {
-	param->yyHaveTime++;
-	}
-	| time_numericzone {
-	param->yyHaveTime++;
-	param->yyHaveZone++;
-	}
-	| zone {
-	param->yyHaveZone++;
-	}
-	| date {
-	param->yyHaveDate++;
-	}
-	| day {
-	param->yyHaveDay++;
-	}
-	| rel {
-	param->yyHaveRel++;
-	}
-	| cvsstamp {
-	param->yyHaveTime++;
-	param->yyHaveDate++;
-	param->yyHaveZone++;
-	}
-	| epochdate {
-	param->yyHaveTime++;
-	param->yyHaveDate++;
-	param->yyHaveZone++;
-	}
+item:
+	  time			{ param->yyHaveTime++; }
+	| time_numericzone	{ param->yyHaveTime++; param->yyHaveZone++; }
+	| zone			{ param->yyHaveZone++; }
+	| date			{ param->yyHaveDate++; }
+	| day			{ param->yyHaveDay++; }
+	| rel			{ param->yyHaveRel++; }
+	| cvsstamp		{ param->yyHaveTime++; param->yyHaveDate++;
+  param->yyHaveZone++; }
+	| epochdate		{ param->yyHaveTime++; param->yyHaveDate++; 
+  param->yyHaveZone++; }
 	| number
-	;
-
-cvsstamp: tUNUMBER '.' tUNUMBER '.' tUNUMBER '.' tUNUMBER '.' tUNUMBER '.' tUNUMBER {
-	param->yyYear = $1;
-	if (param->yyYear < 100) param->yyYear += 1900;
-	param->yyHaveFullYear = 1;
-	param->yyMonth = $3;
-	param->yyDay = $5;
-	param->yyHour = $7;
-	param->yyMinutes = $9;
-	param->yySeconds = $11;
-	param->yyDSTmode = DSToff;
-	param->yyTimezone = 0;
-	}
-	;
+;
 
-epochdate: AT_SIGN at_number {
-time_twhen = $2;
-struct tm tmbuf;
-if (gmtime_r(, ) != NULL) {
-		param->yyYear = tmbuf.tm_year + 1900;
-		param->yyMonth = tmbuf.tm_mon + 1;
-		param->yyDay = tmbuf.tm_mday;
-
-		param->yyHour = tmbuf.tm_hour;
-		param->yyMinutes = tmbuf.tm_min;
-		param->yySeconds = tmbuf.tm_sec;
-	} else {
-		param->yyYear = EPOCH;
-		param->yyMonth = 1;
-		param->yyDay = 1;
+cvsstamp:
+	tUNUMBER '.' tUNUMBER '.' tUNUMBER '.' 
+tUNUMBER '.' tUNUMBER '.' tUNUMBER {
+		param->yyYear = $1;
+		if (param->yyYear < 100) {
+			param->yyYear += 1900;
+		}
+		param->yyHaveFullYear = 1;
+		param->yyMonth = $3;
+		param->yyDay = $5;
+		param->yyHour = $7;
+		param->yyMinutes = $9;
+		param->yySeconds = $11;
+		param->yyDSTmode = DSToff;
+		param->yyTimezone = 0;
+	}
+;
+
+epochdate:
+	AT_SIGN at_number {
+		time_t	when = $2;
+		struct tm tmbuf;
+
+		if (gmtime_r(, ) != NULL) {
+			param->yyYear = tmbuf.tm_year + 1900;
+			param->yyMonth = tmbuf.tm_mon + 1;
+			param->yyDay = tmbuf.tm_mday;
+
+			param->yyHour = tmbuf.tm_hour;
+			param->yyMinutes = tmbuf.tm_min;
+			param->yySeconds = tmbuf.tm_sec;
+		} else {
+			param->yyYear = EPOCH;
+			param->yyMonth = 1;
+			param->yyDay = 1;
 
-		param->yyHour = 0;
+			param->yyHour = 0;
+			param->yyMinutes = 0;
+			param->yySeconds = 0;
+		}
+		param->yyHaveFullYear = 1;
+		param->yyDSTmode = DSToff;
+		param->yyTimezone = 0;
+	}
+;
+
+at_number:
+	  tUNUMBER
+	| tSNUMBER
+;
+
+time:
+	  tUNUMBER tMERIDIAN {
+		param->yyHour = $1;
 		param->yyMinutes = 0;
 		param->yySeconds = 0;
-	}
-	param->yyHaveFullYear = 1;
-	param->yyDSTmode = DSToff;
-	param->yyTimezone = 0;
-	}
-	;
-
-at_number : tUNUMBER | tSNUMBER ;
-
-time	: tUNUMBER tMERIDIAN {
-	param->yyHour = $1;
-	param->yyMinutes = 0;
-	param->yySeconds = 0;
-	param->yyMeridian = $2;
-	}
+		param->yyMeridian = $2;
+	  }
 	| tUNUMBER ':' tUNUMBER o_merid {
-	param->yyHour = $1;
-	param->yyMinutes = $3;
-	param->yySeconds = 0;
-	param->yyMeridian = $4;
-	}
+		param->yyHour = $1;
+		param->yyMinutes = $3;
+		param->yySeconds = 0;
+		param->yyMeridian = $4;
+	  }
 	| tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid {
-	param->yyHour = $1;
-	param->yyMinutes = $3;
-	param->yySeconds = $5;
-	

CVS commit: src/lib/libutil

2015-12-31 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Dec 31 10:52:06 UTC 2015

Modified Files:
src/lib/libutil: parsedate.y

Log Message:
When computing relative months, use mktime() directly and don't call
our Convert(). And check it for failure. This fixes three sets of
problems:

  (1) depending on the passed-in value of Timezone it might
  disassemble the time in one timezone and reassemble it in
  another, causing mysterious offsets of a few hours;

  (2) with the previous set of changes to this file, Convert() fails
  if it ends up normalizing a date, so e.g. going three months
  forward from March 31 would fail;

  (3) previously if Convert() failed we passed -1 on to DSTcorrect(),
  which made a mess.

PR 50574.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/lib/libutil/parsedate.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.y
diff -u src/lib/libutil/parsedate.y:1.26 src/lib/libutil/parsedate.y:1.27
--- src/lib/libutil/parsedate.y:1.26	Thu Dec 31 10:31:07 2015
+++ src/lib/libutil/parsedate.y	Thu Dec 31 10:52:06 2015
@@ -14,7 +14,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: parsedate.y,v 1.26 2015/12/31 10:31:07 dholland Exp $");
+__RCSID("$NetBSD: parsedate.y,v 1.27 2015/12/31 10:52:06 dholland Exp $");
 #endif
 
 #include 
@@ -728,19 +728,31 @@ RelativeMonth(
 {
 struct tm	tm;
 time_t	Month;
-time_t	Year;
+time_t	Then;
 
 if (RelMonth == 0)
 	return 0;
+/*
+ * It doesn't matter what timezone we use to do this computation,
+ * as long as we use the same one to reassemble the time that we
+ * used to disassemble it. So always use localtime and mktime. In
+ * particular, don't use Convert() to reassemble, because it will
+ * not only reassemble with the wrong timezone but it will also
+ * fail if we do e.g. three months from March 31 yielding July 1.
+ */
+(void)Timezone;
+
 if (localtime_r(, ) == NULL)
 	return -1;
+
 Month = 12 * (tm.tm_year + 1900) + tm.tm_mon + RelMonth;
-Year = Month / 12;
-Month = Month % 12 + 1;
-return DSTcorrect(Start,
-	Convert(Month, (time_t)tm.tm_mday, Year,
-		(time_t)tm.tm_hour, (time_t)tm.tm_min, (time_t)tm.tm_sec,
-		Timezone, MER24, DSTmaybe));
+tm.tm_year = (Month / 12) - 1900;
+tm.tm_mon = Month % 12;
+errno = 0;
+Then = mktime();
+if (Then == -1 && errno != 0)
+	return -1;
+return DSTcorrect(Start, Then);
 }
 
 



CVS commit: src/lib/libutil

2015-12-31 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Dec 31 10:31:07 UTC 2015

Modified Files:
src/lib/libutil: parsedate.y

Log Message:
Always use localtime_r; I don't think any of this code is tripping
itself up, but it's still good practice for library functions to not
trash static libc state. Might be relevant to PR 50574.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/lib/libutil/parsedate.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.y
diff -u src/lib/libutil/parsedate.y:1.25 src/lib/libutil/parsedate.y:1.26
--- src/lib/libutil/parsedate.y:1.25	Thu Dec 31 09:12:57 2015
+++ src/lib/libutil/parsedate.y	Thu Dec 31 10:31:07 2015
@@ -14,7 +14,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: parsedate.y,v 1.25 2015/12/31 09:12:57 dholland Exp $");
+__RCSID("$NetBSD: parsedate.y,v 1.26 2015/12/31 10:31:07 dholland Exp $");
 #endif
 
 #include 
@@ -686,15 +686,15 @@ DSTcorrect(
 {
 time_t	StartDay;
 time_t	FutureDay;
-struct tm  *tm;
+struct tm	tm;
 
-if ((tm = localtime()) == NULL)
+if (localtime_r(, ) == NULL)
 	return -1;
-StartDay = (tm->tm_hour + 1) % 24;
+StartDay = (tm.tm_hour + 1) % 24;
 
-if ((tm = localtime()) == NULL)
+if (localtime_r(, ) == NULL)
 	return -1;
-FutureDay = (tm->tm_hour + 1) % 24;
+FutureDay = (tm.tm_hour + 1) % 24;
 
 return (Future - Start) + (StartDay - FutureDay) * 60L * 60L;
 }
@@ -707,14 +707,13 @@ RelativeDate(
 time_t	DayNumber
 )
 {
-struct tm	*tm;
+struct tm	tm;
 time_t	now;
 
 now = Start;
-tm = localtime();
-if (tm == NULL)
+if (localtime_r(, ) == NULL)
 	return -1;
-now += SECSPERDAY * ((DayNumber - tm->tm_wday + 7) % 7);
+now += SECSPERDAY * ((DayNumber - tm.tm_wday + 7) % 7);
 now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1);
 return DSTcorrect(Start, now);
 }
@@ -727,21 +726,20 @@ RelativeMonth(
 time_t	Timezone
 )
 {
-struct tm	*tm;
+struct tm	tm;
 time_t	Month;
 time_t	Year;
 
 if (RelMonth == 0)
 	return 0;
-tm = localtime();
-if (tm == NULL)
+if (localtime_r(, ) == NULL)
 	return -1;
-Month = 12 * (tm->tm_year + 1900) + tm->tm_mon + RelMonth;
+Month = 12 * (tm.tm_year + 1900) + tm.tm_mon + RelMonth;
 Year = Month / 12;
 Month = Month % 12 + 1;
 return DSTcorrect(Start,
-	Convert(Month, (time_t)tm->tm_mday, Year,
-		(time_t)tm->tm_hour, (time_t)tm->tm_min, (time_t)tm->tm_sec,
+	Convert(Month, (time_t)tm.tm_mday, Year,
+		(time_t)tm.tm_hour, (time_t)tm.tm_min, (time_t)tm.tm_sec,
 		Timezone, MER24, DSTmaybe));
 }
 



CVS commit: src/lib/libutil

2015-12-10 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Thu Dec 10 21:32:35 UTC 2015

Modified Files:
src/lib/libutil: parsedate.3

Log Message:
Markup improvements.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/lib/libutil/parsedate.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.3
diff -u src/lib/libutil/parsedate.3:1.19 src/lib/libutil/parsedate.3:1.20
--- src/lib/libutil/parsedate.3:1.19	Tue Dec  8 12:51:21 2015
+++ src/lib/libutil/parsedate.3	Thu Dec 10 21:32:35 2015
@@ -1,4 +1,4 @@
-.\" $NetBSD: parsedate.3,v 1.19 2015/12/08 12:51:21 christos Exp $
+.\" $NetBSD: parsedate.3,v 1.20 2015/12/10 21:32:35 wiz Exp $
 .\"
 .\" Copyright (c) 2006 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -74,32 +74,54 @@ The following words have the indicated n
 \-1,
 .Dv this =
 0,
-.Dv first, next, or one =
+.Dv first , next ,
+or
+.Dv one =
 1,
 .Dv second
 is unused so that it is not confused with
 .Dq seconds ,
 .Dv two =
 2,
-.Dv third or three =
+.Dv third
+or
+.Dv three =
 3,
-.Dv fourth or four =
+.Dv fourth
+or
+.Dv four =
 4,
-.Dv fifth or five  =
+.Dv fifth
+or
+.Dv five  =
 5,
-.Dv sixth or six  =
+.Dv sixth
+or
+.Dv six  =
 6,
-.Dv seventh or seven =
+.Dv seventh
+or
+.Dv seven =
 7,
-.Dv eighth or eight =
+.Dv eighth
+or
+.Dv eight =
 8,
-.Dv ninth or nine =
+.Dv ninth
+or
+.Dv nine =
 9,
-.Dv tenth or ten =
+.Dv tenth
+or
+.Dv ten =
 10,
-.Dv eleventh or eleven =
+.Dv eleventh
+or
+.Dv eleven =
 11,
-.Dv twelfth or twelve =
+.Dv twelfth
+or
+.Dv twelve =
 12.
 .Pp
 The following words are recognized in English only:
@@ -275,9 +297,9 @@ Relative items are also supported:
 Note that, as a special case for
 .Dv midnight
 with the name of a day only,
-.Dv "midnight tuesday"
+.Dq "midnight tuesday"
 implies 00:00 at the beginning of Tuesday, whereas
-.Dv "Sat mn"
+.Dq "Sat mn"
 implies 00:00 at the end of Saturday (i.e. early Sunday morning.)
 .Pp
 Seconds since epoch, UTC, (also known as UNIX time) are also supported:



CVS commit: src/lib/libutil

2015-12-08 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Dec  8 12:51:21 UTC 2015

Modified Files:
src/lib/libutil: parsedate.3

Log Message:
more changes I forgot to commit


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/lib/libutil/parsedate.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.3
diff -u src/lib/libutil/parsedate.3:1.18 src/lib/libutil/parsedate.3:1.19
--- src/lib/libutil/parsedate.3:1.18	Mon Dec  7 15:55:49 2015
+++ src/lib/libutil/parsedate.3	Tue Dec  8 07:51:21 2015
@@ -1,4 +1,4 @@
-.\" $NetBSD: parsedate.3,v 1.18 2015/12/07 20:55:49 christos Exp $
+.\" $NetBSD: parsedate.3,v 1.19 2015/12/08 12:51:21 christos Exp $
 .\"
 .\" Copyright (c) 2006 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -198,11 +198,11 @@ Timezone names:
 .Dv zp5 (+0500) ,
 .Dv ist (+0550) ,
 .Dv zp6 (+0600) ,
-.Dv wast (+0700) ,
-.Dv wadt (+0800) ,
-.Dv awst (+0700) ,
-.Dv awdt (+0800) ,
 .Dv ict (+0700) ,
+.Dv wast (+0800) ,
+.Dv wadt (+0900) ,
+.Dv awst (+0800) ,
+.Dv awdt (+0900) ,
 .Dv cct (+0800) ,
 .Dv sgt (+0800) ,
 .Dv hkt (+0800) ,
@@ -272,6 +272,14 @@ Relative items are also supported:
 .It +2 years
 .El
 .Pp
+Note that, as a special case for
+.Dv midnight
+with the name of a day only,
+.Dv "midnight tuesday"
+implies 00:00 at the beginning of Tuesday, whereas
+.Dv "Sat mn"
+implies 00:00 at the end of Saturday (i.e. early Sunday morning.)
+.Pp
 Seconds since epoch, UTC, (also known as UNIX time) are also supported:
 .Bl -tag -compact -width "@735275209"
 .It @735275209



CVS commit: src/lib/libutil

2015-12-08 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Dec  8 12:51:04 UTC 2015

Modified Files:
src/lib/libutil: parsedate.y

Log Message:
preserve a copy of the tm so we can check later.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/lib/libutil/parsedate.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.y
diff -u src/lib/libutil/parsedate.y:1.23 src/lib/libutil/parsedate.y:1.24
--- src/lib/libutil/parsedate.y:1.23	Mon Dec  7 15:55:49 2015
+++ src/lib/libutil/parsedate.y	Tue Dec  8 07:51:04 2015
@@ -14,7 +14,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: parsedate.y,v 1.23 2015/12/07 20:55:49 christos Exp $");
+__RCSID("$NetBSD: parsedate.y,v 1.24 2015/12/08 12:51:04 christos Exp $");
 #endif
 
 #include 
@@ -675,10 +675,12 @@ Convert(
 	case DSToff: tm.tm_isdst = 0; break;
 	default: tm.tm_isdst = -1; break;
 	}
+	otm = tm;
 	result = mktime();
 } else {
 	/* We rely on mktime_z(NULL, ...) working in UTC */
 	tm.tm_isdst = 0;	/* hence cannot be summer time */
+	otm = tm;
 	errno = 0;
 	result = mktime_z(NULL, );
 	if (result != -1 || errno == 0) {



CVS commit: src/lib/libutil

2015-12-07 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Dec  7 20:55:49 UTC 2015

Modified Files:
src/lib/libutil: parsedate.3 parsedate.y

Log Message:
- Add support for "midnight" "noon", dawn etc.
- Add validation to date/time strings by checking that mktime did not change
  the fields of struct tm from the ones requested
- Allow the format "year monthname day".
>From kre


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/lib/libutil/parsedate.3
cvs rdiff -u -r1.22 -r1.23 src/lib/libutil/parsedate.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.3
diff -u src/lib/libutil/parsedate.3:1.17 src/lib/libutil/parsedate.3:1.18
--- src/lib/libutil/parsedate.3:1.17	Thu Nov 26 04:48:21 2015
+++ src/lib/libutil/parsedate.3	Mon Dec  7 15:55:49 2015
@@ -1,4 +1,4 @@
-.\" $NetBSD: parsedate.3,v 1.17 2015/11/26 09:48:21 wiz Exp $
+.\" $NetBSD: parsedate.3,v 1.18 2015/12/07 20:55:49 christos Exp $
 .\"
 .\" Copyright (c) 2006 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd November 25, 2015
+.Dd December 7, 2015
 .Dt PARSEDATE 3
 .Os
 .Sh NAME
@@ -106,7 +106,14 @@ The following words are recognized in En
 .Dv AM ,
 .Dv PM ,
 .Dv a.m. ,
-.Dv p.m.
+.Dv p.m. ,
+.Dv midnight ,
+.Dv mn ,
+.Dv noon ,
+.Dv dawn ,
+.Dv sunup ,
+.Dv sunset ,
+.Dv sundown .
 .Pp
 The months:
 .Dv january ,
@@ -229,7 +236,7 @@ An ISO-8601 date.
 The year in an ISO-8601 date is always taken literally,
 so this is the year 69, not 2069.
 .It 10/1/2000
-October 10, 2000; the common US format.
+October 1, 2000; the common, but bizarre, US format.
 .It 20 Jun 1994
 .It 23jun2001
 .It 1-sep-06
@@ -253,6 +260,7 @@ As well as times:
 .It 12:11:01.12
 .It 12:21-0500
 .El
+Fractions of seconds (after a decimal point) are parsed, but ignored.
 .Pp
 Relative items are also supported:
 .Bl -tag -compact -width "this thursday"

Index: src/lib/libutil/parsedate.y
diff -u src/lib/libutil/parsedate.y:1.22 src/lib/libutil/parsedate.y:1.23
--- src/lib/libutil/parsedate.y:1.22	Sun Dec  6 09:43:59 2015
+++ src/lib/libutil/parsedate.y	Mon Dec  7 15:55:49 2015
@@ -14,7 +14,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: parsedate.y,v 1.22 2015/12/06 14:43:59 christos Exp $");
+__RCSID("$NetBSD: parsedate.y,v 1.23 2015/12/07 20:55:49 christos Exp $");
 #endif
 
 #include 
@@ -99,10 +99,10 @@ struct dateinfo {
 }
 
 %token	tAGO tDAY tDAYZONE tID tMERIDIAN tMINUTE_UNIT tMONTH tMONTH_UNIT
-%token	tSEC_UNIT tSNUMBER tUNUMBER tZONE tDST AT_SIGN
+%token	tSEC_UNIT tSNUMBER tUNUMBER tZONE tDST AT_SIGN tTIME
 
 %type		tDAY tDAYZONE tMINUTE_UNIT tMONTH tMONTH_UNIT
-%type		tSEC_UNIT tSNUMBER tUNUMBER tZONE
+%type		tSEC_UNIT tSNUMBER tUNUMBER tZONE tTIME
 %type		tMERIDIAN o_merid
 
 %parse-param	{ struct dateinfo *param }
@@ -215,6 +215,15 @@ time	: tUNUMBER tMERIDIAN {
 	param->yyMeridian = MER24;
 /* XXX: Do nothing with millis */
 	}
+	| tTIME {
+	param->yyHour = $1;
+	param->yyMinutes = 0;
+	param->yySeconds = 0;
+	param->yyMeridian = MER24;
+	/* Tues midnight --> Weds 00:00, midnight Tues -> Tues 00:00 */
+	if ($1 == 0 && param->yyHaveDay)
+	param->yyDayNumber++;
+	}
 	;
 
 time_numericzone : tUNUMBER ':' tUNUMBER tSNUMBER {
@@ -306,8 +315,13 @@ date	: tUNUMBER '/' tUNUMBER {
 	}
 	| tUNUMBER tMONTH tUNUMBER {
 	param->yyMonth = $2;
-	param->yyDay = $1;
-	param->yyYear = $3;
+	if ($1 < 35) {
+	param->yyDay = $1;
+	param->yyYear = $3;
+	} else {
+	param->yyDay = $3;
+	param->yyYear = $1;
+	}
 	}
 	;
 
@@ -589,6 +603,17 @@ static const TABLE MilitaryTable[] = {
 { NULL,	0,	0 }
 };
 
+static const TABLE TimeNames[] = {
+{ "midnight",	tTIME,		 0 },
+{ "mn",		tTIME,		 0 },
+{ "noon",		tTIME,		12 },
+{ "dawn",		tTIME,		 6 },
+{ "sunup",		tTIME,		 6 },
+{ "sunset",		tTIME,		18 },
+{ "sundown",	tTIME,		18 },
+{ NULL,		0,		 0 }
+};
+
 
 
 
@@ -635,6 +660,7 @@ Convert(
 )
 {
 struct tm tm = {.tm_sec = 0};
+struct tm otm;
 time_t result;
 
 tm.tm_sec = Seconds;
@@ -673,6 +699,15 @@ Convert(
 fprintf(stderr, " %s", ctime());
 #endif
 
+#define	TM_NE(fld) (otm.tm_ ## fld != tm.tm_ ## fld)
+if (TM_NE(year) || TM_NE(mon) || TM_NE(mday) ||
+	TM_NE(hour) || TM_NE(min) || TM_NE(sec)) {
+	/* mktime() "corrected" our tm, so it must have been invalid */
+	result = -1;
+	errno = EAGAIN;
+}
+#undef	TM_NE
+
 return result;
 }
 
@@ -800,6 +835,12 @@ LookupWord(YYSTYPE *yylval, char *buff)
 if (strcmp(buff, "dst") == 0) 
 	return tDST;
 
+for (tp = TimeNames; tp->name; tp++)
+	if (strcmp(buff, tp->name) == 0) {
+	yylval->Number = tp->value;
+	return tp->type;
+	}
+
 for (tp = UnitsTable; tp->name; tp++)
 	

CVS commit: src/lib/libutil

2015-12-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Dec  6 14:43:59 UTC 2015

Modified Files:
src/lib/libutil: parsedate.y

Log Message:
Fix west australia offset, from kre


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/lib/libutil/parsedate.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.y
diff -u src/lib/libutil/parsedate.y:1.21 src/lib/libutil/parsedate.y:1.22
--- src/lib/libutil/parsedate.y:1.21	Wed Nov 25 20:00:02 2015
+++ src/lib/libutil/parsedate.y	Sun Dec  6 09:43:59 2015
@@ -14,7 +14,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: parsedate.y,v 1.21 2015/11/26 01:00:02 christos Exp $");
+__RCSID("$NetBSD: parsedate.y,v 1.22 2015/12/06 14:43:59 christos Exp $");
 #endif
 
 #include 
@@ -531,14 +531,14 @@ static const TABLE TimezoneTable[] = {
 { "nst",	tZONE, -HOUR(6.5) },/* North Sumatra */
 { "sst",	tZONE, -HOUR(7) },	/* South Sumatra, USSR Zone 6 */
 #endif	/* 0 */
-{ "wast",	tZONE, -HOUR(7) },	/* West Australian Standard */
-{ "awst",	tZONE, -HOUR(7) },	/* West Australian Standard */
-{ "wadt",	tDAYZONE,  -HOUR(7) },	/* West Australian Daylight */
-{ "awdt",	tDAYZONE,  -HOUR(7) },	/* West Australian Daylight */
 { "ict",	tZONE, -HOUR(7) },	/* Indo China Time (Thai) */
 #if 0	/* this one looks to be bogus */
 { "jt",	tZONE, -HOUR(7.5) },/* Java (3pm in Cronusland!) */
 #endif
+{ "wast",	tZONE, -HOUR(8) },	/* West Australian Standard */
+{ "awst",	tZONE, -HOUR(8) },	/* West Australian Standard */
+{ "wadt",	tDAYZONE,  -HOUR(8) },	/* West Australian Daylight */
+{ "awdt",	tDAYZONE,  -HOUR(8) },	/* West Australian Daylight */
 { "cct",	tZONE, -HOUR(8) },	/* China Coast, USSR Zone 7 */
 { "sgt",	tZONE, -HOUR(8) },	/* Singapore */
 { "hkt",	tZONE, -HOUR(8) },	/* Hong Kong */



CVS commit: src/lib/libutil

2015-11-26 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Thu Nov 26 09:48:21 UTC 2015

Modified Files:
src/lib/libutil: parsedate.3

Log Message:
Sort sections. Mark up NULL. End Bl with El.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libutil/parsedate.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.3
diff -u src/lib/libutil/parsedate.3:1.16 src/lib/libutil/parsedate.3:1.17
--- src/lib/libutil/parsedate.3:1.16	Thu Nov 26 01:00:54 2015
+++ src/lib/libutil/parsedate.3	Thu Nov 26 09:48:21 2015
@@ -1,4 +1,4 @@
-.\" $NetBSD: parsedate.3,v 1.16 2015/11/26 01:00:54 christos Exp $
+.\" $NetBSD: parsedate.3,v 1.17 2015/11/26 09:48:21 wiz Exp $
 .\"
 .\" Copyright (c) 2006 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -291,17 +291,6 @@ There is no escape character in comments
 always ends
 (or decreases the nesting level of)
 the comment.
-.Sh ENVIRONMENT
-If the
-.Ar tzoff
-parameter is given as NULL,
-then:
-.Bl -tag -width iTZ
-.It Ev TZ
-The timezone to which the input is relative,
-when no zone information is otherwise specified in the
-.Ar datestr
-input.
 .Sh RETURN VALUES
 .Fn parsedate
 returns the number of seconds passed since,
@@ -320,6 +309,19 @@ before calling
 and checking the value of
 .Va errno
 afterwards.
+.Sh ENVIRONMENT
+If the
+.Ar tzoff
+parameter is given as
+.Dv NULL ,
+then:
+.Bl -tag -width iTZ
+.It Ev TZ
+The timezone to which the input is relative,
+when no zone information is otherwise specified in the
+.Ar datestr
+input.
+.El
 .Sh SEE ALSO
 .Xr date 1 ,
 .Xr touch 1 ,



CVS commit: src/lib/libutil

2015-11-25 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Nov 26 01:00:54 UTC 2015

Modified Files:
src/lib/libutil: parsedate.3

Log Message:
Fix documentation inconsistencies, and add some clarifications (from kre)


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/lib/libutil/parsedate.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.3
diff -u src/lib/libutil/parsedate.3:1.15 src/lib/libutil/parsedate.3:1.16
--- src/lib/libutil/parsedate.3:1.15	Wed Oct  8 18:10:04 2014
+++ src/lib/libutil/parsedate.3	Wed Nov 25 20:00:54 2015
@@ -1,4 +1,4 @@
-.\" $NetBSD: parsedate.3,v 1.15 2014/10/08 22:10:04 wiz Exp $
+.\" $NetBSD: parsedate.3,v 1.16 2015/11/26 01:00:54 christos Exp $
 .\"
 .\" Copyright (c) 2006 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd October 8, 2014
+.Dd November 25, 2015
 .Dt PARSEDATE 3
 .Os
 .Sh NAME
@@ -118,23 +118,20 @@ The months:
 .Dv july ,
 .Dv august ,
 .Dv september ,
-.Dv sept ,
 .Dv october ,
 .Dv november ,
 .Dv december ,
+and common abbreviations for them.
 .Pp
 The days of the week:
 .Dv sunday ,
 .Dv monday ,
 .Dv tuesday ,
-.Dv tues ,
 .Dv wednesday ,
-.Dv wednes ,
 .Dv thursday ,
-.Dv thur ,
-.Dv thurs ,
 .Dv friday ,
 .Dv saturday .
+and common abbreviations for them.
 .Pp
 Time units:
 .Dv year ,
@@ -151,60 +148,80 @@ Time units:
 .Dv yesterday .
 .Pp
 Timezone names:
-.Dv gmt ,
-.Dv ut ,
-.Dv utc ,
-.Dv wet ,
-.Dv bst ,
-.Dv wat ,
-.Dv at ,
-.Dv ast ,
-.Dv adt ,
-.Dv est ,
-.Dv edt ,
-.Dv cst ,
-.Dv cdt ,
-.Dv mst ,
-.Dv mdt ,
-.Dv pst ,
-.Dv pdt ,
-.Dv yst ,
-.Dv ydt ,
-.Dv hst ,
-.Dv hdt ,
-.Dv cat ,
-.Dv ahst ,
-.Dv nt ,
-.Dv idlw ,
-.Dv cet ,
-.Dv met ,
-.Dv mewt ,
-.Dv mest ,
-.Dv swt ,
-.Dv sst ,
-.Dv fwt ,
-.Dv fst ,
-.Dv eet ,
-.Dv bt ,
-.Dv zp4 ,
-.Dv zp5 ,
-.Dv zp6 ,
-.Dv wast ,
-.Dv wadt ,
-.Dv cct ,
-.Dv jst ,
-.Dv east ,
-.Dv eadt ,
-.Dv gst ,
-.Dv nzt ,
-.Dv nzst ,
-.Dv nzdt ,
-.Dv idle .
+.Dv gmt (+) ,
+.Dv ut (+) ,
+.Dv utc (+) ,
+.Dv wet (+) ,
+.Dv bst (+0100) ,
+.Dv wat (-0100) ,
+.Dv at (-0200) ,
+.Dv nft (-0330) ,
+.Dv nst (-0330) ,
+.Dv ndt (-0230) ,
+.Dv ast (-0400) ,
+.Dv adt (-0300) ,
+.Dv est (-0500) ,
+.Dv edt (-0400) ,
+.Dv cst (-0600) ,
+.Dv cdt (-0500) ,
+.Dv mst (-0700) ,
+.Dv mdt (-0600) ,
+.Dv pst (-0800) ,
+.Dv pdt (-0700) ,
+.Dv yst (-0900) ,
+.Dv ydt (-0800) ,
+.Dv hst (-1000) ,
+.Dv hdt (-0900) ,
+.Dv cat (-1000) ,
+.Dv ahst (-1000) ,
+.Dv nt (-1100) ,
+.Dv idlw (-1200) ,
+.Dv cet (+0100) ,
+.Dv met (+0100) ,
+.Dv mewt (+0100) ,
+.Dv mest (+0200) ,
+.Dv swt (+0100) ,
+.Dv sst (+0200) ,
+.Dv fwt (+0100) ,
+.Dv fst (+0200) ,
+.Dv eet (+0200) ,
+.Dv bt (+0300) ,
+.Dv it (+0330) ,
+.Dv zp4 (+0400) ,
+.Dv zp5 (+0500) ,
+.Dv ist (+0550) ,
+.Dv zp6 (+0600) ,
+.Dv wast (+0700) ,
+.Dv wadt (+0800) ,
+.Dv awst (+0700) ,
+.Dv awdt (+0800) ,
+.Dv ict (+0700) ,
+.Dv cct (+0800) ,
+.Dv sgt (+0800) ,
+.Dv hkt (+0800) ,
+.Dv jst (+0900) ,
+.Dv cast (+0930) ,
+.Dv cadt (+1030) ,
+.Dv acst (+0930) ,
+.Dv acst (+1030) ,
+.Dv east (+1000) ,
+.Dv eadt (+1100) ,
+.Dv aest (+1000) ,
+.Dv aedt (+1100) ,
+.Dv gst (+1000) ,
+.Dv nzt (+1200) ,
+.Dv nzst (+1200) ,
+.Dv nzdt (+1300) ,
+.Dv idle (+1200) .
+.Pp
+The timezone names specify an offset from Coordinated Universal Time (UTC)
+and do not imply validating the time/date to be reasonable in any zone
+that happens to use the abbreviation specified.
 .Pp
 A variety of unambiguous dates are recognized:
 .Bl -tag -compact -width "20 Jun 1994"
 .It 9/10/69
-For years between 69-99 we assume 1900+ and for years between 0-68
+For years between 70-99 we assume 1900+ and for years between 0-69
 we assume 2000+.
 .It 2006-11-17
 An ISO-8601 date.
@@ -222,6 +239,13 @@ The year can be omitted.
 This is the US month/day format.
 .El
 .Pp
+Standard e-mail (RFC822, RFC2822, etc)
+formats and the output from
+.Xr date 1 ,
+and
+.Xr asctime 3
+are all supported as input.
+.Pp
 As well as times:
 .Bl -tag -compact -width 12:11:01.12
 .It 10:01
@@ -240,14 +264,49 @@ Relative items are also supported:
 .It +2 years
 .El
 .Pp
-Seconds since epoch (also known as UNIX time) are also supported:
+Seconds since epoch, UTC, (also known as UNIX time) are also supported:
 .Bl -tag -compact -width "@735275209"
 .It @735275209
 Tue Apr 20 03:06:49 UTC 1993
 .El
+provided that the value given is within the range
+that can be represented as a
+.Va "struct tm" .
+Negative values
+(times before the epoch)
+are permitted, but no other significant data.
+.Pp
+Text in
+.Ar datestr
+enclosed in parentheses
+.Ql \&(
+and
+.Ql \&)
+is treated as a comment, and ignored.
+Parentheses nest (the comment ends when there have
+been the same number of closing parentheses as there
+were opening parentheses.)
+There is no escape character 

CVS commit: src/lib/libutil

2015-11-25 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Nov 26 01:00:02 UTC 2015

Modified Files:
src/lib/libutil: parsedate.y

Log Message:
Patch from kre:
- fix missing/inconsistent abbreviations
- set dst only if we are using localtime.
- properly check for errors where there were missing checks
- handle errno properly including saving and restoring.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/lib/libutil/parsedate.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.y
diff -u src/lib/libutil/parsedate.y:1.20 src/lib/libutil/parsedate.y:1.21
--- src/lib/libutil/parsedate.y:1.20	Wed Oct  8 13:38:28 2014
+++ src/lib/libutil/parsedate.y	Wed Nov 25 20:00:02 2015
@@ -14,7 +14,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: parsedate.y,v 1.20 2014/10/08 17:38:28 apb Exp $");
+__RCSID("$NetBSD: parsedate.y,v 1.21 2015/11/26 01:00:02 christos Exp $");
 #endif
 
 #include 
@@ -39,7 +39,7 @@ __RCSID("$NetBSD: parsedate.y,v 1.20 201
as it solves.  */
 
 #define EPOCH		1970
-#define HOUR(x)		((time_t)(x) * 60)
+#define HOUR(x)		((time_t)((x) * 60))
 #define SECSPERDAY	(24L * 60L * 60L)
 
 #define USE_LOCAL_TIME	9 /* special case for Convert() and yyTimezone */
@@ -400,16 +400,24 @@ static const TABLE MonthDayTable[] = {
 { "november",	tMONTH, 11 },
 { "december",	tMONTH, 12 },
 { "sunday",		tDAY, 0 },
+{ "su",		tDAY, 0 },
 { "monday",		tDAY, 1 },
+{ "mo",		tDAY, 1 },
 { "tuesday",	tDAY, 2 },
 { "tues",		tDAY, 2 },
+{ "tu",		tDAY, 2 },
 { "wednesday",	tDAY, 3 },
 { "wednes",		tDAY, 3 },
+{ "weds",		tDAY, 3 },
+{ "we",		tDAY, 3 },
 { "thursday",	tDAY, 4 },
-{ "thur",		tDAY, 4 },
 { "thurs",		tDAY, 4 },
+{ "thur",		tDAY, 4 },
+{ "th",		tDAY, 4 },
 { "friday",		tDAY, 5 },
+{ "fr",		tDAY, 5 },
 { "saturday",	tDAY, 6 },
+{ "sa",		tDAY, 6 },
 { NULL,		0,0 }
 };
 
@@ -481,11 +489,9 @@ static const TABLE TimezoneTable[] = {
 { "bst",	tZONE, HOUR( 3) },	/* Brazil Standard */
 { "gst",	tZONE, HOUR( 3) },	/* Greenland Standard */
 #endif
-#if 0
 { "nft",	tZONE, HOUR(3.5) },	/* Newfoundland */
 { "nst",	tZONE, HOUR(3.5) },	/* Newfoundland Standard */
 { "ndt",	tDAYZONE,  HOUR(3.5) },	/* Newfoundland Daylight */
-#endif
 { "ast",	tZONE, HOUR( 4) },	/* Atlantic Standard */
 { "adt",	tDAYZONE,  HOUR( 4) },	/* Atlantic Daylight */
 { "est",	tZONE, HOUR( 5) },	/* Eastern Standard */
@@ -514,14 +520,10 @@ static const TABLE TimezoneTable[] = {
 { "fst",	tDAYZONE,  -HOUR(1) },	/* French Summer */
 { "eet",	tZONE, -HOUR(2) },	/* Eastern Europe, USSR Zone 1 */
 { "bt",	tZONE, -HOUR(3) },	/* Baghdad, USSR Zone 2 */
-#if 0
 { "it",	tZONE, -HOUR(3.5) },/* Iran */
-#endif
 { "zp4",	tZONE, -HOUR(4) },	/* USSR Zone 3 */
 { "zp5",	tZONE, -HOUR(5) },	/* USSR Zone 4 */
-#if 0
 { "ist",	tZONE, -HOUR(5.5) },/* Indian Standard */
-#endif
 { "zp6",	tZONE, -HOUR(6) },	/* USSR Zone 5 */
 #if	0
 /* For completeness.  NST is also Newfoundland Stanard, and SST is
@@ -530,18 +532,25 @@ static const TABLE TimezoneTable[] = {
 { "sst",	tZONE, -HOUR(7) },	/* South Sumatra, USSR Zone 6 */
 #endif	/* 0 */
 { "wast",	tZONE, -HOUR(7) },	/* West Australian Standard */
+{ "awst",	tZONE, -HOUR(7) },	/* West Australian Standard */
 { "wadt",	tDAYZONE,  -HOUR(7) },	/* West Australian Daylight */
-#if 0
+{ "awdt",	tDAYZONE,  -HOUR(7) },	/* West Australian Daylight */
+{ "ict",	tZONE, -HOUR(7) },	/* Indo China Time (Thai) */
+#if 0	/* this one looks to be bogus */
 { "jt",	tZONE, -HOUR(7.5) },/* Java (3pm in Cronusland!) */
 #endif
 { "cct",	tZONE, -HOUR(8) },	/* China Coast, USSR Zone 7 */
+{ "sgt",	tZONE, -HOUR(8) },	/* Singapore */
+{ "hkt",	tZONE, -HOUR(8) },	/* Hong Kong */
 { "jst",	tZONE, -HOUR(9) },	/* Japan Standard, USSR Zone 8 */
-#if 0
 { "cast",	tZONE, -HOUR(9.5) },/* Central Australian Standard */
+{ "acst",	tZONE, -HOUR(9.5) },/* Central Australian Standard */
 { "cadt",	tDAYZONE,  -HOUR(9.5) },/* Central Australian Daylight */
-#endif
+{ "acdt",	tDAYZONE,  -HOUR(9.5) },/* Central Australian Daylight */
 { "east",	tZONE, -HOUR(10) },	/* Eastern Australian Standard */
+{ "aest",	tZONE, -HOUR(10) },	/* Eastern Australian Standard */
 { "eadt",	tDAYZONE,  -HOUR(10) },	/* Eastern Australian Daylight */
+{ "aedt",	tDAYZONE,  -HOUR(10) },	/* Eastern Australian Daylight */
 { "gst",	tZONE, -HOUR(10) },	/* Guam Standard, USSR Zone 9 */
 { "nzt",	tZONE, -HOUR(12) },	/* New Zealand */
 { "nzst",	tZONE, -HOUR(12) },	/* New Zealand Standard */
@@ -634,18 +643,23 @@ Convert(
 tm.tm_mday = Day;
 tm.tm_mon = Month - 1;
 tm.tm_year = 

CVS commit: src/lib/libutil

2015-10-29 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Oct 29 20:29:24 UTC 2015

Modified Files:
src/lib/libutil: login_cap.c

Log Message:
Correct typos in comments

Pointed out by Edgar Fuss and J. Lewis Muir.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/lib/libutil/login_cap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/login_cap.c
diff -u src/lib/libutil/login_cap.c:1.32 src/lib/libutil/login_cap.c:1.33
--- src/lib/libutil/login_cap.c:1.32	Sat Jul 11 09:21:22 2015
+++ src/lib/libutil/login_cap.c	Thu Oct 29 20:29:24 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: login_cap.c,v 1.32 2015/07/11 09:21:22 kamil Exp $	*/
+/*	$NetBSD: login_cap.c,v 1.33 2015/10/29 20:29:24 kamil Exp $	*/
 
 /*-
  * Copyright (c) 1995,1997 Berkeley Software Design, Inc. All rights reserved.
@@ -36,7 +36,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: login_cap.c,v 1.32 2015/07/11 09:21:22 kamil Exp $");
+__RCSID("$NetBSD: login_cap.c,v 1.33 2015/10/29 20:29:24 kamil Exp $");
 #endif /* LIBC_SCCS and not lint */
  
 #include 
@@ -934,7 +934,7 @@ multiply(u_quad_t n1, u_quad_t n2)
 
 	/*
 	 * First check the magnitude of each number.  If the sum of the
-	 * magnatude is way to high, reject the number.  (If this test
+	 * magnitude is to high, reject the number.  (If this test
 	 * is not done then the first multiply below may overflow.)
 	 */
 	for (b1 = bpw; (((u_quad_t)1 << (b1-1)) & n1) == 0; --b1)
@@ -963,7 +963,7 @@ multiply(u_quad_t n1, u_quad_t n2)
 	 * overflow.
 	 *
 	 * Finally, if MAX - ((h1 * l2) + (l1 * h2) + (l1 * l2)) < (h1*h2)
-	 * then adding in residual amout will cause an overflow.
+	 * then adding in residual amount will cause an overflow.
 	 */
 
 	m = (n1 >> 1) * (n2 >> 1);



CVS commit: src/lib/libutil

2015-09-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Sep 26 20:28:55 UTC 2015

Modified Files:
src/lib/libutil: kinfo_getvmmap.c

Log Message:
need uvm_param.h now.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libutil/kinfo_getvmmap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/kinfo_getvmmap.c
diff -u src/lib/libutil/kinfo_getvmmap.c:1.2 src/lib/libutil/kinfo_getvmmap.c:1.3
--- src/lib/libutil/kinfo_getvmmap.c:1.2	Thu Sep 24 11:30:39 2015
+++ src/lib/libutil/kinfo_getvmmap.c	Sat Sep 26 16:28:55 2015
@@ -2,7 +2,7 @@
 #ifdef __FBSDID
 __FBSDID("$FreeBSD: head/lib/libutil/kinfo_getvmmap.c 186512 2008-12-27 11:12:23Z rwatson $");
 #endif
-__RCSID("$NetBSD: kinfo_getvmmap.c,v 1.2 2015/09/24 15:30:39 christos Exp $");
+__RCSID("$NetBSD: kinfo_getvmmap.c,v 1.3 2015/09/26 20:28:55 christos Exp $");
 
 #include 
 #include 
@@ -10,6 +10,7 @@ __RCSID("$NetBSD: kinfo_getvmmap.c,v 1.2
 #include 
 #include 
 #include 
+#include 
 
 struct kinfo_vmentry *
 kinfo_getvmmap(pid_t pid, size_t *cntp)



CVS commit: src/lib/libutil

2015-09-24 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Sep 24 14:39:20 UTC 2015

Modified Files:
src/lib/libutil: Makefile shlib_version
Added Files:
src/lib/libutil: kinfo_getvmmap.3 kinfo_getvmmap.c

Log Message:
Add kinfo_getvmmap from FreeBSD


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/lib/libutil/Makefile
cvs rdiff -u -r0 -r1.1 src/lib/libutil/kinfo_getvmmap.3 \
src/lib/libutil/kinfo_getvmmap.c
cvs rdiff -u -r1.52 -r1.53 src/lib/libutil/shlib_version

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/Makefile
diff -u src/lib/libutil/Makefile:1.77 src/lib/libutil/Makefile:1.78
--- src/lib/libutil/Makefile:1.77	Sat Jul 25 22:20:30 2015
+++ src/lib/libutil/Makefile	Thu Sep 24 10:39:20 2015
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.77 2015/07/26 02:20:30 kamil Exp $
+#	$NetBSD: Makefile,v 1.78 2015/09/24 14:39:20 christos Exp $
 #	@(#)Makefile	8.1 (Berkeley) 6/4/93
 
 USE_SHLIBDIR=	yes
@@ -15,7 +15,7 @@ SRCS+=	efun.c \
 	getbootfile.c getbyteorder.c getlabelsector.c getmaxpartitions.c \
 	getfsspecname.c getmntopts.c getrawpartition.c getdiskrawname.c \
 	disklabel_dkcksum.c disklabel_scan.c \
-	if_media.c \
+	if_media.c kinfo_getvmmap.c \
 	login.c loginx.c login_cap.c login_tty.c logout.c logoutx.c \
 	logwtmp.c logwtmpx.c opendisk.c parsedate.y \
 	passwd.c pw_scan.c pidfile.c pidlock.c pty.c \
@@ -27,7 +27,7 @@ MAN=	efun.3 \
 	getbootfile.3 getbyteorder.3 getfstypename.3 getlabelsector.3 \
 	getmaxpartitions.3 getmntopts.3 getrawpartition.3 \
 	getdiskrawname.3 getfsspecname.3 \
-	login.3 login_cap.3 loginx.3 \
+	login.3 login_cap.3 loginx.3 kinfo_getvmmap.3 \
 	disklabel_dkcksum.3 disklabel_scan.3 \
 	opendisk.3 openpty.3 parsedate.3 pidfile.3 pidlock.3 \
 	proc_compare.3 pw_getconf.3 pw_init.3 pw_lock.3 secure_path.3 \

Index: src/lib/libutil/shlib_version
diff -u src/lib/libutil/shlib_version:1.52 src/lib/libutil/shlib_version:1.53
--- src/lib/libutil/shlib_version:1.52	Sun Jul 26 11:15:31 2015
+++ src/lib/libutil/shlib_version	Thu Sep 24 10:39:20 2015
@@ -1,5 +1,5 @@
-#	$NetBSD: shlib_version,v 1.52 2015/07/26 15:15:31 kamil Exp $
+#	$NetBSD: shlib_version,v 1.53 2015/09/24 14:39:20 christos Exp $
 #	Remember to update distrib/sets/lists/base/shl.* when changing
 #
 major=7
-minor=22
+minor=23

Added files:

Index: src/lib/libutil/kinfo_getvmmap.3
diff -u /dev/null src/lib/libutil/kinfo_getvmmap.3:1.1
--- /dev/null	Thu Sep 24 10:39:20 2015
+++ src/lib/libutil/kinfo_getvmmap.3	Thu Sep 24 10:39:20 2015
@@ -0,0 +1,80 @@
+.\"	$NetBSD: kinfo_getvmmap.3,v 1.1 2015/09/24 14:39:20 christos Exp $
+.\"
+.\" Copyright (c) 2008 Peter Wemm
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"notice, this list of conditions and the following disclaimer in the
+.\"documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD: head/lib/libutil/kinfo_getvmmap.3 283622 2015-05-27 17:51:06Z jhb $
+.\"
+.Dd September 16, 2015
+.Dt KINFO_GETVMMAP 3
+.Os
+.Sh NAME
+.Nm kinfo_getvmmap
+.Nd function for getting per-process memory map information
+.Sh LIBRARY
+.Lb libutil
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/sysctl.h
+.In util.h
+.Ft struct kinfo_vmentry *
+.Fn kinfo_getvmmap "pid_t pid" "size_t *cntp"
+.Sh DESCRIPTION
+This function is used for obtaining virtual memory mapping information
+of a particular process.
+.Pp
+The
+.Ar pid
+field contains the process identifier.
+This should be the a process that you have privilege to access.
+The
+.Ar cntp
+field is allows the caller to know how many records are returned.
+.Pp
+This function is a wrapper around
+.Xr sysctl 3
+with the
+.Dv KERN_PROC_VMMAP
+mib.
+While the kernel returns a packed structure, this function expands the
+data into a fixed record 

CVS commit: src/lib/libutil

2015-09-24 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Sep 24 15:30:39 UTC 2015

Modified Files:
src/lib/libutil: kinfo_getvmmap.c

Log Message:
Hello lint.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libutil/kinfo_getvmmap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/kinfo_getvmmap.c
diff -u src/lib/libutil/kinfo_getvmmap.c:1.1 src/lib/libutil/kinfo_getvmmap.c:1.2
--- src/lib/libutil/kinfo_getvmmap.c:1.1	Thu Sep 24 10:39:20 2015
+++ src/lib/libutil/kinfo_getvmmap.c	Thu Sep 24 11:30:39 2015
@@ -2,7 +2,7 @@
 #ifdef __FBSDID
 __FBSDID("$FreeBSD: head/lib/libutil/kinfo_getvmmap.c 186512 2008-12-27 11:12:23Z rwatson $");
 #endif
-__RCSID("$NetBSD: kinfo_getvmmap.c,v 1.1 2015/09/24 14:39:20 christos Exp $");
+__RCSID("$NetBSD: kinfo_getvmmap.c,v 1.2 2015/09/24 15:30:39 christos Exp $");
 
 #include 
 #include 
@@ -27,7 +27,7 @@ kinfo_getvmmap(pid_t pid, size_t *cntp)
 	mib[3] = pid;
 	mib[4] = sizeof(*kiv);
 
-	error = sysctl(mib, __arraycount(mib), NULL, , NULL, 0);
+	error = sysctl(mib, (u_int)__arraycount(mib), NULL, , NULL, 0);
 	if (error)
 		return NULL;
 
@@ -37,7 +37,7 @@ kinfo_getvmmap(pid_t pid, size_t *cntp)
 	if (kiv == NULL)
 		return NULL;
 
-	error = sysctl(mib, __arraycount(mib), kiv, , NULL, 0);
+	error = sysctl(mib, (u_int)__arraycount(mib), kiv, , NULL, 0);
 	if (error) {
 		free(kiv);
 		return NULL;



CVS commit: src/lib/libutil

2015-07-26 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Jul 26 17:37:38 UTC 2015

Modified Files:
src/lib/libutil: efun.3

Log Message:
Bump date for recent changes


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libutil/efun.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/efun.3
diff -u src/lib/libutil/efun.3:1.13 src/lib/libutil/efun.3:1.14
--- src/lib/libutil/efun.3:1.13	Sun Jul 26 17:36:38 2015
+++ src/lib/libutil/efun.3	Sun Jul 26 17:37:38 2015
@@ -1,4 +1,4 @@
-.\ $NetBSD: efun.3,v 1.13 2015/07/26 17:36:38 kamil Exp $
+.\ $NetBSD: efun.3,v 1.14 2015/07/26 17:37:38 kamil Exp $
 .\
 .\ Copyright (c) 2006 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -27,7 +27,7 @@
 .\ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\ POSSIBILITY OF SUCH DAMAGE.
 .\
-.Dd May 3, 2010
+.Dd July 26, 2015
 .Dt EFUN 3
 .Os
 .Sh NAME



CVS commit: src/lib/libutil

2015-07-26 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Jul 26 17:36:38 UTC 2015

Modified Files:
src/lib/libutil: efun.3

Log Message:
Sync parameter name with efun.c

This change is non-functional.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libutil/efun.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/efun.3
diff -u src/lib/libutil/efun.3:1.12 src/lib/libutil/efun.3:1.13
--- src/lib/libutil/efun.3:1.12	Sun Jul 26 02:20:30 2015
+++ src/lib/libutil/efun.3	Sun Jul 26 17:36:38 2015
@@ -1,4 +1,4 @@
-.\ $NetBSD: efun.3,v 1.12 2015/07/26 02:20:30 kamil Exp $
+.\ $NetBSD: efun.3,v 1.13 2015/07/26 17:36:38 kamil Exp $
 .\
 .\ Copyright (c) 2006 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -57,7 +57,7 @@
 .Ft FILE *
 .Fn efopen const char *p const char *m
 .Ft void *
-.Fn ecalloc size_t n size_t c
+.Fn ecalloc size_t n size_t s
 .Ft void *
 .Fn emalloc size_t n
 .Ft void *



CVS commit: src/lib/libutil

2015-06-13 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sat Jun 13 19:52:58 UTC 2015

Modified Files:
src/lib/libutil: getfsspecname.3

Log Message:
grammar patrol


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libutil/getfsspecname.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/getfsspecname.3
diff -u src/lib/libutil/getfsspecname.3:1.4 src/lib/libutil/getfsspecname.3:1.5
--- src/lib/libutil/getfsspecname.3:1.4	Mon Aug 18 07:33:21 2014
+++ src/lib/libutil/getfsspecname.3	Sat Jun 13 19:52:58 2015
@@ -1,4 +1,4 @@
-.\	$NetBSD: getfsspecname.3,v 1.4 2014/08/18 07:33:21 christos Exp $
+.\	$NetBSD: getfsspecname.3,v 1.5 2015/06/13 19:52:58 dholland Exp $
 .\
 .\ Copyright (c) 2012 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -72,7 +72,7 @@ or the original
 argument.
 On failure
 .Dv NULL
-is return and
+is returned and
 .Fa buf
 contains the reason for the error.
 .Sh SEE ALSO



CVS commit: src/lib/libutil

2015-01-22 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jan 22 16:19:08 UTC 2015

Modified Files:
src/lib/libutil: pidfile.c

Log Message:
- not all asprintfs return -1 *and* set buf = NULL, check explicitly.
- don't shadow basename(3)


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/lib/libutil/pidfile.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/pidfile.c
diff -u src/lib/libutil/pidfile.c:1.9 src/lib/libutil/pidfile.c:1.10
--- src/lib/libutil/pidfile.c:1.9	Tue Mar 29 09:55:37 2011
+++ src/lib/libutil/pidfile.c	Thu Jan 22 11:19:08 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: pidfile.c,v 1.9 2011/03/29 13:55:37 jmmv Exp $	*/
+/*	$NetBSD: pidfile.c,v 1.10 2015/01/22 16:19:08 christos Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include sys/cdefs.h
 #if defined(LIBC_SCCS)  !defined(lint)
-__RCSID($NetBSD: pidfile.c,v 1.9 2011/03/29 13:55:37 jmmv Exp $);
+__RCSID($NetBSD: pidfile.c,v 1.10 2015/01/22 16:19:08 christos Exp $);
 #endif
 
 #include sys/param.h
@@ -105,15 +105,16 @@ cleanup_old_pidfile(const char* path)
  * Returns a pointer to a dynamically-allocatd string containing the absolute
  * path to the pidfile; NULL on failure. */
 static char *
-generate_varrun_path(const char *basename)
+generate_varrun_path(const char *bname)
 {
 	char *path;
 
-	if (basename == NULL)
-		basename = getprogname();
+	if (bname == NULL)
+		bname = getprogname();
 
 	/* _PATH_VARRUN includes trailing / */
-	(void) asprintf(path, %s%s.pid, _PATH_VARRUN, basename);
+	if (asprintf(path, %s%s.pid, _PATH_VARRUN, basename) == -1)
+		return NULL;
 	return path;
 }
 



CVS commit: src/lib/libutil

2015-01-22 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jan 22 19:04:28 UTC 2015

Modified Files:
src/lib/libutil: pidfile.c

Log Message:
s/basename/bname/


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/libutil/pidfile.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/pidfile.c
diff -u src/lib/libutil/pidfile.c:1.10 src/lib/libutil/pidfile.c:1.11
--- src/lib/libutil/pidfile.c:1.10	Thu Jan 22 11:19:08 2015
+++ src/lib/libutil/pidfile.c	Thu Jan 22 14:04:28 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: pidfile.c,v 1.10 2015/01/22 16:19:08 christos Exp $	*/
+/*	$NetBSD: pidfile.c,v 1.11 2015/01/22 19:04:28 christos Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include sys/cdefs.h
 #if defined(LIBC_SCCS)  !defined(lint)
-__RCSID($NetBSD: pidfile.c,v 1.10 2015/01/22 16:19:08 christos Exp $);
+__RCSID($NetBSD: pidfile.c,v 1.11 2015/01/22 19:04:28 christos Exp $);
 #endif
 
 #include sys/param.h
@@ -99,7 +99,7 @@ cleanup_old_pidfile(const char* path)
 }
 
 /* Constructs a name for a pidfile in the default location (/var/run).  If
- * 'basename' is NULL, uses the name of the current program for the name of
+ * 'bname' is NULL, uses the name of the current program for the name of
  * the pidfile.
  *
  * Returns a pointer to a dynamically-allocatd string containing the absolute
@@ -113,7 +113,7 @@ generate_varrun_path(const char *bname)
 		bname = getprogname();
 
 	/* _PATH_VARRUN includes trailing / */
-	if (asprintf(path, %s%s.pid, _PATH_VARRUN, basename) == -1)
+	if (asprintf(path, %s%s.pid, _PATH_VARRUN, bname) == -1)
 		return NULL;
 	return path;
 }



CVS commit: src/lib/libutil

2015-01-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jan 18 18:09:36 UTC 2015

Modified Files:
src/lib/libutil: Makefile efun.3 efun.c

Log Message:
add estro{i,u} (Kamil Rytarowski)


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/lib/libutil/Makefile
cvs rdiff -u -r1.10 -r1.11 src/lib/libutil/efun.3
cvs rdiff -u -r1.8 -r1.9 src/lib/libutil/efun.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/Makefile
diff -u src/lib/libutil/Makefile:1.75 src/lib/libutil/Makefile:1.76
--- src/lib/libutil/Makefile:1.75	Thu Jun 20 16:42:30 2013
+++ src/lib/libutil/Makefile	Sun Jan 18 13:09:36 2015
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.75 2013/06/20 20:42:30 christos Exp $
+#	$NetBSD: Makefile,v 1.76 2015/01/18 18:09:36 christos Exp $
 #	@(#)Makefile	8.1 (Berkeley) 6/4/93
 
 USE_SHLIBDIR=	yes
@@ -77,6 +77,8 @@ MLINKS+=efun.3 estrlcpy.3
 MLINKS+=efun.3 estrlcat.3
 MLINKS+=efun.3 estrdup.3
 MLINKS+=efun.3 estrndup.3
+MLINKS+=efun.3 estrtoi.3
+MLINKS+=efun.3 estrtou.3
 MLINKS+=efun.3 emalloc.3
 MLINKS+=efun.3 ecalloc.3
 MLINKS+=efun.3 erealloc.3

Index: src/lib/libutil/efun.3
diff -u src/lib/libutil/efun.3:1.10 src/lib/libutil/efun.3:1.11
--- src/lib/libutil/efun.3:1.10	Mon May  3 01:40:37 2010
+++ src/lib/libutil/efun.3	Sun Jan 18 13:09:36 2015
@@ -1,4 +1,4 @@
-.\ $NetBSD: efun.3,v 1.10 2010/05/03 05:40:37 jruoho Exp $
+.\ $NetBSD: efun.3,v 1.11 2015/01/18 18:09:36 christos Exp $
 .\
 .\ Copyright (c) 2006 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -41,6 +41,8 @@
 .Nm estrndup ,
 .Nm estrlcat ,
 .Nm estrlcpy ,
+.Nm estrtoi ,
+.Nm estrtou ,
 .Nm evasprintf
 .Nd error-checked utility functions
 .Sh LIBRARY
@@ -67,6 +69,10 @@
 .Fn estrlcat char *dst const char *src size_t len
 .Ft size_t
 .Fn estrlcpy char *dst const char *src size_t len
+.Ft intmax_t
+.Fn estrtoi const char * nptr int base intmax_t lo intmax_t hi
+.Ft uintmax_t
+.Fn estrtou const char * nptr int base uintmax_t lo uintmax_t hi
 .Ft int
 .Fn evasprintf char ** restrict str const char * restrict fmt ...
 .Sh DESCRIPTION
@@ -80,6 +86,8 @@ The
 .Fn estrndup ,
 .Fn estrlcat ,
 .Fn estrlcpy ,
+.Fn estrtoi ,
+.Fn estrtou ,
 and
 .Fn evasprintf
 functions
@@ -114,4 +122,13 @@ error handler will just call
 .Xr strlcat 3 ,
 .Xr strlcpy 3 ,
 .Xr strndup 3 ,
+.Xr strtoi 3 ,
+.Xr strtou 3 ,
 .Xr vasprintf 3
+.Sh HISTORY
+The
+.Fn estrtoi
+and
+.Fn estrtou
+functions were added in
+.Nx 8 .

Index: src/lib/libutil/efun.c
diff -u src/lib/libutil/efun.c:1.8 src/lib/libutil/efun.c:1.9
--- src/lib/libutil/efun.c:1.8	Sun Dec 30 12:37:13 2012
+++ src/lib/libutil/efun.c	Sun Jan 18 13:09:36 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: efun.c,v 1.8 2012/12/30 17:37:13 dholland Exp $	*/
+/*	$NetBSD: efun.c,v 1.9 2015/01/18 18:09:36 christos Exp $	*/
 
 /*-
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -35,11 +35,12 @@
 
 #include sys/cdefs.h
 #ifdef __RCSID
-__RCSID($NetBSD: efun.c,v 1.8 2012/12/30 17:37:13 dholland Exp $);
+__RCSID($NetBSD: efun.c,v 1.9 2015/01/18 18:09:36 christos Exp $);
 #endif
 
 #include err.h
 #include errno.h
+#include inttypes.h
 #include string.h
 #include stdlib.h
 #include stdio.h
@@ -156,3 +157,31 @@ evasprintf(char ** __restrict ret, const
 		(*efunc)(1, Cannot format string);
 	return rv;
 }
+
+intmax_t
+estrtoi(const char * nptr, int base, intmax_t lo, intmax_t hi)
+{
+	int e;
+	intmax_t rv = strtoi(nptr, NULL, base, lo, hi, e);
+	if (e != 0) {
+		errno = e;
+		(*efunc)(1,
+		Cannot convert string value '%s' with base %d to a number in range [%jd .. %jd],
+		nptr, base, lo, hi);
+	}
+	return rv;
+}
+
+uintmax_t
+estrtou(const char * nptr, int base, uintmax_t lo, uintmax_t hi)
+{
+	int e;
+	uintmax_t rv = strtou(nptr, NULL, base, lo, hi, e);
+	if (e != 0) {
+		errno = e;
+		(*efunc)(1,
+		Cannot convert string value '%s' with base %d to a number in range [%ju .. %ju],
+		nptr, base, lo, hi);
+	}
+	return rv;
+}



CVS commit: src/lib/libutil

2014-10-08 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Wed Oct  8 14:32:29 UTC 2014

Modified Files:
src/lib/libutil: parsedate.y

Log Message:
A time like HH:MM:SS.sss says nothing about whether DST is on or off.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/lib/libutil/parsedate.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.y
diff -u src/lib/libutil/parsedate.y:1.17 src/lib/libutil/parsedate.y:1.18
--- src/lib/libutil/parsedate.y:1.17	Tue Oct  7 22:27:14 2014
+++ src/lib/libutil/parsedate.y	Wed Oct  8 14:32:29 2014
@@ -14,7 +14,7 @@
 
 #include sys/cdefs.h
 #ifdef __RCSID
-__RCSID($NetBSD: parsedate.y,v 1.17 2014/10/07 22:27:14 apb Exp $);
+__RCSID($NetBSD: parsedate.y,v 1.18 2014/10/08 14:32:29 apb Exp $);
 #endif
 
 #include stdio.h
@@ -223,9 +223,7 @@ time	: tUNUMBER tMERIDIAN {
 	param-yyMinutes = $3;
 	param-yySeconds = $5;
 	param-yyMeridian = MER24;
-	param-yyDSTmode = DSToff;
 /* XXX: Do nothing with millis */
-/*	param-yyTimezone = ($7 % 100 + ($7 / 100) * 60); */
 	}
 	;
 



CVS commit: src/lib/libutil

2014-10-08 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Wed Oct  8 14:43:48 UTC 2014

Modified Files:
src/lib/libutil: parsedate.y

Log Message:
Add a new non-terminal time_numericzone for a time with
a numeric timezone.  Move some productions from time to time_numericzone.
Increment yyHaveZone when encountering one of these.

Previously, input of the form HH:MM:SS + would not have set the
yyhaveZone flag.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/lib/libutil/parsedate.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.y
diff -u src/lib/libutil/parsedate.y:1.18 src/lib/libutil/parsedate.y:1.19
--- src/lib/libutil/parsedate.y:1.18	Wed Oct  8 14:32:29 2014
+++ src/lib/libutil/parsedate.y	Wed Oct  8 14:43:48 2014
@@ -14,7 +14,7 @@
 
 #include sys/cdefs.h
 #ifdef __RCSID
-__RCSID($NetBSD: parsedate.y,v 1.18 2014/10/08 14:32:29 apb Exp $);
+__RCSID($NetBSD: parsedate.y,v 1.19 2014/10/08 14:43:48 apb Exp $);
 #endif
 
 #include stdio.h
@@ -118,6 +118,10 @@ spec	: /* NULL */
 item	: time {
 	param-yyHaveTime++;
 	}
+	| time_numericzone {
+	param-yyHaveTime++;
+	param-yyHaveZone++;
+	}
 	| zone {
 	param-yyHaveZone++;
 	}
@@ -197,33 +201,35 @@ time	: tUNUMBER tMERIDIAN {
 	param-yySeconds = 0;
 	param-yyMeridian = $4;
 	}
-	| tUNUMBER ':' tUNUMBER tSNUMBER {
-	param-yyHour = $1;
-	param-yyMinutes = $3;
-	param-yyMeridian = MER24;
-	param-yyDSTmode = DSToff;
-	param-yyTimezone = - ($4 % 100 + ($4 / 100) * 60);
-	}
 	| tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid {
 	param-yyHour = $1;
 	param-yyMinutes = $3;
 	param-yySeconds = $5;
 	param-yyMeridian = $6;
 	}
-	| tUNUMBER ':' tUNUMBER ':' tUNUMBER tSNUMBER {
+	| tUNUMBER ':' tUNUMBER ':' tUNUMBER '.' tUNUMBER {
 	param-yyHour = $1;
 	param-yyMinutes = $3;
 	param-yySeconds = $5;
 	param-yyMeridian = MER24;
+/* XXX: Do nothing with millis */
+	}
+	;
+
+time_numericzone : tUNUMBER ':' tUNUMBER tSNUMBER {
+	param-yyHour = $1;
+	param-yyMinutes = $3;
+	param-yyMeridian = MER24;
 	param-yyDSTmode = DSToff;
-	param-yyTimezone = - ($6 % 100 + ($6 / 100) * 60);
+	param-yyTimezone = - ($4 % 100 + ($4 / 100) * 60);
 	}
-	| tUNUMBER ':' tUNUMBER ':' tUNUMBER '.' tUNUMBER {
+	| tUNUMBER ':' tUNUMBER ':' tUNUMBER tSNUMBER {
 	param-yyHour = $1;
 	param-yyMinutes = $3;
 	param-yySeconds = $5;
 	param-yyMeridian = MER24;
-/* XXX: Do nothing with millis */
+	param-yyDSTmode = DSToff;
+	param-yyTimezone = - ($6 % 100 + ($6 / 100) * 60);
 	}
 	;
 



CVS commit: src/lib/libutil

2014-10-08 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Wed Oct  8 17:06:18 UTC 2014

Modified Files:
src/lib/libutil: parsedate.3

Log Message:
The tzoff argument is in minutes (behind/west of UTC), not seconds.

While here, also say that time = NULL and tzoff = NULL are independent.
The code doesn't yet implement that, but it will soon.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libutil/parsedate.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.3
diff -u src/lib/libutil/parsedate.3:1.13 src/lib/libutil/parsedate.3:1.14
--- src/lib/libutil/parsedate.3:1.13	Tue Oct  7 22:39:32 2014
+++ src/lib/libutil/parsedate.3	Wed Oct  8 17:06:18 2014
@@ -1,4 +1,4 @@
-.\ $NetBSD: parsedate.3,v 1.13 2014/10/07 22:39:32 apb Exp $
+.\ $NetBSD: parsedate.3,v 1.14 2014/10/08 17:06:18 apb Exp $
 .\
 .\ Copyright (c) 2006 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -27,7 +27,7 @@
 .\ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\ POSSIBILITY OF SUCH DAMAGE.
 .\
-.Dd October 7, 2014
+.Dd October 8, 2014
 .Dt PARSEDATE 3
 .Os
 .Sh NAME
@@ -46,15 +46,20 @@ function parses a datetime from
 .Ar datestr
 described in English relative to an optional
 .Ar time
-point and an optional timezone offset in seconds specified in
+point,
+and an optional timezone offset (in minutes behind/west of UTC)
+specified in
 .Ar tzoff .
-If either
+If
 .Ar time
-or
+is
+.Dv NULL 
+then the current time is used.
+If
 .Ar tzoff
-are
+is
 .Dv NULL ,
-then the current time and timezone offset are used.
+then the current time zone is used.
 .Pp
 The
 .Ar datestr



CVS commit: src/lib/libutil

2014-10-08 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Wed Oct  8 17:38:28 UTC 2014

Modified Files:
src/lib/libutil: parsedate.y

Log Message:
Improved handling of local times.

* A magic value USE_LOCAL_TIME (defined as 9) may be passed as the
  Timezone to Convert(), instructing it to use mktime() to work
  in the local time zone, instead of using mktime_z to work in UTC
  (and then adding the specified timezone offset).
* Some old code is removed now that there's no need to find the local
  timezone offset.
* Allow either one or both of the now and zone arguments to
  parsedate() to be NULL, treating them independently.  Previously,
  if either one was NULL, the other was ignored.
* If the zone argument is specified, then the current date is calculated
  in the specified zone, not in local time.

Also add some disabled debug code.

This should fix PR lib/47916.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/lib/libutil/parsedate.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.y
diff -u src/lib/libutil/parsedate.y:1.19 src/lib/libutil/parsedate.y:1.20
--- src/lib/libutil/parsedate.y:1.19	Wed Oct  8 14:43:48 2014
+++ src/lib/libutil/parsedate.y	Wed Oct  8 17:38:28 2014
@@ -14,7 +14,7 @@
 
 #include sys/cdefs.h
 #ifdef __RCSID
-__RCSID($NetBSD: parsedate.y,v 1.19 2014/10/08 14:43:48 apb Exp $);
+__RCSID($NetBSD: parsedate.y,v 1.20 2014/10/08 17:38:28 apb Exp $);
 #endif
 
 #include stdio.h
@@ -42,6 +42,7 @@ __RCSID($NetBSD: parsedate.y,v 1.19 201
 #define HOUR(x)		((time_t)(x) * 60)
 #define SECSPERDAY	(24L * 60L * 60L)
 
+#define USE_LOCAL_TIME	9 /* special case for Convert() and yyTimezone */
 
 /*
 **  An entry in the lexical lookup table.
@@ -618,7 +619,8 @@ Convert(
 time_t	Hours,		/* Hour of day [0-24] */
 time_t	Minutes,	/* Minute of hour [0-59] */
 time_t	Seconds,	/* Second of minute [0-60] */
-time_t	Timezone,	/* Timezone as minutes east of UTC */
+time_t	Timezone,	/* Timezone as minutes east of UTC,
+ * or USE_LOCAL_TIME special case */
 MERIDIAN	Meridian,	/* Hours are am/pm/24 hour clock */
 DSTMODE	DSTmode		/* DST on/off/maybe */
 )
@@ -638,9 +640,25 @@ Convert(
 default: tm.tm_isdst = -1; break;
 }
 
-/* We rely on mktime_z(NULL, ...) working in UTC, not in local time. */
-result = mktime_z(NULL, tm);
-result += Timezone * 60;
+if (Timezone == USE_LOCAL_TIME) {
+	result = mktime(tm);
+} else {
+	/* We rely on mktime_z(NULL, ...) working in UTC */
+	result = mktime_z(NULL, tm);
+	result += Timezone * 60;
+}
+
+#if PARSEDATE_DEBUG
+fprintf(stderr, %s(M=%jd D=%jd Y=%jd H=%jd M=%jd S=%jd Z=%jd
+		 mer=%d DST=%d),
+	__func__,
+	(intmax_t)Month, (intmax_t)Day, (intmax_t)Year,
+	(intmax_t)Hours, (intmax_t)Minutes, (intmax_t)Seconds,
+	(intmax_t)Timezone, (int)Meridian, (int)DSTmode);
+fprintf(stderr,  - %jd, (intmax_t)result);
+fprintf(stderr,  %s, ctime(result));
+#endif
+
 return result;
 }
 
@@ -878,31 +896,10 @@ yylex(YYSTYPE *yylval, const char **yyIn
 
 #define TM_YEAR_ORIGIN 1900
 
-/* Yield A - B, measured in seconds.  */
-static time_t
-difftm (struct tm *a, struct tm *b)
-{
-  int ay = a-tm_year + (TM_YEAR_ORIGIN - 1);
-  int by = b-tm_year + (TM_YEAR_ORIGIN - 1);
-  int days = (
-	  /* difference in day of year */
-	  a-tm_yday - b-tm_yday
-	  /* + intervening leap days */
-	  +  ((ay  2) - (by  2))
-	  -  (ay/100 - by/100)
-	  +  ((ay/100  2) - (by/100  2))
-	  /* + difference in years * 365 */
-	  +  (long)(ay-by) * 365
-	  );
-  return ((time_t)60*(60*(24*days + (a-tm_hour - b-tm_hour))
-	  + (a-tm_min - b-tm_min))
-	  + (a-tm_sec - b-tm_sec));
-}
-
 time_t
 parsedate(const char *p, const time_t *now, const int *zone)
 {
-struct tm gmt, local, *gmt_ptr, *tm;
+struct tm		local, *tm;
 time_t		nowt;
 int			zonet;
 time_t		Start;
@@ -913,29 +910,24 @@ parsedate(const char *p, const time_t *n
 saved_errno = errno;
 errno = 0;
 
-if (now == NULL || zone == NULL) {
+if (now == NULL) {
 now = nowt;
-	zone = zonet;
 	(void)time(nowt);
-
-	gmt_ptr = gmtime_r(now, gmt);
+}
+if (zone == NULL) {
+	zone = zonet;
+	zonet = USE_LOCAL_TIME;
 	if ((tm = localtime_r(now, local)) == NULL)
 	return -1;
-
-	if (gmt_ptr != NULL)
-	zonet = difftm(gmt, local) / 60;
-	else
-	/* We are on a system like VMS, where the system clock is
-	   in local time and the system has no concept of timezones.
-	   Hopefully we can fake this out (for the case in which the
-	   user specifies no timezone) by just saying the timezone
-	   is zero.  */
-	zonet = 0;
-
-	if (local.tm_isdst)
-	zonet += 60;
 } else {
-	if ((tm = localtime_r(now, local)) == NULL)
+	/*
+	 * Should use the specified zone, not localtime.
+	 * Fake it using gmtime and 

CVS commit: src/lib/libutil

2014-10-08 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Wed Oct  8 22:10:04 UTC 2014

Modified Files:
src/lib/libutil: parsedate.3

Log Message:
Drop trailing whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/lib/libutil/parsedate.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.3
diff -u src/lib/libutil/parsedate.3:1.14 src/lib/libutil/parsedate.3:1.15
--- src/lib/libutil/parsedate.3:1.14	Wed Oct  8 17:06:18 2014
+++ src/lib/libutil/parsedate.3	Wed Oct  8 22:10:04 2014
@@ -1,4 +1,4 @@
-.\ $NetBSD: parsedate.3,v 1.14 2014/10/08 17:06:18 apb Exp $
+.\ $NetBSD: parsedate.3,v 1.15 2014/10/08 22:10:04 wiz Exp $
 .\
 .\ Copyright (c) 2006 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -53,7 +53,7 @@ specified in
 If
 .Ar time
 is
-.Dv NULL 
+.Dv NULL
 then the current time is used.
 If
 .Ar tzoff



CVS commit: src/lib/libutil

2014-10-07 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Tue Oct  7 22:27:14 UTC 2014

Modified Files:
src/lib/libutil: parsedate.y

Log Message:
Some years don't need the maybe add 1900 or 2000 adjustment
that was designed for handling two-digit abbreviated years.
For example, 1/2/70 still refers to the year 1970, as before,
but 70-01-02 now refers to the year 70.

* Add a new yyHaveFullYear member to struct dateinfo, to record whether
  or not the year needs to be adjusted.
* Code that parses years sets yyHaveFullYear=1 if they know that the
  year should not be adjusted (as is the case for ISO 8601 dates), or if
  they perform their own adjustment (as is the case for CVS timestamps).
* Move the year adjustment code into a new function, AdjustYear,
  instead of inline in Convert().
* Make Convert() assume the year doesn't need to be adjusted,
  and make Convert's callers first call AdjustYear() if appropriate.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libutil/parsedate.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.y
diff -u src/lib/libutil/parsedate.y:1.16 src/lib/libutil/parsedate.y:1.17
--- src/lib/libutil/parsedate.y:1.16	Wed Jun 12 01:46:07 2013
+++ src/lib/libutil/parsedate.y	Tue Oct  7 22:27:14 2014
@@ -14,7 +14,7 @@
 
 #include sys/cdefs.h
 #ifdef __RCSID
-__RCSID($NetBSD: parsedate.y,v 1.16 2013/06/12 01:46:07 yamt Exp $);
+__RCSID($NetBSD: parsedate.y,v 1.17 2014/10/07 22:27:14 apb Exp $);
 #endif
 
 #include stdio.h
@@ -69,22 +69,24 @@ typedef enum _MERIDIAN {
 
 
 struct dateinfo {
-	DSTMODE	yyDSTmode;
+	DSTMODE	yyDSTmode;	/* DST on/off/maybe */
 	time_t	yyDayOrdinal;
 	time_t	yyDayNumber;
 	int	yyHaveDate;
+	int	yyHaveFullYear;	/* if true, year is not abbreviated. */
+/* if false, need to call AdjustYear(). */
 	int	yyHaveDay;
 	int	yyHaveRel;
 	int	yyHaveTime;
 	int	yyHaveZone;
-	time_t	yyTimezone;
-	time_t	yyDay;
-	time_t	yyHour;
-	time_t	yyMinutes;
-	time_t	yyMonth;
-	time_t	yySeconds;
-	time_t	yyYear;
-	MERIDIAN	yyMeridian;
+	time_t	yyTimezone;	/* Timezone as minutes ahead/east of UTC */
+	time_t	yyDay;		/* Day of month [1-31] */
+	time_t	yyHour;		/* Hour of day [0-24] or [1-12] */
+	time_t	yyMinutes;	/* Minute of hour [0-59] */
+	time_t	yyMonth;	/* Month of year [1-12] */
+	time_t	yySeconds;	/* Second of minute [0-60] */
+	time_t	yyYear;		/* Year, see also yyHaveFullYear */
+	MERIDIAN yyMeridian;	/* Interpret yyHour as AM/PM/24 hour clock */
 	time_t	yyRelMonth;
 	time_t	yyRelSeconds;
 };
@@ -144,6 +146,7 @@ item	: time {
 cvsstamp: tUNUMBER '.' tUNUMBER '.' tUNUMBER '.' tUNUMBER '.' tUNUMBER '.' tUNUMBER {
 	param-yyYear = $1;
 	if (param-yyYear  100) param-yyYear += 1900;
+	param-yyHaveFullYear = 1;
 	param-yyMonth = $3;
 	param-yyDay = $5;
 	param-yyHour = $7;
@@ -174,6 +177,7 @@ epochdate: AT_SIGN at_number {
 		param-yyMinutes = 0;
 		param-yySeconds = 0;
 	}
+	param-yyHaveFullYear = 1;
 	param-yyDSTmode = DSToff;
 	param-yyTimezone = 0;
 	}
@@ -272,6 +276,7 @@ date	: tUNUMBER '/' tUNUMBER {
 	| tUNUMBER tSNUMBER tSNUMBER {
 	/* ISO 8601 format.  -mm-dd.  */
 	param-yyYear = $1;
+	param-yyHaveFullYear = 1;
 	param-yyMonth = -$2;
 	param-yyDay = -$3;
 	}
@@ -581,15 +586,31 @@ yyerror(struct dateinfo *param, const ch
 }
 
 
-/* Year is either
-   * A negative number, which means to use its absolute value (why?)
-   * A number from 0 to 99, which means a year from 1900 to 1999, or
-   * The actual year (=100).  */
+/* Adjust year from a value that might be abbreviated, to a full value.
+ * e.g. convert 70 to 1970.
+ * Input Year is either:
+ *  - A negative number, which means to use its absolute value (why?)
+ *  - A number from 0 to 99, which means a year from 1900 to 1999, or
+ *  - The actual year (=100).
+ * Returns the full year. */
+static time_t
+AdjustYear(time_t Year)
+{
+/* XXX Y2K */
+if (Year  0)
+	Year = -Year;
+if (Year  70)
+	Year += 2000;
+else if (Year  100)
+	Year += 1900;
+return Year;
+}
+
 static time_t
 Convert(
 time_t	Month,		/* month of year [1-12] */
 time_t	Day,		/* day of month [1-31] */
-time_t	Year,		/* year; see above comment */
+time_t	Year,		/* year, not abbreviated in any way */
 time_t	Hours,		/* Hour of day [0-24] */
 time_t	Minutes,	/* Minute of hour [0-59] */
 time_t	Seconds,	/* Second of minute [0-60] */
@@ -601,14 +622,6 @@ Convert(
 struct tm tm = {.tm_sec = 0};
 time_t result;
 
-/* XXX Y2K */
-if (Year  0)
-	Year = -Year;
-if (Year  70)
-	Year += 2000;
-else if (Year  100)
-	Year += 1900;
-
 tm.tm_sec = Seconds;
 tm.tm_min = Minutes;
 tm.tm_hour = Hours + (Meridian == MERpm ? 12 : 0);
@@ -933,6 +946,7 @@ parsedate(const char *p, const time_t *n
 param.yyRelSeconds = 0;
 param.yyRelMonth = 0;
 param.yyHaveDate = 0;
+

CVS commit: src/lib/libutil

2014-10-07 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Tue Oct  7 22:39:32 UTC 2014

Modified Files:
src/lib/libutil: parsedate.3

Log Message:
Document that years in ISO 8601 dates are taken literally.
69-09-10 is in the year 69, not 2069.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libutil/parsedate.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.3
diff -u src/lib/libutil/parsedate.3:1.12 src/lib/libutil/parsedate.3:1.13
--- src/lib/libutil/parsedate.3:1.12	Sat Jan 19 15:28:25 2013
+++ src/lib/libutil/parsedate.3	Tue Oct  7 22:39:32 2014
@@ -1,4 +1,4 @@
-.\ $NetBSD: parsedate.3,v 1.12 2013/01/19 15:28:25 apb Exp $
+.\ $NetBSD: parsedate.3,v 1.13 2014/10/07 22:39:32 apb Exp $
 .\
 .\ Copyright (c) 2006 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -27,7 +27,7 @@
 .\ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\ POSSIBILITY OF SUCH DAMAGE.
 .\
-.Dd January 19, 2013
+.Dd October 7, 2014
 .Dt PARSEDATE 3
 .Os
 .Sh NAME
@@ -198,11 +198,14 @@ Timezone names:
 .Pp
 A variety of unambiguous dates are recognized:
 .Bl -tag -compact -width 20 Jun 1994
-.It 69-09-10
+.It 9/10/69
 For years between 69-99 we assume 1900+ and for years between 0-68
 we assume 2000+.
 .It 2006-11-17
 An ISO-8601 date.
+.It 69-09-10
+The year in an ISO-8601 date is always taken literally,
+so this is the year 69, not 2069.
 .It 10/1/2000
 October 10, 2000; the common US format.
 .It 20 Jun 1994
@@ -210,7 +213,8 @@ October 10, 2000; the common US format.
 .It 1-sep-06
 Other common abbreviations.
 .It 1/11
-the year can be omitted
+The year can be omitted.
+This is the US month/day format.
 .El
 .Pp
 As well as times:



CVS commit: src/lib/libutil

2014-09-29 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Sep 29 21:04:52 UTC 2014

Modified Files:
src/lib/libutil: opendisk.c

Log Message:
toolify opendisk


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libutil/opendisk.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/opendisk.c
diff -u src/lib/libutil/opendisk.c:1.12 src/lib/libutil/opendisk.c:1.13
--- src/lib/libutil/opendisk.c:1.12	Tue Oct 13 18:00:31 2009
+++ src/lib/libutil/opendisk.c	Mon Sep 29 17:04:52 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: opendisk.c,v 1.12 2009/10/13 22:00:31 pooka Exp $	*/
+/*	$NetBSD: opendisk.c,v 1.13 2014/09/29 21:04:52 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -29,9 +29,13 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#if HAVE_NBTOOL_CONFIG_H
+#include nbtool_config.h
+#endif
+
 #include sys/cdefs.h
 #if defined(LIBC_SCCS)  !defined(lint)
-__RCSID($NetBSD: opendisk.c,v 1.12 2009/10/13 22:00:31 pooka Exp $);
+__RCSID($NetBSD: opendisk.c,v 1.13 2014/09/29 21:04:52 christos Exp $);
 #endif
 
 #include sys/param.h
@@ -39,8 +43,12 @@ __RCSID($NetBSD: opendisk.c,v 1.12 2009
 #include assert.h
 #include errno.h
 #include fcntl.h
+#ifndef HAVE_NBTOOL_CONFIG_H
 #include util.h
 #include paths.h
+#else
+#include opendisk.h
+#endif
 #include stdio.h
 #include string.h
 



CVS commit: src/lib/libutil

2014-09-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Sep 17 23:54:42 UTC 2014

Modified Files:
src/lib/libutil: getdiskrawname.c

Log Message:
KNF, sign cast.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libutil/getdiskrawname.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/getdiskrawname.c
diff -u src/lib/libutil/getdiskrawname.c:1.4 src/lib/libutil/getdiskrawname.c:1.5
--- src/lib/libutil/getdiskrawname.c:1.4	Fri Sep 12 07:38:23 2014
+++ src/lib/libutil/getdiskrawname.c	Wed Sep 17 19:54:42 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: getdiskrawname.c,v 1.4 2014/09/12 11:38:23 mlelstv Exp $	*/
+/*	$NetBSD: getdiskrawname.c,v 1.5 2014/09/17 23:54:42 christos Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include sys/cdefs.h
-__RCSID($NetBSD: getdiskrawname.c,v 1.4 2014/09/12 11:38:23 mlelstv Exp $);
+__RCSID($NetBSD: getdiskrawname.c,v 1.5 2014/09/17 23:54:42 christos Exp $);
 
 #include sys/stat.h
 
@@ -47,7 +47,7 @@ resolve_link(char *buf, size_t bufsiz, c
 	size_t nlen;
 	ssize_t dlen;
 
-	dlen = readlink(name, buf, bufsiz-1);
+	dlen = readlink(name, buf, bufsiz - 1);
 	if (dlen == -1)
 		return name;
 
@@ -62,7 +62,7 @@ resolve_link(char *buf, size_t bufsiz, c
 			if (nlen + dlen + 1  bufsiz)
 return NULL;
 
-			memmove(buf+nlen, buf, dlen+1);
+			memmove(buf + nlen, buf, (size_t)dlen + 1);
 			memcpy(buf, name, nlen);
 		}
 	}



CVS commit: src/lib/libutil

2014-09-12 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Fri Sep 12 07:59:37 UTC 2014

Modified Files:
src/lib/libutil: getdiskrawname.c

Log Message:
- use a private buffer to resolve symlinks, the previous code was broken
- factored out symlink handling
- handle relative symlinks now
- handle device paths that do not contain a '/'.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libutil/getdiskrawname.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/getdiskrawname.c
diff -u src/lib/libutil/getdiskrawname.c:1.2 src/lib/libutil/getdiskrawname.c:1.3
--- src/lib/libutil/getdiskrawname.c:1.2	Sun Dec 22 14:31:51 2013
+++ src/lib/libutil/getdiskrawname.c	Fri Sep 12 07:59:36 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: getdiskrawname.c,v 1.2 2013/12/22 14:31:51 mlelstv Exp $	*/
+/*	$NetBSD: getdiskrawname.c,v 1.3 2014/09/12 07:59:36 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include sys/cdefs.h
-__RCSID($NetBSD: getdiskrawname.c,v 1.2 2013/12/22 14:31:51 mlelstv Exp $);
+__RCSID($NetBSD: getdiskrawname.c,v 1.3 2014/09/12 07:59:36 mlelstv Exp $);
 
 #include sys/stat.h
 
@@ -37,25 +37,51 @@ __RCSID($NetBSD: getdiskrawname.c,v 1.2
 #include string.h
 #include errno.h
 #include util.h
+#include limits.h
 #include unistd.h
 
+static const char *
+resolve_link(char *buf, size_t bufsiz, const char *name)
+{
+	const char *dp;
+	ssize_t nlen, dlen;
+
+	dlen = readlink(name, buf, bufsiz-1);
+	if (dlen == -1)
+		return name;
+
+	buf[dlen] = '\0';
+
+	if (buf[0] != '/') {
+		dp = strrchr(name, '/');
+		if (dp != NULL) {
+			nlen = dp - name + 1;
+			if (nlen + 1  PATH_MAX)
+return NULL;
+			if (nlen + dlen + 1  PATH_MAX)
+return NULL;
+
+			memmove(buf+nlen, buf, dlen+1);
+			memcpy(buf, name, nlen);
+		}
+	}
+
+	return buf;
+}
+
 const char *
 getdiskrawname(char *buf, size_t bufsiz, const char *name)
 {
-	const char *dp = strrchr(name, '/');
+	const char *dp;
 	struct stat st;
-	ssize_t len;
+	char dest[PATH_MAX];
 
-	if (dp == NULL) {
+	if ((name = resolve_link(dest, sizeof(dest), name)) == NULL) {
 		errno = EINVAL;
 		return NULL;
 	}
 
-	len = readlink(name, buf, bufsiz-1);
-	if (len  0) {
-		buf[len] = '\0';
-		name = buf;
-	}
+	dp = strrchr(name, '/');
 
 	if (stat(name, st) == -1)
 		return NULL;
@@ -65,7 +91,10 @@ getdiskrawname(char *buf, size_t bufsiz,
 		return NULL;
 	}
 
-	(void)snprintf(buf, bufsiz, %.*s/r%s, (int)(dp - name), name, dp + 1);
+	if (dp != NULL)
+		(void)snprintf(buf, bufsiz, %.*s/r%s, (int)(dp - name), name, dp + 1);
+	else
+		(void)snprintf(buf, bufsiz, r%s, name);
 
 	return buf;
 }
@@ -75,17 +104,18 @@ getdiskcookedname(char *buf, size_t bufs
 {
 	const char *dp;
 	struct stat st;
-	ssize_t len;
+	char dest[PATH_MAX];
 
-	if ((dp = strrchr(name, '/')) == NULL) {
+	if ((name = resolve_link(dest, sizeof(dest), name)) == NULL) {
 		errno = EINVAL;
 		return NULL;
 	}
 
-	len = readlink(name, buf, bufsiz-1);
-	if (len  0) {
-		buf[len] = '\0';
-		name = buf;
+	dp = strrchr(name, '/');
+
+	if ((dp != NULL  dp[1] != 'r') || (dp == NULL  name[0] != 'r')) {
+		errno = EINVAL;
+		return NULL;
 	}
 
 	if (stat(name, st) == -1)
@@ -96,12 +126,10 @@ getdiskcookedname(char *buf, size_t bufs
 		return NULL;
 	}
 
-	if (dp[1] != 'r') {
-		errno = EINVAL;
-		return NULL;
-	}
-
-	(void)snprintf(buf, bufsiz, %.*s/%s, (int)(dp - name), name, dp + 2);
+	if (dp != NULL)
+		(void)snprintf(buf, bufsiz, %.*s/%s, (int)(dp - name), name, dp + 2);
+	else
+		(void)snprintf(buf, bufsiz, %s, name + 1);
 
 	return buf;
 }



CVS commit: src/lib/libutil

2014-09-12 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Fri Sep 12 11:38:23 UTC 2014

Modified Files:
src/lib/libutil: getdiskrawname.c

Log Message:
use the passed parameter instead of PATH_MAX. Change signedness
of nlen.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libutil/getdiskrawname.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/getdiskrawname.c
diff -u src/lib/libutil/getdiskrawname.c:1.3 src/lib/libutil/getdiskrawname.c:1.4
--- src/lib/libutil/getdiskrawname.c:1.3	Fri Sep 12 07:59:36 2014
+++ src/lib/libutil/getdiskrawname.c	Fri Sep 12 11:38:23 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: getdiskrawname.c,v 1.3 2014/09/12 07:59:36 mlelstv Exp $	*/
+/*	$NetBSD: getdiskrawname.c,v 1.4 2014/09/12 11:38:23 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include sys/cdefs.h
-__RCSID($NetBSD: getdiskrawname.c,v 1.3 2014/09/12 07:59:36 mlelstv Exp $);
+__RCSID($NetBSD: getdiskrawname.c,v 1.4 2014/09/12 11:38:23 mlelstv Exp $);
 
 #include sys/stat.h
 
@@ -44,7 +44,8 @@ static const char *
 resolve_link(char *buf, size_t bufsiz, const char *name)
 {
 	const char *dp;
-	ssize_t nlen, dlen;
+	size_t nlen;
+	ssize_t dlen;
 
 	dlen = readlink(name, buf, bufsiz-1);
 	if (dlen == -1)
@@ -56,9 +57,9 @@ resolve_link(char *buf, size_t bufsiz, c
 		dp = strrchr(name, '/');
 		if (dp != NULL) {
 			nlen = dp - name + 1;
-			if (nlen + 1  PATH_MAX)
+			if (nlen + 1  bufsiz)
 return NULL;
-			if (nlen + dlen + 1  PATH_MAX)
+			if (nlen + dlen + 1  bufsiz)
 return NULL;
 
 			memmove(buf+nlen, buf, dlen+1);



CVS commit: src/lib/libutil

2014-08-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Aug 18 07:33:21 UTC 2014

Modified Files:
src/lib/libutil: getfsspecname.3

Log Message:
fix param name


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libutil/getfsspecname.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/getfsspecname.3
diff -u src/lib/libutil/getfsspecname.3:1.3 src/lib/libutil/getfsspecname.3:1.4
--- src/lib/libutil/getfsspecname.3:1.3	Sat Apr  7 12:22:42 2012
+++ src/lib/libutil/getfsspecname.3	Mon Aug 18 03:33:21 2014
@@ -1,4 +1,4 @@
-.\	$NetBSD: getfsspecname.3,v 1.3 2012/04/07 16:22:42 christos Exp $
+.\	$NetBSD: getfsspecname.3,v 1.4 2014/08/18 07:33:21 christos Exp $
 .\
 .\ Copyright (c) 2012 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -28,7 +28,7 @@
 .\ POSSIBILITY OF SUCH DAMAGE.
 .\
 .\
-.Dd March 6, 2012
+.Dd August 18, 2014
 .Dt GETFSSPECNAME 3
 .Os
 .Sh NAME
@@ -54,7 +54,7 @@ to the underlying
 device node, and places the resulting pathname in
 .Fa buf
 up to len
-.Fa bufsiz .
+.Fa buflen .
 .Pp
 If the
 .Fa spec



CVS commit: src/lib/libutil

2014-05-25 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun May 25 13:46:07 UTC 2014

Modified Files:
src/lib/libutil: getfsspecname.c

Log Message:
In COMPAT_DKWEDGE, attempt to open the label as specified in the NAME= entry.
This works for BSD disklabels, providing full compatibility. Merge some
duplicated code. This means that at least for BSD labels, we can handle
both pre and post- autodiscover kernels with the same fstab.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libutil/getfsspecname.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/getfsspecname.c
diff -u src/lib/libutil/getfsspecname.c:1.4 src/lib/libutil/getfsspecname.c:1.5
--- src/lib/libutil/getfsspecname.c:1.4	Tue Jan  1 13:32:17 2013
+++ src/lib/libutil/getfsspecname.c	Sun May 25 09:46:07 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: getfsspecname.c,v 1.4 2013/01/01 18:32:17 dsl Exp $	*/
+/*	$NetBSD: getfsspecname.c,v 1.5 2014/05/25 13:46:07 christos Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include sys/cdefs.h
-__RCSID($NetBSD: getfsspecname.c,v 1.4 2013/01/01 18:32:17 dsl Exp $);
+__RCSID($NetBSD: getfsspecname.c,v 1.5 2014/05/25 13:46:07 christos Exp $);
 
 #include sys/types.h
 #include sys/ioctl.h
@@ -53,13 +53,12 @@ getfsspecname(char *buf, size_t bufsiz, 
 {
 	static const int mib[] = { CTL_HW, HW_DISKNAMES };
 	static const unsigned int miblen = __arraycount(mib);
-	char *drives, *dk;
+	char *drives, *dk, *p;
 	size_t len;
-	int fd, savee;
+	int fd, savee = errno;
 	char *vname;
 
-	drives = NULL;
-	vname = NULL;
+	p = drives = vname = NULL;
 	if (strncasecmp(name, NAME=, 5) != 0) {
 #ifdef COMPAT_DKWEDGE
 		/*
@@ -129,20 +128,28 @@ search:
 		}
 		(void)close(fd);
 		if (strcmp(vname, (char *)dkw.dkw_wname) == 0) {
-			char *p = strstr(buf, /rdk);
-			if (p++ == NULL) 
-return buf;
-			strcpy(p, p + 1);
-			free(drives);
-			free(vname);
-			return buf;
+			p = strstr(buf, /rdk);
+			goto good;
 		}
 	}
+#ifdef COMPAT_DKWEDGE
+	/* Last ditch effort assuming NAME=label, and label is a disk name */
+	fd = opendisk(name, O_RDONLY, buf, bufsiz, 0);
+	if (fd != -1) {
+		close(fd);
+		p = strstr(buf, /r);
+		goto good;
+	}
+#endif
 	savee = ESRCH;
 	snprintf(buf, bufsiz, no match for `%s', vname);
 out:
+	buf = NULL;
+good:
+	if (p++ != NULL) 
+		strcpy(p, p + 1);
 	free(drives);
 	free(vname);
 	errno = savee;
-	return NULL;
+	return buf;
 }



CVS commit: src/lib/libutil

2013-12-31 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Tue Dec 31 12:58:02 UTC 2013

Modified Files:
src/lib/libutil: sockaddr_snprintf.c

Log Message:
Use output buffer size to limit copy-out of sun_path. Otherwise you may
get a buffer overflow with strlcpy :)


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/libutil/sockaddr_snprintf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/sockaddr_snprintf.c
diff -u src/lib/libutil/sockaddr_snprintf.c:1.10 src/lib/libutil/sockaddr_snprintf.c:1.11
--- src/lib/libutil/sockaddr_snprintf.c:1.10	Fri Jun  7 17:23:26 2013
+++ src/lib/libutil/sockaddr_snprintf.c	Tue Dec 31 12:58:02 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: sockaddr_snprintf.c,v 1.10 2013/06/07 17:23:26 christos Exp $	*/
+/*	$NetBSD: sockaddr_snprintf.c,v 1.11 2013/12/31 12:58:02 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 #include sys/cdefs.h
 #if defined(LIBC_SCCS)  !defined(lint)
-__RCSID($NetBSD: sockaddr_snprintf.c,v 1.10 2013/06/07 17:23:26 christos Exp $);
+__RCSID($NetBSD: sockaddr_snprintf.c,v 1.11 2013/12/31 12:58:02 mlelstv Exp $);
 #endif /* LIBC_SCCS and not lint */
 
 #include sys/types.h
@@ -145,7 +145,7 @@ sockaddr_snprintf(char * const sbuf, con
 		break;
 	case AF_LOCAL:
 		sun = ((const struct sockaddr_un *)(const void *)sa);
-		(void)strlcpy(addr = abuf, sun-sun_path, SUN_LEN(sun));
+		(void)strlcpy(addr = abuf, sun-sun_path, sizeof(abuf));
 		break;
 	case AF_INET:
 		sin4 = ((const struct sockaddr_in *)(const void *)sa);



CVS commit: src/lib/libutil

2013-12-22 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Dec 22 14:31:51 UTC 2013

Modified Files:
src/lib/libutil: getdiskrawname.c

Log Message:
Resolve symlinks and cook the targets instead of the symlink names.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libutil/getdiskrawname.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/getdiskrawname.c
diff -u src/lib/libutil/getdiskrawname.c:1.1 src/lib/libutil/getdiskrawname.c:1.2
--- src/lib/libutil/getdiskrawname.c:1.1	Sat Apr  7 16:44:39 2012
+++ src/lib/libutil/getdiskrawname.c	Sun Dec 22 14:31:51 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: getdiskrawname.c,v 1.1 2012/04/07 16:44:39 christos Exp $	*/
+/*	$NetBSD: getdiskrawname.c,v 1.2 2013/12/22 14:31:51 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include sys/cdefs.h
-__RCSID($NetBSD: getdiskrawname.c,v 1.1 2012/04/07 16:44:39 christos Exp $);
+__RCSID($NetBSD: getdiskrawname.c,v 1.2 2013/12/22 14:31:51 mlelstv Exp $);
 
 #include sys/stat.h
 
@@ -37,18 +37,26 @@ __RCSID($NetBSD: getdiskrawname.c,v 1.1
 #include string.h
 #include errno.h
 #include util.h
+#include unistd.h
 
 const char *
 getdiskrawname(char *buf, size_t bufsiz, const char *name)
 {
 	const char *dp = strrchr(name, '/');
 	struct stat st;
+	ssize_t len;
 
 	if (dp == NULL) {
 		errno = EINVAL;
 		return NULL;
 	}
 
+	len = readlink(name, buf, bufsiz-1);
+	if (len  0) {
+		buf[len] = '\0';
+		name = buf;
+	}
+
 	if (stat(name, st) == -1)
 		return NULL;
 
@@ -67,11 +75,19 @@ getdiskcookedname(char *buf, size_t bufs
 {
 	const char *dp;
 	struct stat st;
+	ssize_t len;
 
 	if ((dp = strrchr(name, '/')) == NULL) {
 		errno = EINVAL;
 		return NULL;
 	}
+
+	len = readlink(name, buf, bufsiz-1);
+	if (len  0) {
+		buf[len] = '\0';
+		name = buf;
+	}
+
 	if (stat(name, st) == -1)
 		return NULL;
 
@@ -79,10 +95,12 @@ getdiskcookedname(char *buf, size_t bufs
 		errno = EFTYPE;
 		return NULL;
 	}
+
 	if (dp[1] != 'r') {
 		errno = EINVAL;
 		return NULL;
 	}
+
 	(void)snprintf(buf, bufsiz, %.*s/%s, (int)(dp - name), name, dp + 2);
 
 	return buf;



CVS commit: src/lib/libutil

2013-08-07 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Wed Aug  7 22:51:59 UTC 2013

Modified Files:
src/lib/libutil: snprintb.3

Log Message:
Add an example using snprintb_m()

Replace \*[Gt] and \*[Lt] with the simple characters  and  (OK wiz)

XXX Note that the examples currently do not compile with GCC!  The hex
XXX character sequences such as \x10CACHE are being parsed as longer
XXX than 2-hex-digit strings!


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/lib/libutil/snprintb.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/snprintb.3
diff -u src/lib/libutil/snprintb.3:1.14 src/lib/libutil/snprintb.3:1.15
--- src/lib/libutil/snprintb.3:1.14	Wed May 13 02:50:32 2009
+++ src/lib/libutil/snprintb.3	Wed Aug  7 22:51:59 2013
@@ -1,4 +1,4 @@
-.\ $NetBSD: snprintb.3,v 1.14 2009/05/13 02:50:32 pgoyette Exp $
+.\ $NetBSD: snprintb.3,v 1.15 2013/08/07 22:51:59 pgoyette Exp $
 .\
 .\ Copyright (c) 1998 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -225,14 +225,14 @@ total number of bytes.
 Two examples of the old formatting style:
 .Bd -literal -offset indent
 snprintb(buf, buflen, \e10\e2BITTWO\e1BITONE, 3)
-\(rA 3\*[Lt]BITTWO,BITONE\*[Gt]
+\(rA 03BITTWO,BITONE
 
 snprintb(buf, buflen,
\e20\ex10NOTBOOT\ex0fFPP\ex0eSDVMA\ex0cVIDEO
\ex0bLORES\ex0aFPA\ex09DIAG\ex07CACHE
\ex06IOCACHE\ex05LOOPBACK\ex04DBGCACHE,
0xe860)
-\(rA e860\*[Lt]NOTBOOT,FPP,SDVMA,VIDEO,CACHE,IOCACHE\*[Gt]
+\(rA 0xe860NOTBOOT,FPP,SDVMA,VIDEO,CACHE,IOCACHE
 .Ed
 .Pp
 An example of the new formatting style:
@@ -242,7 +242,17 @@ snprintb(buf, buflen,
f\ex10\e4BURST\e0=\e4FOUR\e0=\exfSIXTEEN\e0
b\ex1fMSB\e0\e0,
0x800f0701)
-\(rA 800f0701\*[Lt]LSB,NIBBLE2=0,BURST=f=SIXTEEN,MSB\*[Gt]
+\(rA 0x800f0701LSB,NIBBLE2=0x0,BURST=0xf=SIXTEEN,MSB
+.Ed
+.Pp
+An example using snprintb_m:
+.Bd -literal -offset indent
+snprintb_m(buf, buflen,
+   \e177\e020b\e0LSB\e0b\e1_BITONE\e0f\e4\e4NIBBLE2\e0
+   f\ex10\e4BURST\e0=\e4FOUR\e0=\exfSIXTEEN\e0
+   b\ex1fMSB\e0\e0,
+   0x800f0701, 34)
+\(rA 0x800f0701LSB,NIBBLE2=0x0\e00x800f0701BURST=0xf=SIXTEEN,MSB\e0
 .Ed
 .Sh ERRORS
 .Fn snprintb



CVS commit: src/lib/libutil

2013-08-07 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Wed Aug  7 23:22:28 UTC 2013

Modified Files:
src/lib/libutil: snprintb.3

Log Message:
Update example using hex-escape-sequences to conform to gcc parsing rules.
(See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33167 for details.)


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/lib/libutil/snprintb.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/snprintb.3
diff -u src/lib/libutil/snprintb.3:1.15 src/lib/libutil/snprintb.3:1.16
--- src/lib/libutil/snprintb.3:1.15	Wed Aug  7 22:51:59 2013
+++ src/lib/libutil/snprintb.3	Wed Aug  7 23:22:28 2013
@@ -1,4 +1,4 @@
-.\ $NetBSD: snprintb.3,v 1.15 2013/08/07 22:51:59 pgoyette Exp $
+.\ $NetBSD: snprintb.3,v 1.16 2013/08/07 23:22:28 pgoyette Exp $
 .\
 .\ Copyright (c) 1998 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -228,9 +228,9 @@ snprintb(buf, buflen, \e10\e2BITTWO\e1B
 \(rA 03BITTWO,BITONE
 
 snprintb(buf, buflen,
-   \e20\ex10NOTBOOT\ex0fFPP\ex0eSDVMA\ex0cVIDEO
-   \ex0bLORES\ex0aFPA\ex09DIAG\ex07CACHE
-   \ex06IOCACHE\ex05LOOPBACK\ex04DBGCACHE,
+   \e20\ex10NOTBOOT\ex0f FPP\ex0eSDVMA\ex0cVIDEO
+   \ex0bLORES\ex0a FPA\ex09 DIAG\ex07 CACHE
+   \ex06IOCACHE\ex05LOOPBACK\ex04 DBGCACHE,
0xe860)
 \(rA 0xe860NOTBOOT,FPP,SDVMA,VIDEO,CACHE,IOCACHE
 .Ed



CVS commit: src/lib/libutil

2013-06-23 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Jun 23 08:38:41 UTC 2013

Modified Files:
src/lib/libutil: login_cap.3

Log Message:
Put code example on its own line, using Dl.
Ok christos


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/lib/libutil/login_cap.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/login_cap.3
diff -u src/lib/libutil/login_cap.3:1.20 src/lib/libutil/login_cap.3:1.21
--- src/lib/libutil/login_cap.3:1.20	Fri Jun 21 08:18:24 2013
+++ src/lib/libutil/login_cap.3	Sun Jun 23 08:38:41 2013
@@ -1,4 +1,4 @@
-.\ $NetBSD: login_cap.3,v 1.20 2013/06/21 08:18:24 wiz Exp $
+.\ $NetBSD: login_cap.3,v 1.21 2013/06/23 08:38:41 wiz Exp $
 .\
 .\ Copyright (c) 1996,1997 Berkeley Software Design, Inc. All rights reserved.
 .\
@@ -102,10 +102,7 @@ function.
 The
 .Fn login_getpwclass
 function is equivalent to:
-login_getclass(
-.Fa pwd
-? pwd-pw_class :
-.Dv NULL ) .
+.Dl login_getclass(pwd\ ? pwd-pw_class\ : NULL)
 .Pp
 Once
 .Ar lc



CVS commit: src/lib/libutil

2013-06-21 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Fri Jun 21 08:18:25 UTC 2013

Modified Files:
src/lib/libutil: login_cap.3

Log Message:
Punctuation nit.
(Shouldn't the whole line be .Dl or .Bl -literal instead?)


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/lib/libutil/login_cap.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/login_cap.3
diff -u src/lib/libutil/login_cap.3:1.19 src/lib/libutil/login_cap.3:1.20
--- src/lib/libutil/login_cap.3:1.19	Thu Jun 20 20:42:30 2013
+++ src/lib/libutil/login_cap.3	Fri Jun 21 08:18:24 2013
@@ -1,4 +1,4 @@
-.\ $NetBSD: login_cap.3,v 1.19 2013/06/20 20:42:30 christos Exp $
+.\ $NetBSD: login_cap.3,v 1.20 2013/06/21 08:18:24 wiz Exp $
 .\
 .\ Copyright (c) 1996,1997 Berkeley Software Design, Inc. All rights reserved.
 .\
@@ -105,7 +105,7 @@ function is equivalent to:
 login_getclass(
 .Fa pwd
 ? pwd-pw_class :
-.Dv NULL ).
+.Dv NULL ) .
 .Pp
 Once
 .Ar lc



CVS commit: src/lib/libutil

2013-06-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jun 20 20:42:30 UTC 2013

Modified Files:
src/lib/libutil: Makefile login_cap.3

Log Message:
document login_getpwclass(3)


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/lib/libutil/Makefile
cvs rdiff -u -r1.18 -r1.19 src/lib/libutil/login_cap.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/Makefile
diff -u src/lib/libutil/Makefile:1.74 src/lib/libutil/Makefile:1.75
--- src/lib/libutil/Makefile:1.74	Thu May  2 03:17:09 2013
+++ src/lib/libutil/Makefile	Thu Jun 20 16:42:30 2013
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.74 2013/05/02 07:17:09 matt Exp $
+#	$NetBSD: Makefile,v 1.75 2013/06/20 20:42:30 christos Exp $
 #	@(#)Makefile	8.1 (Berkeley) 6/4/93
 
 USE_SHLIBDIR=	yes
@@ -51,6 +51,7 @@ MLINKS+=login_cap.3 login_getcapnum.3
 MLINKS+=login_cap.3 login_getcapsize.3
 MLINKS+=login_cap.3 login_getcapstr.3
 MLINKS+=login_cap.3 login_getcaptime.3
+MLINKS+=login_cap.3 login_getpwclass.3
 MLINKS+=login_cap.3 login_close.3
 MLINKS+=login_cap.3 setclasscontext.3
 MLINKS+=login_cap.3 setusercontext.3

Index: src/lib/libutil/login_cap.3
diff -u src/lib/libutil/login_cap.3:1.18 src/lib/libutil/login_cap.3:1.19
--- src/lib/libutil/login_cap.3:1.18	Wed May  5 18:05:31 2010
+++ src/lib/libutil/login_cap.3	Thu Jun 20 16:42:30 2013
@@ -1,4 +1,4 @@
-.\ $NetBSD: login_cap.3,v 1.18 2010/05/05 22:05:31 wiz Exp $
+.\ $NetBSD: login_cap.3,v 1.19 2013/06/20 20:42:30 christos Exp $
 .\
 .\ Copyright (c) 1996,1997 Berkeley Software Design, Inc. All rights reserved.
 .\
@@ -32,7 +32,7 @@
 .\
 .\ BSDI login_cap.3,v 1.4 1997/11/07 16:22:27 jch Exp
 .\
-.Dd October 6, 2007
+.Dd June 20, 2013
 .Dt LOGIN_CAP 3
 .Os
 .Sh NAME
@@ -42,6 +42,7 @@
 .Nm login_getcapsize ,
 .Nm login_getcapstr ,
 .Nm login_getcaptime ,
+.Nm login_getpwclass ,
 .Nm login_close ,
 .Nm setclasscontext ,
 .Nm setusercontext
@@ -63,6 +64,8 @@
 .Fn login_getcapstr login_cap_t *lc const char *cap char *def char *err
 .Ft quad_t
 .Fn login_getcaptime login_cap_t *lc const char *cap quad_t def quad_t err
+.Ft login_cap_t *
+.Fn login_getpwclass struct passwd *pwd
 .Ft void
 .Fn login_close login_cap_t *lc
 .Ft int
@@ -96,6 +99,14 @@ structure is no longer needed, it should
 .Fn login_close
 function.
 .Pp
+The
+.Fn login_getpwclass
+function is equivalent to:
+login_getclass(
+.Fa pwd
+? pwd-pw_class :
+.Dv NULL ).
+.Pp
 Once
 .Ar lc
 has been returned by



CVS commit: src/lib/libutil

2013-06-11 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Wed Jun 12 01:31:25 UTC 2013

Modified Files:
src/lib/libutil: parsedate.y

Log Message:
add rcsid


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/lib/libutil/parsedate.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.y
diff -u src/lib/libutil/parsedate.y:1.14 src/lib/libutil/parsedate.y:1.15
--- src/lib/libutil/parsedate.y:1.14	Sat Jan 19 15:23:33 2013
+++ src/lib/libutil/parsedate.y	Wed Jun 12 01:31:24 2013
@@ -12,6 +12,11 @@
 /* SUPPRESS 287 on yaccpar_sccsid *//* Unused static variable */
 /* SUPPRESS 288 on yyerrlab *//* Label unused */
 
+#include sys/cdefs.h
+#ifdef __RCSID
+__RCSID($NetBSD: parsedate.y,v 1.15 2013/06/12 01:31:24 yamt Exp $);
+#endif
+
 #include stdio.h
 #include ctype.h
 #include errno.h



CVS commit: src/lib/libutil

2013-06-11 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Wed Jun 12 01:46:07 UTC 2013

Modified Files:
src/lib/libutil: parsedate.y

Log Message:
fix timezone bugs in rev.1.11 and rev.1.13.  PR/47916.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/lib/libutil/parsedate.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.y
diff -u src/lib/libutil/parsedate.y:1.15 src/lib/libutil/parsedate.y:1.16
--- src/lib/libutil/parsedate.y:1.15	Wed Jun 12 01:31:24 2013
+++ src/lib/libutil/parsedate.y	Wed Jun 12 01:46:07 2013
@@ -14,7 +14,7 @@
 
 #include sys/cdefs.h
 #ifdef __RCSID
-__RCSID($NetBSD: parsedate.y,v 1.15 2013/06/12 01:31:24 yamt Exp $);
+__RCSID($NetBSD: parsedate.y,v 1.16 2013/06/12 01:46:07 yamt Exp $);
 #endif
 
 #include stdio.h
@@ -593,7 +593,7 @@ Convert(
 time_t	Hours,		/* Hour of day [0-24] */
 time_t	Minutes,	/* Minute of hour [0-59] */
 time_t	Seconds,	/* Second of minute [0-60] */
-time_t	Timezone,	/* Timezone as seconds west of UTC */
+time_t	Timezone,	/* Timezone as minutes east of UTC */
 MERIDIAN	Meridian,	/* Hours are am/pm/24 hour clock */
 DSTMODE	DSTmode		/* DST on/off/maybe */
 )
@@ -623,7 +623,7 @@ Convert(
 
 /* We rely on mktime_z(NULL, ...) working in UTC, not in local time. */
 result = mktime_z(NULL, tm);
-result -= Timezone;
+result += Timezone * 60;
 return result;
 }
 



CVS commit: src/lib/libutil

2013-06-07 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jun  7 17:23:26 UTC 2013

Modified Files:
src/lib/libutil: sockaddr_snprintf.3 sockaddr_snprintf.c

Log Message:
Add a debugging format that prints all the fields with names.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/libutil/sockaddr_snprintf.3
cvs rdiff -u -r1.9 -r1.10 src/lib/libutil/sockaddr_snprintf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/sockaddr_snprintf.3
diff -u src/lib/libutil/sockaddr_snprintf.3:1.7 src/lib/libutil/sockaddr_snprintf.3:1.8
--- src/lib/libutil/sockaddr_snprintf.3:1.7	Sat Apr 11 12:13:49 2009
+++ src/lib/libutil/sockaddr_snprintf.3	Fri Jun  7 13:23:26 2013
@@ -1,4 +1,4 @@
-.\ $NetBSD: sockaddr_snprintf.3,v 1.7 2009/04/11 16:13:49 joerg Exp $
+.\ $NetBSD: sockaddr_snprintf.3,v 1.8 2013/06/07 17:23:26 christos Exp $
 .\
 .\ Copyright (c) 2004 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -27,7 +27,7 @@
 .\ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\ POSSIBILITY OF SUCH DAMAGE.
 .\
-.Dd April 9, 2005
+.Dd June 7, 2013
 .Dt SOCKADDR_SNPRINTF 3
 .Os
 .Sh NAME
@@ -109,6 +109,10 @@ this is the hostname associated with the
 For all other address families, it is the same as the
 .Dq a
 format.
+.It D
+Debugging output:
+For all addresses, print all their fields as
+.Dq field_name=value .
 .It f
 The numeric value of the family of the address is printed.
 .It l

Index: src/lib/libutil/sockaddr_snprintf.c
diff -u src/lib/libutil/sockaddr_snprintf.c:1.9 src/lib/libutil/sockaddr_snprintf.c:1.10
--- src/lib/libutil/sockaddr_snprintf.c:1.9	Mon Apr 28 16:23:03 2008
+++ src/lib/libutil/sockaddr_snprintf.c	Fri Jun  7 13:23:26 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: sockaddr_snprintf.c,v 1.9 2008/04/28 20:23:03 martin Exp $	*/
+/*	$NetBSD: sockaddr_snprintf.c,v 1.10 2013/06/07 17:23:26 christos Exp $	*/
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 #include sys/cdefs.h
 #if defined(LIBC_SCCS)  !defined(lint)
-__RCSID($NetBSD: sockaddr_snprintf.c,v 1.9 2008/04/28 20:23:03 martin Exp $);
+__RCSID($NetBSD: sockaddr_snprintf.c,v 1.10 2013/06/07 17:23:26 christos Exp $);
 #endif /* LIBC_SCCS and not lint */
 
 #include sys/types.h
@@ -44,9 +44,71 @@ __RCSID($NetBSD: sockaddr_snprintf.c,v 
 #include stdio.h
 #include string.h
 #include errno.h
+#include stdlib.h
 #include util.h
 #include netdb.h
 
+static int
+debug_at(char *str, size_t len, const struct sockaddr_at *sat)
+{
+	return snprintf(str, len, sat_len=%u, sat_family=%u, sat_port=%u, 
+	sat_addr.s_net=%u, sat_addr.s_node=%u, 
+	sat_range.r_netrange.nr_phase=%u, 
+	sat_range.r_netrange.nr_firstnet=%u, 
+	sat_range.r_netrange.nr_lastnet=%u,
+	sat-sat_len, sat-sat_family, sat-sat_port,
+	sat-sat_addr.s_net, sat-sat_addr.s_node,
+	sat-sat_range.r_netrange.nr_phase,
+	sat-sat_range.r_netrange.nr_firstnet,
+	sat-sat_range.r_netrange.nr_lastnet);
+}
+
+static int
+debug_in(char *str, size_t len, const struct sockaddr_in *sin)
+{
+	return snprintf(str, len, sin_len=%u, sin_family=%u, sin_port=%u, 
+	sin_addr.s_addr=%08x,
+	sin-sin_len, sin-sin_family, sin-sin_port,
+	sin-sin_addr.s_addr);
+}
+
+static int
+debug_in6(char *str, size_t len, const struct sockaddr_in6 *sin6)
+{
+	const uint8_t *s = sin6-sin6_addr.s6_addr;
+
+	return snprintf(str, len, sin6_len=%u, sin6_family=%u, sin6_port=%u, 
+	sin6_flowinfo=%u, 
+	sin6_addr=%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:
+	%02x:%02x:%02x:%02x:%02x:%02x, sin6_scope_id=%u,
+	sin6-sin6_len, sin6-sin6_family, sin6-sin6_port,
+	sin6-sin6_flowinfo, s[0x0], s[0x1], s[0x2], s[0x3], s[0x4], s[0x5],
+	s[0x6], s[0x7], s[0x8], s[0x9], s[0xa], s[0xb], s[0xc], s[0xd],
+	s[0xe], s[0xf], sin6-sin6_scope_id);
+}
+
+static int
+debug_un(char *str, size_t len, const struct sockaddr_un *sun)
+{
+	return snprintf(str, len, sun_len=%u, sun_family=%u, sun_path=%*s,
+	sun-sun_len, sun-sun_family, (int)sizeof(sun-sun_path),
+	sun-sun_path);
+}
+
+static int
+debug_dl(char *str, size_t len, const struct sockaddr_dl *sdl)
+{
+	const uint8_t *s = (const void *)sdl-sdl_data;
+
+	return snprintf(str, len, sdl_len=%u, sdl_family=%u, sdl_index=%u, 
+	sdl_type=%u, sdl_nlen=%u, sdl_alen=%u, sdl_slen=%u, sdl_data=
+	%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x,
+	sdl-sdl_len, sdl-sdl_family, sdl-sdl_index,
+	sdl-sdl_type, sdl-sdl_nlen, sdl-sdl_alen, sdl-sdl_slen,
+	s[0x0], s[0x1], s[0x2], s[0x3], s[0x4], s[0x5],
+	s[0x6], s[0x7], s[0x8], s[0x9], s[0xa], s[0xb]);
+}
+
 int
 sockaddr_snprintf(char * const sbuf, const size_t len, const char * const fmt,
 const struct sockaddr * const sa)
@@ -207,6 +269,28 @@ sockaddr_snprintf(char * const sbuf, con
 ADDNA();
 			}
 			break;
+		case 'D':
+			switch (sa-sa_family) {
+			

CVS commit: src/lib/libutil

2013-05-03 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Fri May  3 20:21:24 UTC 2013

Modified Files:
src/lib/libutil: getbyteorder.3

Log Message:
Use more markup.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libutil/getbyteorder.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/getbyteorder.3
diff -u src/lib/libutil/getbyteorder.3:1.1 src/lib/libutil/getbyteorder.3:1.2
--- src/lib/libutil/getbyteorder.3:1.1	Thu May  2 07:17:09 2013
+++ src/lib/libutil/getbyteorder.3	Fri May  3 20:21:24 2013
@@ -1,4 +1,4 @@
-.\	$NetBSD: getbyteorder.3,v 1.1 2013/05/02 07:17:09 matt Exp $
+.\	$NetBSD: getbyteorder.3,v 1.2 2013/05/03 20:21:24 wiz Exp $
 .\
 .\ Copyright (c) 1996 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -42,7 +42,9 @@
 .Fn getbyteorder void
 .Sh DESCRIPTION
 .Fn getbyteorder
-returns LITTLE_ENDIAN, BIG_ENDIAN,
+returns
+.Dv LITTLE_ENDIAN ,
+.Dv BIG_ENDIAN ,
 or \-1 in case of an error, setting the global
 .Va errno
 variable.



CVS commit: src/lib/libutil

2013-05-02 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Thu May  2 07:17:10 UTC 2013

Modified Files:
src/lib/libutil: Makefile
Added Files:
src/lib/libutil: getbyteorder.3 getbyteorder.c

Log Message:
Add getbyteorder() call.


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/lib/libutil/Makefile
cvs rdiff -u -r0 -r1.1 src/lib/libutil/getbyteorder.3 \
src/lib/libutil/getbyteorder.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/Makefile
diff -u src/lib/libutil/Makefile:1.73 src/lib/libutil/Makefile:1.74
--- src/lib/libutil/Makefile:1.73	Sat Apr  7 16:44:39 2012
+++ src/lib/libutil/Makefile	Thu May  2 07:17:09 2013
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.73 2012/04/07 16:44:39 christos Exp $
+#	$NetBSD: Makefile,v 1.74 2013/05/02 07:17:09 matt Exp $
 #	@(#)Makefile	8.1 (Berkeley) 6/4/93
 
 USE_SHLIBDIR=	yes
@@ -11,7 +11,8 @@ WARNS?=	5
 LIB=	util
 CPPFLAGS+=-DLIBC_SCCS -I${.CURDIR}
 LINTFLAGS+=-w
-SRCS+=	efun.c getbootfile.c getlabelsector.c getmaxpartitions.c \
+SRCS+=	efun.c \
+	getbootfile.c getbyteorder.c getlabelsector.c getmaxpartitions.c \
 	getfsspecname.c getmntopts.c getrawpartition.c getdiskrawname.c \
 	disklabel_dkcksum.c disklabel_scan.c \
 	if_media.c \
@@ -22,7 +23,8 @@ SRCS+=	efun.c getbootfile.c getlabelsect
 	secure_path.c sockaddr_snprintf.c stat_flags.c \
 	strpct.c ttyaction.c ttymsg.c
 
-MAN=	efun.3 getbootfile.3 getfstypename.3 getlabelsector.3 \
+MAN=	efun.3 \
+	getbootfile.3 getbyteorder.3 getfstypename.3 getlabelsector.3 \
 	getmaxpartitions.3 getmntopts.3 getrawpartition.3 \
 	getdiskrawname.3 getfsspecname.3 \
 	login.3 login_cap.3 loginx.3 \

Added files:

Index: src/lib/libutil/getbyteorder.3
diff -u /dev/null src/lib/libutil/getbyteorder.3:1.1
--- /dev/null	Thu May  2 07:17:10 2013
+++ src/lib/libutil/getbyteorder.3	Thu May  2 07:17:09 2013
@@ -0,0 +1,59 @@
+.\	$NetBSD: getbyteorder.3,v 1.1 2013/05/02 07:17:09 matt Exp $
+.\
+.\ Copyright (c) 1996 The NetBSD Foundation, Inc.
+.\ All rights reserved.
+.\
+.\ This code is derived from software contributed to The NetBSD Foundation
+.\ by Jason R. Thorpe.
+.\
+.\ Redistribution and use in source and binary forms, with or without
+.\ modification, are permitted provided that the following conditions
+.\ are met:
+.\ 1. Redistributions of source code must retain the above copyright
+.\notice, this list of conditions and the following disclaimer.
+.\ 2. Redistributions in binary form must reproduce the above copyright
+.\notice, this list of conditions and the following disclaimer in the
+.\documentation and/or other materials provided with the distribution.
+.\
+.\ THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\ PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\ POSSIBILITY OF SUCH DAMAGE.
+.\
+.Dd May 1, 2013
+.Dt GETBYTEORDER 3
+.Os
+.Sh NAME
+.Nm getbyteorder
+.Nd get the current byte order
+.Sh LIBRARY
+.Lb libutil
+.Sh SYNOPSIS
+.In util.h
+.In sys/endian.h
+.Ft int
+.Fn getbyteorder void
+.Sh DESCRIPTION
+.Fn getbyteorder
+returns LITTLE_ENDIAN, BIG_ENDIAN,
+or \-1 in case of an error, setting the global
+.Va errno
+variable.
+The possible values for
+.Va errno
+are the same as in
+.Xr sysctl 3 .
+.Sh SEE ALSO
+.Xr sysctl 3
+.Sh HISTORY
+The
+.Fn getbyteorder
+function call appeared in
+.Nx 7 .
Index: src/lib/libutil/getbyteorder.c
diff -u /dev/null src/lib/libutil/getbyteorder.c:1.1
--- /dev/null	Thu May  2 07:17:10 2013
+++ src/lib/libutil/getbyteorder.c	Thu May  2 07:17:10 2013
@@ -0,0 +1,54 @@
+/*	$NetBSD: getbyteorder.c,v 1.1 2013/05/02 07:17:10 matt Exp $	*/
+
+/*-
+ * Copyright (c) 1996 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or 

CVS commit: src/lib/libutil

2013-01-19 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Sat Jan 19 09:27:32 UTC 2013

Modified Files:
src/lib/libutil: parsedate.y

Log Message:
mktime(3) works in local time, and trying to trick it by
setting tm_gmtoff doesn't work.  Instead, call mktime_z(3)
with a null timezone (so it works in UTC) and adjust the
result afterwards.  Now date -d @0 correctly
prints the local equivalent of 1970-01-01 00:00:00 UTC.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libutil/parsedate.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.y
diff -u src/lib/libutil/parsedate.y:1.12 src/lib/libutil/parsedate.y:1.13
--- src/lib/libutil/parsedate.y:1.12	Thu Sep 13 21:44:50 2012
+++ src/lib/libutil/parsedate.y	Sat Jan 19 09:27:32 2013
@@ -590,7 +590,8 @@ Convert(
 DSTMODE	DSTmode		/* DST on/off/maybe */
 )
 {
-struct tm tm;
+struct tm tm = {.tm_sec = 0};
+time_t result;
 
 /* XXX Y2K */
 if (Year  0)
@@ -611,9 +612,11 @@ Convert(
 case DSToff: tm.tm_isdst = 0; break;
 default: tm.tm_isdst = -1; break;
 }
-tm.tm_gmtoff = -Timezone;
 
-return mktime(tm);
+/* We rely on mktime_z(NULL, ...) working in UTC, not in local time. */
+result = mktime_z(NULL, tm);
+result -= Timezone;
+return result;
 }
 
 



CVS commit: src/lib/libutil

2013-01-19 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Sat Jan 19 15:23:33 UTC 2013

Modified Files:
src/lib/libutil: parsedate.y

Log Message:
Distinguish between a non-error result of (time_t)-1 and an error result.
Modernise the test code inside #ifdef TEST.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libutil/parsedate.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.y
diff -u src/lib/libutil/parsedate.y:1.13 src/lib/libutil/parsedate.y:1.14
--- src/lib/libutil/parsedate.y:1.13	Sat Jan 19 09:27:32 2013
+++ src/lib/libutil/parsedate.y	Sat Jan 19 15:23:33 2013
@@ -14,6 +14,7 @@
 
 #include stdio.h
 #include ctype.h
+#include errno.h
 #include string.h
 #include time.h
 #include util.h
@@ -148,8 +149,8 @@ cvsstamp: tUNUMBER '.' tUNUMBER '.' tUNU
 	}
 	;
 
-epochdate: AT_SIGN tUNUMBER {
-time_twhen = $2;
+epochdate: AT_SIGN at_number {
+time_twhen = $Number2;
 struct tm tmbuf;
 if (gmtime_r(when, tmbuf) != NULL) {
 		param-yyYear = tmbuf.tm_year + 1900;
@@ -173,6 +174,8 @@ epochdate: AT_SIGN tUNUMBER {
 	}
 	;
 
+at_number : tUNUMBER | tSNUMBER ;
+
 time	: tUNUMBER tMERIDIAN {
 	param-yyHour = $1;
 	param-yyMinutes = 0;
@@ -883,6 +886,10 @@ parsedate(const char *p, const time_t *n
 time_t		Start;
 time_t		tod, rm;
 struct dateinfo	param;
+int			saved_errno;
+
+saved_errno = errno;
+errno = 0;
 
 if (now == NULL || zone == NULL) {
 now = nowt;
@@ -927,14 +934,16 @@ parsedate(const char *p, const time_t *n
 param.yyHaveZone = 0;
 
 if (yyparse(param, p) || param.yyHaveTime  1 || param.yyHaveZone  1 ||
-	param.yyHaveDate  1 || param.yyHaveDay  1)
+	param.yyHaveDate  1 || param.yyHaveDay  1) {
+	errno = EINVAL;
 	return -1;
+}
 
 if (param.yyHaveDate || param.yyHaveTime || param.yyHaveDay) {
 	Start = Convert(param.yyMonth, param.yyDay, param.yyYear, param.yyHour,
 	param.yyMinutes, param.yySeconds, param.yyTimezone,
 	param.yyMeridian, param.yyDSTmode);
-	if (Start == -1)
+	if (Start == -1  errno != 0)
 	return -1;
 }
 else {
@@ -945,7 +954,7 @@ parsedate(const char *p, const time_t *n
 
 Start += param.yyRelSeconds;
 rm = RelativeMonth(Start, param.yyRelMonth, param.yyTimezone);
-if (rm == -1)
+if (rm == -1  errno != 0)
 	return -1;
 Start += rm;
 
@@ -954,6 +963,8 @@ parsedate(const char *p, const time_t *n
 	Start += tod;
 }
 
+if (errno == 0)
+	errno = saved_errno;
 return Start;
 }
 
@@ -962,21 +973,21 @@ parsedate(const char *p, const time_t *n
 
 /* ARGSUSED */
 int
-main(ac, av)
-int		ac;
-char	*av[];
+main(int ac, char *av[])
 {
 char	buff[128];
 time_t	d;
 
 (void)printf(Enter date, or blank line to exit.\n\t );
 (void)fflush(stdout);
-while (gets(buff)  buff[0]) {
+while (fgets(buff, sizeof(buff), stdin)  buff[0] != '\n') {
+	errno = 0;
 	d = parsedate(buff, NULL, NULL);
-	if (d == -1)
-	(void)printf(Bad format - couldn't convert.\n);
+	if (d == -1  errno != 0)
+	(void)printf(Bad format - couldn't convert: %s\n,
+	strerror(errno));
 	else
-	(void)printf(%s, ctime(d));
+	(void)printf(%jd\t%s, (intmax_t)d, ctime(d));
 	(void)printf(\t );
 	(void)fflush(stdout);
 }



CVS commit: src/lib/libutil

2013-01-19 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Sat Jan 19 15:28:25 UTC 2013

Modified Files:
src/lib/libutil: parsedate.3

Log Message:
Document that errno may be used to distinguish between a
non-error result of -1 and an error.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/lib/libutil/parsedate.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/parsedate.3
diff -u src/lib/libutil/parsedate.3:1.11 src/lib/libutil/parsedate.3:1.12
--- src/lib/libutil/parsedate.3:1.11	Fri Apr  6 11:36:04 2012
+++ src/lib/libutil/parsedate.3	Sat Jan 19 15:28:25 2013
@@ -1,4 +1,4 @@
-.\ $NetBSD: parsedate.3,v 1.11 2012/04/06 11:36:04 wiz Exp $
+.\ $NetBSD: parsedate.3,v 1.12 2013/01/19 15:28:25 apb Exp $
 .\
 .\ Copyright (c) 2006 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -27,7 +27,7 @@
 .\ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\ POSSIBILITY OF SUCH DAMAGE.
 .\
-.Dd December 20, 2010
+.Dd January 19, 2013
 .Dt PARSEDATE 3
 .Os
 .Sh NAME
@@ -241,8 +241,20 @@ Tue Apr 20 03:06:49 UTC 1993
 returns the number of seconds passed since the Epoch, or
 .Dv \-1
 if the date could not be parsed properly.
+A non-error result of
+.Dv \-1
+can be distinguished from an error by setting
+.Va errno
+to
+.Dv 0
+before calling
+.Fn parsedate ,
+and checking the value of
+.Va errno
+afterwards.
 .Sh SEE ALSO
 .Xr date 1 ,
+.Xr errno 2 ,
 .Xr eeprom 8
 .Sh HISTORY
 The parser used in



CVS commit: src/lib/libutil

2013-01-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Jan 15 22:42:14 UTC 2013

Modified Files:
src/lib/libutil: ttymsg.3

Log Message:
add some things to add next time we modify the function


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/lib/libutil/ttymsg.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/ttymsg.3
diff -u src/lib/libutil/ttymsg.3:1.11 src/lib/libutil/ttymsg.3:1.12
--- src/lib/libutil/ttymsg.3:1.11	Wed Apr 30 09:10:52 2008
+++ src/lib/libutil/ttymsg.3	Tue Jan 15 17:42:14 2013
@@ -1,4 +1,4 @@
-.\ $NetBSD: ttymsg.3,v 1.11 2008/04/30 13:10:52 martin Exp $
+.\ $NetBSD: ttymsg.3,v 1.12 2013/01/15 22:42:14 christos Exp $
 .\
 .\ Copyright (c) 1996 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -24,7 +24,7 @@
 .\ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\ POSSIBILITY OF SUCH DAMAGE.
 .\
-.Dd June 29, 1997
+.Dd January 15, 2013
 .Dt TTYMSG 3
 .Os
 .Sh NAME
@@ -56,5 +56,13 @@ returns a pointer to an error string on 
 error; the string is not newline-terminated.
 Various normal errors are
 ignored (exclusive-use, lack of permission, etc.).
+.Sh BUGS
+.Nm
+could grow some flags and a username/uid who is the expected owner
+of the tty.
+If the flags say so then the owner should be checked against the tty
+owner, and the message should not be sent if there is a mismatch.
+Also another flag could say check against group writable, and don't
+send a message.
 .Sh SEE ALSO
 .Xr writev 2



CVS commit: src/lib/libutil

2013-01-15 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Wed Jan 16 06:44:28 UTC 2013

Modified Files:
src/lib/libutil: ttymsg.3

Log Message:
Sort sections.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libutil/ttymsg.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/ttymsg.3
diff -u src/lib/libutil/ttymsg.3:1.12 src/lib/libutil/ttymsg.3:1.13
--- src/lib/libutil/ttymsg.3:1.12	Tue Jan 15 22:42:14 2013
+++ src/lib/libutil/ttymsg.3	Wed Jan 16 06:44:27 2013
@@ -1,4 +1,4 @@
-.\ $NetBSD: ttymsg.3,v 1.12 2013/01/15 22:42:14 christos Exp $
+.\ $NetBSD: ttymsg.3,v 1.13 2013/01/16 06:44:27 wiz Exp $
 .\
 .\ Copyright (c) 1996 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -56,6 +56,8 @@ returns a pointer to an error string on 
 error; the string is not newline-terminated.
 Various normal errors are
 ignored (exclusive-use, lack of permission, etc.).
+.Sh SEE ALSO
+.Xr writev 2
 .Sh BUGS
 .Nm
 could grow some flags and a username/uid who is the expected owner
@@ -64,5 +66,3 @@ If the flags say so then the owner shoul
 owner, and the message should not be sent if there is a mismatch.
 Also another flag could say check against group writable, and don't
 send a message.
-.Sh SEE ALSO
-.Xr writev 2



CVS commit: src/lib/libutil

2013-01-01 Thread David Laight
Module Name:src
Committed By:   dsl
Date:   Tue Jan  1 18:32:17 UTC 2013

Modified Files:
src/lib/libutil: getfsspecname.c

Log Message:
Don't rely on something including sys/ioctl.h for us.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libutil/getfsspecname.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/getfsspecname.c
diff -u src/lib/libutil/getfsspecname.c:1.3 src/lib/libutil/getfsspecname.c:1.4
--- src/lib/libutil/getfsspecname.c:1.3	Sun Apr  8 20:56:12 2012
+++ src/lib/libutil/getfsspecname.c	Tue Jan  1 18:32:17 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: getfsspecname.c,v 1.3 2012/04/08 20:56:12 christos Exp $	*/
+/*	$NetBSD: getfsspecname.c,v 1.4 2013/01/01 18:32:17 dsl Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,9 +29,10 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include sys/cdefs.h
-__RCSID($NetBSD: getfsspecname.c,v 1.3 2012/04/08 20:56:12 christos Exp $);
+__RCSID($NetBSD: getfsspecname.c,v 1.4 2013/01/01 18:32:17 dsl Exp $);
 
 #include sys/types.h
+#include sys/ioctl.h
 #include sys/sysctl.h
 #include sys/disk.h
 



CVS commit: src/lib/libutil

2012-12-30 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Dec 30 17:36:00 UTC 2012

Modified Files:
src/lib/libutil: efun.c

Log Message:
If malloc, calloc, or realloc returns NULL when a size of 0 was
requested, which is allowed by pertinent standards, honor it instead
of bombing.

Do not do this for calloc(x, y) where x != 0  y != 0 but x*y == 0;
in that case bomb.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libutil/efun.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/efun.c
diff -u src/lib/libutil/efun.c:1.6 src/lib/libutil/efun.c:1.7
--- src/lib/libutil/efun.c:1.6	Mon Apr 28 20:23:02 2008
+++ src/lib/libutil/efun.c	Sun Dec 30 17:36:00 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: efun.c,v 1.6 2008/04/28 20:23:02 martin Exp $	*/
+/*	$NetBSD: efun.c,v 1.7 2012/12/30 17:36:00 dholland Exp $	*/
 
 /*-
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include sys/cdefs.h
 #ifdef __RCSID
-__RCSID($NetBSD: efun.c,v 1.6 2008/04/28 20:23:02 martin Exp $);
+__RCSID($NetBSD: efun.c,v 1.7 2012/12/30 17:36:00 dholland Exp $);
 #endif
 
 #include err.h
@@ -104,7 +104,7 @@ void *
 emalloc(size_t n)
 {
 	void *p = malloc(n);
-	if (p == NULL)
+	if (p == NULL  n != 0)
 		(*efunc)(1, Cannot allocate %zu bytes, n);
 	return p;
 }
@@ -113,7 +113,7 @@ void *
 ecalloc(size_t n, size_t s)
 {
 	void *p = calloc(n, s);
-	if (p == NULL)
+	if (p == NULL  n != 0  s != 0)
 		(*efunc)(1, Cannot allocate %zu bytes, n);
 	return p;
 }
@@ -122,7 +122,7 @@ void *
 erealloc(void *p, size_t n)
 {
 	void *q = realloc(p, n);
-	if (q == NULL)
+	if (q == NULL  n != 0)
 		(*efunc)(1, Cannot re-allocate %zu bytes, n);
 	return q;
 }



CVS commit: src/lib/libutil

2012-12-30 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Dec 30 17:37:13 UTC 2012

Modified Files:
src/lib/libutil: efun.c

Log Message:
Fix failure message for ecalloc.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/libutil/efun.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/efun.c
diff -u src/lib/libutil/efun.c:1.7 src/lib/libutil/efun.c:1.8
--- src/lib/libutil/efun.c:1.7	Sun Dec 30 17:36:00 2012
+++ src/lib/libutil/efun.c	Sun Dec 30 17:37:13 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: efun.c,v 1.7 2012/12/30 17:36:00 dholland Exp $	*/
+/*	$NetBSD: efun.c,v 1.8 2012/12/30 17:37:13 dholland Exp $	*/
 
 /*-
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include sys/cdefs.h
 #ifdef __RCSID
-__RCSID($NetBSD: efun.c,v 1.7 2012/12/30 17:36:00 dholland Exp $);
+__RCSID($NetBSD: efun.c,v 1.8 2012/12/30 17:37:13 dholland Exp $);
 #endif
 
 #include err.h
@@ -114,7 +114,7 @@ ecalloc(size_t n, size_t s)
 {
 	void *p = calloc(n, s);
 	if (p == NULL  n != 0  s != 0)
-		(*efunc)(1, Cannot allocate %zu bytes, n);
+		(*efunc)(1, Cannot allocate %zu blocks of size %zu, n, s);
 	return p;
 }
 



CVS commit: src/lib/libutil/compat

2012-11-04 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Nov  4 13:08:57 UTC 2012

Modified Files:
src/lib/libutil/compat: compat_loginx.c util.h

Log Message:
don't include things you don't need


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libutil/compat/compat_loginx.c \
src/lib/libutil/compat/util.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/compat/compat_loginx.c
diff -u src/lib/libutil/compat/compat_loginx.c:1.2 src/lib/libutil/compat/compat_loginx.c:1.3
--- src/lib/libutil/compat/compat_loginx.c:1.2	Sat Jan 10 21:57:18 2009
+++ src/lib/libutil/compat/compat_loginx.c	Sun Nov  4 08:08:56 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat_loginx.c,v 1.2 2009/01/11 02:57:18 christos Exp $	*/
+/*	$NetBSD: compat_loginx.c,v 1.3 2012/11/04 13:08:56 christos Exp $	*/
 
 /*
  * Copyright (c) 1988, 1993
@@ -31,7 +31,7 @@
 
 #include sys/cdefs.h
 #if defined(LIBC_SCCS)  !defined(lint)
-__RCSID($NetBSD: compat_loginx.c,v 1.2 2009/01/11 02:57:18 christos Exp $);
+__RCSID($NetBSD: compat_loginx.c,v 1.3 2012/11/04 13:08:56 christos Exp $);
 #endif /* LIBC_SCCS and not lint */
 
 #include sys/types.h
@@ -44,12 +44,10 @@ __RCSID($NetBSD: compat_loginx.c,v 1.2 
 #include string.h
 #include stdlib.h
 #include unistd.h
-#include util.h
-#include compat/util.h
-#include utmp.h
-#include compat/include/utmp.h
 #include utmpx.h
 #include compat/include/utmpx.h
+#include util.h
+#include compat/util.h
 
 __warn_references(loginx,
 warning: reference to compatibility loginx(); include util.h to generate correct reference)
Index: src/lib/libutil/compat/util.h
diff -u src/lib/libutil/compat/util.h:1.2 src/lib/libutil/compat/util.h:1.3
--- src/lib/libutil/compat/util.h:1.2	Sat Jan 10 21:57:18 2009
+++ src/lib/libutil/compat/util.h	Sun Nov  4 08:08:57 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: util.h,v 1.2 2009/01/11 02:57:18 christos Exp $	*/
+/*	$NetBSD: util.h,v 1.3 2012/11/04 13:08:57 christos Exp $	*/
 
 /*-
  * Copyright (c) 1995
@@ -34,10 +34,15 @@
 
 #include sys/cdefs.h
 #include sys/types.h
-#include compat/include/pwd.h
-#include compat/include/utmp.h
-#include compat/include/utmpx.h
-#include machine/ansi.h
+#include sys/inttypes.h
+#include sys/ansi.h
+
+struct utmp50;
+struct utmpx50;
+struct passwd50;
+struct utmp;
+struct utmpx;
+struct passwd;
 
 void		login(const struct utmp50 *);
 void		loginx(const struct utmpx50 *);



CVS commit: src/lib/libutil

2012-09-19 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Wed Sep 19 23:22:57 UTC 2012

Modified Files:
src/lib/libutil: stat_flags.3

Log Message:
Fix string_to_flags prototype. From Brooks Davis in PR 46986.
Bump date.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/libutil/stat_flags.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/stat_flags.3
diff -u src/lib/libutil/stat_flags.3:1.7 src/lib/libutil/stat_flags.3:1.8
--- src/lib/libutil/stat_flags.3:1.7	Sat Aug  6 11:28:24 2011
+++ src/lib/libutil/stat_flags.3	Wed Sep 19 23:22:56 2012
@@ -1,4 +1,4 @@
-.\ $NetBSD: stat_flags.3,v 1.7 2011/08/06 11:28:24 jruoho Exp $
+.\ $NetBSD: stat_flags.3,v 1.8 2012/09/19 23:22:56 wiz Exp $
 .\
 .\ Copyright (c) 1996 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -27,7 +27,7 @@
 .\ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\ POSSIBILITY OF SUCH DAMAGE.
 .\
-.Dd August 6, 2011
+.Dd September 20, 2012
 .Dt STAT_FLAGS 3
 .Os
 .Sh NAME
@@ -41,7 +41,7 @@
 .Ft char *
 .Fn flags_to_string u_long flags const char *def
 .Ft int
-.Fn string_to_flags char **stringp u_long *setp u_long clrp
+.Fn string_to_flags char **stringp u_long *setp u_long *clrp
 .Sh DESCRIPTION
 The
 .Fn flags_to_string



CVS commit: src/lib/libutil

2012-07-27 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Fri Jul 27 18:22:04 UTC 2012

Modified Files:
src/lib/libutil: openpty.3

Log Message:
Remove trailing whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/lib/libutil/openpty.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/openpty.3
diff -u src/lib/libutil/openpty.3:1.15 src/lib/libutil/openpty.3:1.16
--- src/lib/libutil/openpty.3:1.15	Mon Jul 23 02:21:14 2012
+++ src/lib/libutil/openpty.3	Fri Jul 27 18:22:04 2012
@@ -1,4 +1,4 @@
-.\	$NetBSD: openpty.3,v 1.15 2012/07/23 02:21:14 christos Exp $
+.\	$NetBSD: openpty.3,v 1.16 2012/07/27 18:22:04 wiz Exp $
 .\
 .\ Copyright (c) 1995
 .\	The Regents of the University of California.  All rights reserved.
@@ -68,7 +68,7 @@ If
 .Fa name
 is non-null, the filename of the slave is returned in
 .Fa name .
-The length of 
+The length of
 .Fa name
 is limited to
 .Dv 16
@@ -76,7 +76,7 @@ characters in the current
 .Xr ptm 4
 device driver (including the terminating
 .Dv NUL )
-which limits the maximum to 
+which limits the maximum to
 .Dv 100,000
 ptys.
 If



CVS commit: src/lib/libutil

2012-07-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jul 27 21:33:46 UTC 2012

Modified Files:
src/lib/libutil: openpty.3

Log Message:
mention PATH_MAX instead of 16.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libutil/openpty.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/openpty.3
diff -u src/lib/libutil/openpty.3:1.16 src/lib/libutil/openpty.3:1.17
--- src/lib/libutil/openpty.3:1.16	Fri Jul 27 14:22:04 2012
+++ src/lib/libutil/openpty.3	Fri Jul 27 17:33:46 2012
@@ -1,4 +1,4 @@
-.\	$NetBSD: openpty.3,v 1.16 2012/07/27 18:22:04 wiz Exp $
+.\	$NetBSD: openpty.3,v 1.17 2012/07/27 21:33:46 christos Exp $
 .\
 .\ Copyright (c) 1995
 .\	The Regents of the University of California.  All rights reserved.
@@ -31,7 +31,7 @@
 .\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\ SUCH DAMAGE.
 .\
-.Dd July 22, 2012
+.Dd July 27, 2012
 .Dt OPENPTY 3
 .Os
 .Sh NAME
@@ -71,14 +71,16 @@ is non-null, the filename of the slave i
 The length of
 .Fa name
 is limited to
-.Dv 16
-characters in the current
-.Xr ptm 4
-device driver (including the terminating
-.Dv NUL )
-which limits the maximum to
-.Dv 100,000
-ptys.
+.Dv PATH_MAX
+as any other regular path name, so a buffer of this size should be used.
+.\ .Dv 16
+.\ characters in the current
+.\ .Xr ptm 4
+.\ device driver (including the terminating
+.\ .Dv NUL )
+.\ which limits the maximum to
+.\ .Dv 100,000
+.\ ptys.
 If
 .Fa termp
 is non-null, the terminal parameters of the slave will be set to the



CVS commit: src/lib/libutil

2012-07-22 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jul 23 02:21:14 UTC 2012

Modified Files:
src/lib/libutil: openpty.3

Log Message:
Mention how big the name can be.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/lib/libutil/openpty.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/openpty.3
diff -u src/lib/libutil/openpty.3:1.14 src/lib/libutil/openpty.3:1.15
--- src/lib/libutil/openpty.3:1.14	Fri Nov 28 02:17:17 2008
+++ src/lib/libutil/openpty.3	Sun Jul 22 22:21:14 2012
@@ -1,4 +1,4 @@
-.\	$NetBSD: openpty.3,v 1.14 2008/11/28 07:17:17 dholland Exp $
+.\	$NetBSD: openpty.3,v 1.15 2012/07/23 02:21:14 christos Exp $
 .\
 .\ Copyright (c) 1995
 .\	The Regents of the University of California.  All rights reserved.
@@ -31,7 +31,7 @@
 .\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\ SUCH DAMAGE.
 .\
-.Dd November 28, 2008
+.Dd July 22, 2012
 .Dt OPENPTY 3
 .Os
 .Sh NAME
@@ -68,6 +68,17 @@ If
 .Fa name
 is non-null, the filename of the slave is returned in
 .Fa name .
+The length of 
+.Fa name
+is limited to
+.Dv 16
+characters in the current
+.Xr ptm 4
+device driver (including the terminating
+.Dv NUL )
+which limits the maximum to 
+.Dv 100,000
+ptys.
 If
 .Fa termp
 is non-null, the terminal parameters of the slave will be set to the



  1   2   >