diff options
| author | David E. O'Brien <obrien@FreeBSD.org> | 1999-07-04 08:54:26 +0000 | 
|---|---|---|
| committer | David E. O'Brien <obrien@FreeBSD.org> | 1999-07-04 08:54:26 +0000 | 
| commit | b47f20df897d1ccd7216f7b6c56e557e4267eaab (patch) | |
| tree | 5a963c80cfc583115997af23a90955c0a27d5047 /lib/libc | |
| parent | edff69904f676656813a36e6b5ebfef64aab38e8 (diff) | |
Notes
Diffstat (limited to 'lib/libc')
| -rw-r--r-- | lib/libc/stdtime/strptime.3 | 13 | ||||
| -rw-r--r-- | lib/libc/stdtime/strptime.c | 33 | 
2 files changed, 44 insertions, 2 deletions
diff --git a/lib/libc/stdtime/strptime.3 b/lib/libc/stdtime/strptime.3 index 8e74a1327bd3..99568c95f2b7 100644 --- a/lib/libc/stdtime/strptime.3 +++ b/lib/libc/stdtime/strptime.3 @@ -23,7 +23,7 @@  .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF  .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  .\" -.\" $Id: strptime.3,v 1.3 1999/04/25 01:42:18 wes Exp $ +.\" $Id: strptime.3,v 1.4 1999/04/25 07:28:39 wes Exp $  .\" "  .Dd May 8, 1997  .Dt STRPTIME 3 @@ -44,6 +44,7 @@ according to the string pointed to by  .Fa format ,  and fills in the elements of the structure pointed to by  .Fa timeptr . +The resulting values will be relative to the local time zone.  Thus, it can be considered the reverse operation of  .Xr strftime 3 .  .Pp @@ -91,3 +92,13 @@ The  .Fn strptime  function appeared in  .Fx 3.0 . +.Pp +.Sh BUGS +The +.Fa %Z +format specifier only accepts time zone abbreviations of the local time zone, +or the value "GMT". +This limitation is because of ambiguity due to of the over loading of time +zone abbreviations.  One such example is +.Fa EST +which is both Eastern Standard Time and Eastern Australia Summer Time. diff --git a/lib/libc/stdtime/strptime.c b/lib/libc/stdtime/strptime.c index 27437fe31f2f..34da06e713bd 100644 --- a/lib/libc/stdtime/strptime.c +++ b/lib/libc/stdtime/strptime.c @@ -53,7 +53,7 @@  #ifdef LIBC_RCS  static const char rcsid[] = -	"$Id: strptime.c,v 1.5 1999/04/25 01:42:18 wes Exp $"; +	"$Id: strptime.c,v 1.6 1999/04/25 07:28:39 wes Exp $";  #endif  #ifndef lint @@ -71,6 +71,8 @@ static char sccsid[] = "@(#)strptime.c	0.1 (Powerdog) 94/03/27";  #define asizeof(a)	(sizeof (a) / sizeof ((a)[0])) +static int got_GMT = 0; +  char *  strptime(const char *buf, const char *fmt, struct tm *tm)  { @@ -344,8 +346,37 @@ strptime(const char *buf, const char *fmt, struct tm *tm)  				while (*ptr != 0 && !isspace((unsigned char)*ptr))  					ptr++;  			break; + +		case 'Z': +			{ +			const char *cp; +			char *zonestr; + +			for (cp = buf; *cp && isupper(*cp); ++cp) {/*empty*/} +			if (cp - buf) { +				zonestr = alloca(cp - buf + 1); +				strncpy(zonestr, buf, cp - buf); +				zonestr[cp - buf] = '\0'; +				tzset(); +				if (0 == strcmp(zonestr, "GMT")) { +					got_GMT = 1; +				} else if (0 == strcmp(zonestr, tzname[0])) { +					tm->tm_isdst = 0; +				} else if (0 == strcmp(zonestr, tzname[1])) { +					tm->tm_isdst = 1; +				} else { +					return 0; +				} +				buf += cp - buf; +			} +			} +			break;  		}  	} +	if (got_GMT) { +		time_t t = timegm(tm); +		localtime_r(&t, tm); +	}  	return (char *)buf;  }  | 
