CVS commit: [netbsd-7] src/lib/libutil
Module Name:src Committed By: snj Date: Sun Jan 29 05:17:33 UTC 2017 Modified Files: src/lib/libutil [netbsd-7]: opendisk.3 opendisk.c Log Message: Pull up following revision(s) (requested by pgoyette in ticket #1349): lib/libutil/opendisk.c: revision 1.14 lib/libutil/opendisk.3: revision 1.12, 1.13 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.11.42.1 src/lib/libutil/opendisk.3 cvs rdiff -u -r1.12 -r1.12.24.1 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.11.42.1 --- src/lib/libutil/opendisk.3:1.11 Wed Apr 30 13:10:52 2008 +++ src/lib/libutil/opendisk.3 Sun Jan 29 05:17:33 2017 @@ -1,4 +1,4 @@ -.\" $NetBSD: opendisk.3,v 1.11 2008/04/30 13:10:52 martin Exp $ +.\" $NetBSD: opendisk.3,v 1.11.42.1 2017/01/29 05:17:33 snj 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 7.1 +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.12 src/lib/libutil/opendisk.c:1.12.24.1 --- src/lib/libutil/opendisk.c:1.12 Tue Oct 13 22:00:31 2009 +++ src/lib/libutil/opendisk.c Sun Jan 29 05:17:33 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: opendisk.c,v 1.12 2009/10/13 22:00:31 pooka Exp $ */ +/* $NetBSD: opendisk.c,v 1.12.24.1 2017/01/29 05:17:33 snj Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -31,61 +31,76 @@ #include #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.12.24.1 2017/01/29 05:17:33 snj Exp $"); #endif #include #include #include +#include #include #include #include #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) +
CVS commit: [netbsd-7] src/lib/libutil
Module Name:src Committed By: snj Date: Sat Oct 11 16:56:21 UTC 2014 Modified Files: src/lib/libutil [netbsd-7]: parsedate.y Log Message: Pull up following revision(s) (requested by apb in ticket #135): lib/libutil/parsedate.y: revision 1.20 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.16.6.3 -r1.16.6.4 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.6.3 src/lib/libutil/parsedate.y:1.16.6.4 --- src/lib/libutil/parsedate.y:1.16.6.3 Sat Oct 11 16:51:23 2014 +++ src/lib/libutil/parsedate.y Sat Oct 11 16:56:21 2014 @@ -14,7 +14,7 @@ #include #ifdef __RCSID -__RCSID("$NetBSD: parsedate.y,v 1.16.6.3 2014/10/11 16:51:23 snj Exp $"); +__RCSID("$NetBSD: parsedate.y,v 1.16.6.4 2014/10/11 16:56:21 snj Exp $"); #endif #include @@ -42,6 +42,7 @@ __RCSID("$NetBSD: parsedate.y,v 1.16.6.3 #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_is
CVS commit: [netbsd-7] src/lib/libutil
Module Name:src Committed By: snj Date: Sat Oct 11 16:51:23 UTC 2014 Modified Files: src/lib/libutil [netbsd-7]: parsedate.y Log Message: Pull up following revision(s) (requested by apb in ticket #135): lib/libutil/parsedate.y: revision 1.19 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.16.6.2 -r1.16.6.3 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.6.2 src/lib/libutil/parsedate.y:1.16.6.3 --- src/lib/libutil/parsedate.y:1.16.6.2 Sat Oct 11 16:47:48 2014 +++ src/lib/libutil/parsedate.y Sat Oct 11 16:51:23 2014 @@ -14,7 +14,7 @@ #include #ifdef __RCSID -__RCSID("$NetBSD: parsedate.y,v 1.16.6.2 2014/10/11 16:47:48 snj Exp $"); +__RCSID("$NetBSD: parsedate.y,v 1.16.6.3 2014/10/11 16:51:23 snj Exp $"); #endif #include @@ -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: [netbsd-7] src/lib/libutil
Module Name:src Committed By: snj Date: Sat Oct 11 16:52:07 UTC 2014 Modified Files: src/lib/libutil [netbsd-7]: parsedate.3 Log Message: Pull up following revision(s) (requested by apb in ticket #135): lib/libutil/parsedate.3: revision 1.14 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.12.8.1 -r1.12.8.2 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.8.1 src/lib/libutil/parsedate.3:1.12.8.2 --- src/lib/libutil/parsedate.3:1.12.8.1 Sat Oct 11 16:45:58 2014 +++ src/lib/libutil/parsedate.3 Sat Oct 11 16:52:07 2014 @@ -1,4 +1,4 @@ -.\" $NetBSD: parsedate.3,v 1.12.8.1 2014/10/11 16:45:58 snj Exp $ +.\" $NetBSD: parsedate.3,v 1.12.8.2 2014/10/11 16:52:07 snj 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: [netbsd-7] src/lib/libutil
Module Name:src Committed By: snj Date: Sat Oct 11 16:47:48 UTC 2014 Modified Files: src/lib/libutil [netbsd-7]: parsedate.y Log Message: Pull up following revision(s) (requested by apb in ticket #135): lib/libutil/parsedate.y: revision 1.18 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.16.6.1 -r1.16.6.2 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.6.1 src/lib/libutil/parsedate.y:1.16.6.2 --- src/lib/libutil/parsedate.y:1.16.6.1 Sat Oct 11 16:44:31 2014 +++ src/lib/libutil/parsedate.y Sat Oct 11 16:47:48 2014 @@ -14,7 +14,7 @@ #include #ifdef __RCSID -__RCSID("$NetBSD: parsedate.y,v 1.16.6.1 2014/10/11 16:44:31 snj Exp $"); +__RCSID("$NetBSD: parsedate.y,v 1.16.6.2 2014/10/11 16:47:48 snj Exp $"); #endif #include @@ -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: [netbsd-7] src/lib/libutil
Module Name:src Committed By: snj Date: Sat Oct 11 16:45:58 UTC 2014 Modified Files: src/lib/libutil [netbsd-7]: parsedate.3 Log Message: Pull up following revision(s) (requested by apb in ticket #135): lib/libutil/parsedate.3: revision 1.13 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.12.8.1 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.12.8.1 --- src/lib/libutil/parsedate.3:1.12 Sat Jan 19 15:28:25 2013 +++ src/lib/libutil/parsedate.3 Sat Oct 11 16:45:58 2014 @@ -1,4 +1,4 @@ -.\" $NetBSD: parsedate.3,v 1.12 2013/01/19 15:28:25 apb Exp $ +.\" $NetBSD: parsedate.3,v 1.12.8.1 2014/10/11 16:45:58 snj 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: [netbsd-7] src/lib/libutil
Module Name:src Committed By: snj Date: Sat Oct 11 16:44:31 UTC 2014 Modified Files: src/lib/libutil [netbsd-7]: parsedate.y Log Message: Pull up following revision(s) (requested by apb in ticket #135): lib/libutil/parsedate.y: revision 1.17 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.16.6.1 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.16.6.1 --- src/lib/libutil/parsedate.y:1.16 Wed Jun 12 01:46:07 2013 +++ src/lib/libutil/parsedate.y Sat Oct 11 16:44:31 2014 @@ -14,7 +14,7 @@ #include #ifdef __RCSID -__RCSID("$NetBSD: parsedate.y,v 1.16 2013/06/12 01:46:07 yamt Exp $"); +__RCSID("$NetBSD: parsedate.y,v 1.16.6.1 2014/10/11 16:44:31 snj Exp $"); #endif #include @@ -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
CVS commit: [netbsd-7] src/lib/libutil
Module Name:src Committed By: martin Date: Mon Sep 22 11:19:20 UTC 2014 Modified Files: src/lib/libutil [netbsd-7]: getdiskrawname.c Log Message: Pull up following revision(s) (requested by mlelstv in ticket #117): lib/libutil/getdiskrawname.c: revision 1.3 lib/libutil/getdiskrawname.c: revision 1.4 lib/libutil/getdiskrawname.c: revision 1.5 - 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 '/'. use the passed parameter instead of PATH_MAX. Change signedness of nlen. KNF, sign cast. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.2.4.1 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.2.4.1 --- src/lib/libutil/getdiskrawname.c:1.2 Sun Dec 22 14:31:51 2013 +++ src/lib/libutil/getdiskrawname.c Mon Sep 22 11:19:20 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: getdiskrawname.c,v 1.2 2013/12/22 14:31:51 mlelstv Exp $ */ +/* $NetBSD: getdiskrawname.c,v 1.2.4.1 2014/09/22 11:19:20 martin Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: getdiskrawname.c,v 1.2 2013/12/22 14:31:51 mlelstv Exp $"); +__RCSID("$NetBSD: getdiskrawname.c,v 1.2.4.1 2014/09/22 11:19:20 martin Exp $"); #include @@ -37,25 +37,52 @@ __RCSID("$NetBSD: getdiskrawname.c,v 1.2 #include #include #include +#include #include +static const char * +resolve_link(char *buf, size_t bufsiz, const char *name) +{ + const char *dp; + size_t nlen; + ssize_t 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 > bufsiz) +return NULL; + if (nlen + dlen + 1 > bufsiz) +return NULL; + + memmove(buf + nlen, buf, (size_t)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 +92,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 +105,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 +127,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; }