Home | History | Annotate | Line # | Download | only in time
strftime.c revision 1.8.2.2
      1  1.8.2.2        he /*	$NetBSD: strftime.c,v 1.8.2.2 2000/09/20 09:48:02 he Exp $	*/
      2      1.2    kleink 
      3      1.1       mrg /*
      4      1.1       mrg  * Copyright (c) 1989 The Regents of the University of California.
      5      1.1       mrg  * All rights reserved.
      6      1.1       mrg  *
      7      1.1       mrg  * Redistribution and use in source and binary forms, with or without
      8      1.1       mrg  * modification, are permitted provided that the following conditions
      9      1.1       mrg  * are met:
     10      1.1       mrg  * 1. Redistributions of source code must retain the above copyright
     11      1.1       mrg  *    notice, this list of conditions and the following disclaimer.
     12      1.1       mrg  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.1       mrg  *    notice, this list of conditions and the following disclaimer in the
     14      1.1       mrg  *    documentation and/or other materials provided with the distribution.
     15      1.1       mrg  * 3. All advertising materials mentioning features or use of this software
     16      1.1       mrg  *    must display the following acknowledgement:
     17      1.1       mrg  *	This product includes software developed by the University of
     18      1.1       mrg  *	California, Berkeley and its contributors.
     19      1.1       mrg  * 4. Neither the name of the University nor the names of its contributors
     20      1.1       mrg  *    may be used to endorse or promote products derived from this software
     21      1.1       mrg  *    without specific prior written permission.
     22      1.1       mrg  *
     23      1.1       mrg  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24      1.1       mrg  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25      1.1       mrg  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26      1.1       mrg  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27      1.1       mrg  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28      1.1       mrg  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29      1.1       mrg  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30      1.1       mrg  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31      1.1       mrg  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32      1.1       mrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33      1.1       mrg  * SUCH DAMAGE.
     34      1.1       mrg  */
     35      1.1       mrg 
     36      1.3  christos #include <sys/cdefs.h>
     37      1.1       mrg #if defined(LIBC_SCCS) && !defined(lint)
     38      1.3  christos #if 0
     39      1.3  christos static char *sccsid = "@(#)strftime.c	5.11 (Berkeley) 2/24/91";
     40      1.3  christos #else
     41  1.8.2.2        he __RCSID("$NetBSD: strftime.c,v 1.8.2.2 2000/09/20 09:48:02 he Exp $");
     42      1.3  christos #endif
     43      1.1       mrg #endif /* LIBC_SCCS and not lint */
     44      1.1       mrg 
     45      1.4       jtc #include "namespace.h"
     46  1.8.2.1        he #include "private.h"
     47      1.1       mrg #include <sys/localedef.h>
     48      1.1       mrg #include <locale.h>
     49      1.1       mrg #include <string.h>
     50      1.1       mrg #include <tzfile.h>
     51      1.1       mrg #include <time.h>
     52      1.1       mrg 
     53      1.5    kleink static	int _add __P((const char *, char **, const char *));
     54      1.6  christos static	int _conv __P((int, int, int, char **, const char *));
     55      1.5    kleink static	int _secs __P((const struct tm *, char **, const char *));
     56      1.5    kleink static	size_t _fmt __P((const char *, const struct tm *, char **,
     57      1.5    kleink 	    const char *));
     58      1.1       mrg 
     59      1.1       mrg size_t
     60      1.1       mrg strftime(s, maxsize, format, t)
     61      1.1       mrg 	char *s;
     62      1.1       mrg 	size_t maxsize;
     63      1.1       mrg 	const char *format;
     64      1.1       mrg 	const struct tm *t;
     65      1.1       mrg {
     66      1.5    kleink 	char *pt;
     67      1.5    kleink 
     68      1.1       mrg 	tzset();
     69      1.5    kleink 	if (maxsize < 1)
     70      1.5    kleink 		return (0);
     71      1.1       mrg 
     72      1.1       mrg 	pt = s;
     73      1.5    kleink 	if (_fmt(format, t, &pt, s + maxsize)) {
     74      1.5    kleink 		*pt = '\0';
     75      1.5    kleink 		return (pt - s);
     76      1.5    kleink 	} else
     77      1.2    kleink 		return (0);
     78      1.1       mrg }
     79      1.1       mrg 
     80      1.1       mrg #define SUN_WEEK(t)	(((t)->tm_yday + 7 - \
     81      1.1       mrg 				((t)->tm_wday)) / 7)
     82      1.1       mrg #define MON_WEEK(t)	(((t)->tm_yday + 7 - \
     83      1.1       mrg 				((t)->tm_wday ? (t)->tm_wday - 1 : 6)) / 7)
     84      1.5    kleink 
     85      1.1       mrg static size_t
     86      1.5    kleink _fmt(format, t, pt, ptlim)
     87      1.5    kleink 	const char *format;
     88      1.1       mrg 	const struct tm *t;
     89      1.5    kleink 	char **pt;
     90      1.5    kleink 	const char * const ptlim;
     91      1.1       mrg {
     92      1.1       mrg 	for (; *format; ++format) {
     93      1.1       mrg 		if (*format == '%') {
     94      1.1       mrg 			++format;
     95      1.1       mrg 			if (*format == 'E') {
     96      1.1       mrg 				/* Alternate Era */
     97      1.1       mrg 				++format;
     98      1.1       mrg 			} else if (*format == 'O') {
     99      1.1       mrg 				/* Alternate numeric symbols */
    100      1.1       mrg 				++format;
    101      1.1       mrg 			}
    102      1.2    kleink 			switch (*format) {
    103      1.1       mrg 			case '\0':
    104      1.1       mrg 				--format;
    105      1.1       mrg 				break;
    106      1.1       mrg 			case 'A':
    107      1.1       mrg 				if (t->tm_wday < 0 || t->tm_wday > 6)
    108      1.2    kleink 					return (0);
    109      1.5    kleink 				if (!_add(_CurrentTimeLocale->day[t->tm_wday],
    110      1.5    kleink 				    pt, ptlim))
    111      1.2    kleink 					return (0);
    112      1.1       mrg 				continue;
    113      1.5    kleink 
    114      1.1       mrg 			case 'a':
    115      1.1       mrg 				if (t->tm_wday < 0 || t->tm_wday > 6)
    116      1.2    kleink 					return (0);
    117      1.5    kleink 				if (!_add(_CurrentTimeLocale->abday[t->tm_wday],
    118      1.5    kleink 				    pt, ptlim))
    119      1.2    kleink 					return (0);
    120      1.1       mrg 				continue;
    121      1.1       mrg 			case 'B':
    122      1.1       mrg 				if (t->tm_mon < 0 || t->tm_mon > 11)
    123      1.2    kleink 					return (0);
    124      1.5    kleink 				if (!_add(_CurrentTimeLocale->mon[t->tm_mon],
    125      1.5    kleink 				    pt, ptlim))
    126      1.2    kleink 					return (0);
    127      1.1       mrg 				continue;
    128      1.1       mrg 			case 'b':
    129      1.1       mrg 			case 'h':
    130      1.1       mrg 				if (t->tm_mon < 0 || t->tm_mon > 11)
    131      1.2    kleink 					return (0);
    132      1.5    kleink 				if (!_add(_CurrentTimeLocale->abmon[t->tm_mon],
    133      1.5    kleink 				    pt, ptlim))
    134      1.2    kleink 					return (0);
    135      1.1       mrg 				continue;
    136      1.1       mrg 			case 'C':
    137      1.1       mrg 				if (!_conv((t->tm_year + TM_YEAR_BASE) / 100,
    138      1.5    kleink 				    2, '0', pt, ptlim))
    139      1.2    kleink 					return (0);
    140      1.1       mrg 				continue;
    141      1.1       mrg 			case 'c':
    142      1.5    kleink 				if (!_fmt(_CurrentTimeLocale->d_t_fmt, t, pt,
    143      1.5    kleink 				    ptlim))
    144      1.2    kleink 					return (0);
    145      1.1       mrg 				continue;
    146      1.1       mrg 			case 'D':
    147      1.5    kleink 				if (!_fmt("%m/%d/%y", t, pt, ptlim))
    148      1.2    kleink 					return (0);
    149      1.1       mrg 				continue;
    150      1.1       mrg 			case 'd':
    151      1.5    kleink 				if (!_conv(t->tm_mday, 2, '0', pt, ptlim))
    152      1.2    kleink 					return (0);
    153      1.1       mrg 				continue;
    154      1.1       mrg 			case 'e':
    155      1.5    kleink 				if (!_conv(t->tm_mday, 2, ' ', pt, ptlim))
    156      1.2    kleink 					return (0);
    157      1.1       mrg 				continue;
    158  1.8.2.2        he 			case 'F':
    159  1.8.2.2        he 				if (!_fmt("%Y-%m-%d", t, pt, ptlim))
    160  1.8.2.2        he 					return (0);
    161  1.8.2.2        he 				continue;
    162      1.1       mrg 			case 'H':
    163      1.5    kleink 				if (!_conv(t->tm_hour, 2, '0', pt, ptlim))
    164      1.2    kleink 					return (0);
    165      1.1       mrg 				continue;
    166      1.1       mrg 			case 'I':
    167      1.1       mrg 				if (!_conv(t->tm_hour % 12 ?
    168      1.5    kleink 				    t->tm_hour % 12 : 12, 2, '0', pt, ptlim))
    169      1.2    kleink 					return (0);
    170      1.1       mrg 				continue;
    171      1.1       mrg 			case 'j':
    172      1.5    kleink 				if (!_conv(t->tm_yday + 1, 3, '0', pt, ptlim))
    173      1.2    kleink 					return (0);
    174      1.1       mrg 				continue;
    175      1.1       mrg 			case 'k':
    176      1.5    kleink 				if (!_conv(t->tm_hour, 2, ' ', pt, ptlim))
    177      1.2    kleink 					return (0);
    178      1.1       mrg 				continue;
    179      1.1       mrg 			case 'l':
    180      1.1       mrg 				if (!_conv(t->tm_hour % 12 ?
    181      1.5    kleink 				    t->tm_hour % 12: 12, 2, ' ', pt, ptlim))
    182      1.2    kleink 					return (0);
    183      1.1       mrg 				continue;
    184      1.1       mrg 			case 'M':
    185      1.5    kleink 				if (!_conv(t->tm_min, 2, '0', pt, ptlim))
    186      1.2    kleink 					return (0);
    187      1.1       mrg 				continue;
    188      1.1       mrg 			case 'm':
    189      1.5    kleink 				if (!_conv(t->tm_mon + 1, 2, '0', pt, ptlim))
    190      1.2    kleink 					return (0);
    191      1.1       mrg 				continue;
    192      1.1       mrg 			case 'n':
    193      1.5    kleink 				if (!_add("\n", pt, ptlim))
    194      1.2    kleink 					return (0);
    195      1.1       mrg 				continue;
    196      1.1       mrg 			case 'p':
    197      1.5    kleink 				if (!_add(_CurrentTimeLocale->am_pm[t->tm_hour
    198      1.5    kleink 				    >= 12], pt, ptlim))
    199      1.2    kleink 					return (0);
    200      1.1       mrg 				continue;
    201      1.1       mrg 			case 'R':
    202      1.5    kleink 				if (!_fmt("%H:%M", t, pt, ptlim))
    203      1.2    kleink 					return (0);
    204      1.1       mrg 				continue;
    205      1.1       mrg 			case 'r':
    206      1.5    kleink 				if (!_fmt(_CurrentTimeLocale->t_fmt_ampm, t, pt,
    207      1.5    kleink 				    ptlim))
    208      1.2    kleink 					return (0);
    209      1.1       mrg 				continue;
    210      1.1       mrg 			case 'S':
    211      1.5    kleink 				if (!_conv(t->tm_sec, 2, '0', pt, ptlim))
    212      1.2    kleink 					return (0);
    213      1.1       mrg 				continue;
    214      1.1       mrg 			case 's':
    215      1.5    kleink 				if (!_secs(t, pt, ptlim))
    216      1.2    kleink 					return (0);
    217      1.1       mrg 				continue;
    218      1.1       mrg 			case 'T':
    219      1.5    kleink 				if (!_fmt("%H:%M:%S", t, pt, ptlim))
    220      1.2    kleink 					return (0);
    221      1.1       mrg 				continue;
    222      1.1       mrg 			case 't':
    223      1.5    kleink 				if (!_add("\t", pt, ptlim))
    224      1.2    kleink 					return (0);
    225      1.1       mrg 				continue;
    226      1.1       mrg 			case 'U':
    227      1.5    kleink 				if (!_conv(SUN_WEEK(t), 2, '0', pt, ptlim))
    228      1.2    kleink 					return (0);
    229      1.1       mrg 				continue;
    230      1.1       mrg 			case 'u':
    231      1.5    kleink 				if (!_conv(t->tm_wday ? t->tm_wday : 7, 1, '0',
    232      1.5    kleink 				    pt, ptlim))
    233      1.2    kleink 					return (0);
    234      1.1       mrg 				continue;
    235      1.8  augustss 			case 'V':	/* ISO 8601 week number */
    236      1.8  augustss 			case 'G':	/* ISO 8601 year (four digits) */
    237      1.8  augustss 			case 'g':	/* ISO 8601 year (two digits) */
    238      1.8  augustss /*
    239      1.8  augustss ** From Arnold Robbins' strftime version 3.0:  "the week number of the
    240      1.8  augustss ** year (the first Monday as the first day of week 1) as a decimal number
    241      1.8  augustss ** (01-53)."
    242      1.8  augustss ** (ado, 1993-05-24)
    243      1.8  augustss **
    244      1.8  augustss ** From "http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html" by Markus Kuhn:
    245      1.8  augustss ** "Week 01 of a year is per definition the first week which has the
    246      1.8  augustss ** Thursday in this year, which is equivalent to the week which contains
    247      1.8  augustss ** the fourth day of January. In other words, the first week of a new year
    248      1.8  augustss ** is the week which has the majority of its days in the new year. Week 01
    249      1.8  augustss ** might also contain days from the previous year and the week before week
    250      1.8  augustss ** 01 of a year is the last week (52 or 53) of the previous year even if
    251      1.8  augustss ** it contains days from the new year. A week starts with Monday (day 1)
    252      1.8  augustss ** and ends with Sunday (day 7).  For example, the first week of the year
    253      1.8  augustss ** 1997 lasts from 1996-12-30 to 1997-01-05..."
    254      1.8  augustss ** (ado, 1996-01-02)
    255      1.8  augustss */
    256      1.1       mrg 				{
    257      1.8  augustss 					int	year;
    258      1.8  augustss 					int	yday;
    259      1.8  augustss 					int	wday;
    260      1.8  augustss 					int	w;
    261      1.8  augustss 
    262      1.8  augustss 					year = t->tm_year + TM_YEAR_BASE;
    263      1.8  augustss 					yday = t->tm_yday;
    264      1.8  augustss 					wday = t->tm_wday;
    265      1.8  augustss 					for ( ; ; ) {
    266      1.8  augustss 						int	len;
    267      1.8  augustss 						int	bot;
    268      1.8  augustss 						int	top;
    269      1.8  augustss 
    270      1.8  augustss 						len = isleap(year) ?
    271      1.8  augustss 							DAYSPERLYEAR :
    272      1.8  augustss 							DAYSPERNYEAR;
    273      1.8  augustss 						/*
    274      1.8  augustss 						** What yday (-3 ... 3) does
    275      1.8  augustss 						** the ISO year begin on?
    276      1.8  augustss 						*/
    277      1.8  augustss 						bot = ((yday + 11 - wday) %
    278      1.8  augustss 							DAYSPERWEEK) - 3;
    279      1.8  augustss 						/*
    280      1.8  augustss 						** What yday does the NEXT
    281      1.8  augustss 						** ISO year begin on?
    282      1.8  augustss 						*/
    283      1.8  augustss 						top = bot -
    284      1.8  augustss 							(len % DAYSPERWEEK);
    285      1.8  augustss 						if (top < -3)
    286      1.8  augustss 							top += DAYSPERWEEK;
    287      1.8  augustss 						top += len;
    288      1.8  augustss 						if (yday >= top) {
    289      1.8  augustss 							++year;
    290      1.8  augustss 							w = 1;
    291      1.8  augustss 							break;
    292      1.8  augustss 						}
    293      1.8  augustss 						if (yday >= bot) {
    294      1.8  augustss 							w = 1 + ((yday - bot) /
    295      1.8  augustss 								DAYSPERWEEK);
    296      1.8  augustss 							break;
    297      1.8  augustss 						}
    298      1.8  augustss 						--year;
    299      1.8  augustss 						yday += isleap(year) ?
    300      1.8  augustss 							DAYSPERLYEAR :
    301      1.8  augustss 							DAYSPERNYEAR;
    302      1.8  augustss 					}
    303      1.8  augustss #ifdef XPG4_1994_04_09
    304      1.8  augustss 					if ((w == 52
    305      1.8  augustss 					     && t->tm_mon == TM_JANUARY)
    306      1.8  augustss 					    || (w == 1
    307      1.8  augustss 						&& t->tm_mon == TM_DECEMBER))
    308      1.8  augustss 						w = 53;
    309      1.8  augustss #endif /* defined XPG4_1994_04_09 */
    310      1.8  augustss 					if (*format == 'V') {
    311      1.8  augustss 						if (!_conv(w, 2, '0',
    312      1.8  augustss 							pt, ptlim))
    313      1.8  augustss 							return (0);
    314      1.8  augustss 					} else if (*format == 'g') {
    315      1.8  augustss 						if (!_conv(year % 100, 2, '0',
    316      1.8  augustss 							pt, ptlim))
    317      1.8  augustss 							return (0);
    318      1.8  augustss 					} else	if (!_conv(year, 4, '0',
    319      1.8  augustss 							pt, ptlim))
    320      1.8  augustss 							return (0);
    321      1.1       mrg 				}
    322      1.1       mrg 				continue;
    323      1.1       mrg 			case 'W':
    324      1.5    kleink 				if (!_conv(MON_WEEK(t), 2, '0', pt, ptlim))
    325      1.2    kleink 					return (0);
    326      1.1       mrg 				continue;
    327      1.1       mrg 			case 'w':
    328      1.5    kleink 				if (!_conv(t->tm_wday, 1, '0', pt, ptlim))
    329      1.2    kleink 					return (0);
    330      1.1       mrg 				continue;
    331      1.1       mrg 			case 'x':
    332      1.5    kleink 				if (!_fmt(_CurrentTimeLocale->d_fmt, t, pt,
    333      1.5    kleink 				    ptlim))
    334      1.2    kleink 					return (0);
    335      1.1       mrg 				continue;
    336      1.1       mrg 			case 'X':
    337      1.5    kleink 				if (!_fmt(_CurrentTimeLocale->t_fmt, t, pt,
    338      1.5    kleink 				    ptlim))
    339      1.2    kleink 					return (0);
    340      1.1       mrg 				continue;
    341      1.1       mrg 			case 'y':
    342      1.1       mrg 				if (!_conv((t->tm_year + TM_YEAR_BASE) % 100,
    343      1.5    kleink 				    2, '0', pt, ptlim))
    344      1.2    kleink 					return (0);
    345      1.1       mrg 				continue;
    346      1.1       mrg 			case 'Y':
    347      1.5    kleink 				if (!_conv((t->tm_year + TM_YEAR_BASE), 4, '0',
    348      1.5    kleink 				    pt, ptlim))
    349      1.2    kleink 					return (0);
    350      1.1       mrg 				continue;
    351      1.1       mrg 			case 'Z':
    352  1.8.2.1        he #ifdef TM_ZONE
    353  1.8.2.1        he 				if (t->TM_ZONE != NULL) {
    354  1.8.2.1        he 					if (!_add(t->TM_ZONE, pt, ptlim))
    355  1.8.2.1        he 						return (0);
    356  1.8.2.1        he 				} else
    357  1.8.2.1        he #endif /* TM_ZONE */
    358      1.2    kleink 				if (tzname[t->tm_isdst ? 1 : 0] &&
    359      1.5    kleink 				    !_add(tzname[t->tm_isdst ? 1 : 0], pt,
    360      1.5    kleink 				    ptlim))
    361      1.2    kleink 					return (0);
    362      1.1       mrg 				continue;
    363      1.1       mrg 			case '%':
    364      1.1       mrg 			/*
    365      1.1       mrg 			 * X311J/88-090 (4.12.3.5): if conversion char is
    366      1.1       mrg 			 * undefined, behavior is undefined.  Print out the
    367      1.1       mrg 			 * character itself as printf(3) does.
    368      1.1       mrg 			 */
    369      1.1       mrg 			default:
    370      1.1       mrg 				break;
    371      1.1       mrg 			}
    372      1.1       mrg 		}
    373      1.5    kleink 		if (*pt == ptlim)
    374      1.2    kleink 			return (0);
    375      1.5    kleink 		*(*pt)++ = *format;
    376      1.1       mrg 	}
    377      1.5    kleink 	return (ptlim - *pt);
    378      1.1       mrg }
    379      1.1       mrg 
    380      1.1       mrg static int
    381      1.5    kleink _secs(t, pt, ptlim)
    382      1.1       mrg 	const struct tm *t;
    383      1.5    kleink 	char **pt;
    384      1.5    kleink 	const char * const ptlim;
    385      1.1       mrg {
    386      1.5    kleink 	char buf[15];
    387      1.5    kleink 	time_t s;
    388      1.5    kleink 	char *p;
    389      1.1       mrg 	struct tm tmp;
    390      1.1       mrg 
    391      1.7  sommerfe 	buf[sizeof (buf) - 1] = '\0';
    392      1.1       mrg 	/* Make a copy, mktime(3) modifies the tm struct. */
    393      1.1       mrg 	tmp = *t;
    394      1.1       mrg 	s = mktime(&tmp);
    395      1.1       mrg 	for (p = buf + sizeof(buf) - 2; s > 0 && p > buf; s /= 10)
    396      1.6  christos 		*p-- = (char)(s % 10 + '0');
    397      1.5    kleink 	return (_add(++p, pt, ptlim));
    398      1.1       mrg }
    399      1.1       mrg 
    400      1.1       mrg static int
    401      1.5    kleink _conv(n, digits, pad, pt, ptlim)
    402      1.1       mrg 	int n, digits;
    403      1.6  christos 	int pad;
    404      1.5    kleink 	char **pt;
    405      1.5    kleink 	const char * const ptlim;
    406      1.1       mrg {
    407      1.5    kleink 	char buf[10];
    408      1.5    kleink 	char *p;
    409      1.1       mrg 
    410      1.5    kleink 	buf[sizeof (buf) - 1] = '\0';
    411  1.8.2.2        he 	p = buf + sizeof(buf) - 2;
    412  1.8.2.2        he 	do {
    413      1.1       mrg 		*p-- = n % 10 + '0';
    414  1.8.2.2        he 		n /= 10;
    415  1.8.2.2        he 		--digits;
    416  1.8.2.2        he 	} while (n > 0 && p > buf);
    417      1.1       mrg 	while (p > buf && digits-- > 0)
    418      1.1       mrg 		*p-- = pad;
    419      1.5    kleink 	return (_add(++p, pt, ptlim));
    420      1.1       mrg }
    421      1.1       mrg 
    422      1.1       mrg static int
    423      1.5    kleink _add(str, pt, ptlim)
    424      1.5    kleink 	const char *str;
    425      1.5    kleink 	char **pt;
    426      1.5    kleink 	const char * const ptlim;
    427      1.1       mrg {
    428      1.5    kleink 
    429      1.5    kleink 	for (;; ++(*pt)) {
    430      1.5    kleink 		if (*pt == ptlim)
    431      1.2    kleink 			return (0);
    432      1.5    kleink 		if ((**pt = *str++) == '\0')
    433      1.2    kleink 			return (1);
    434      1.1       mrg 	}
    435      1.1       mrg }
    436