1 /* Copyright (C) 1991,92,93,94,95,96,97,98 Free Software Foundation, Inc.
3 NOTE: The canonical source of this file is maintained with the GNU C Library.
4 Bugs can be reported to bug-glibc@prep.ai.mit.edu.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
25 /* Some systems need this in order to declare localtime_r properly. */
31 # define HAVE_LIMITS_H 1
33 # define HAVE_MBRLEN 1
34 # define HAVE_STRUCT_ERA_ENTRY 1
35 # define HAVE_TM_GMTOFF 1
36 # define HAVE_TM_ZONE 1
37 # define HAVE_TZNAME 1
39 # define MULTIBYTE_IS_FORMAT_SAFE 1
40 # define STDC_HEADERS 1
41 # include "../locale/localeinfo.h"
44 #if defined emacs && !defined HAVE_BCOPY
45 # define HAVE_MEMCPY 1
49 #include <sys/types.h> /* Some systems define `time_t' here. */
51 /* Provide a declaration of localtime_r on systems that lack it. */
52 #if ! defined HAVE_DECL_LOCALTIME_R
53 extern struct tm* localtime_r ();
56 #ifdef TIME_WITH_SYS_TIME
57 # include <sys/time.h>
60 # ifdef HAVE_SYS_TIME_H
61 # include <sys/time.h>
67 extern char *tzname[];
70 /* Do multibyte processing if multibytes are supported, unless
71 multibyte sequences are safe in formats. Multibyte sequences are
72 safe if they cannot contain byte sequences that look like format
73 conversion specifications. The GNU C Library uses UTF8 multibyte
74 encoding, which is safe for formats, but strftime.c can be used
75 with other C libraries that use unsafe encodings. */
76 #define DO_MULTIBYTE (HAVE_MBLEN && ! MULTIBYTE_IS_FORMAT_SAFE)
82 /* Simulate mbrlen with mblen as best we can. */
83 # define mbstate_t int
84 # define mbrlen(s, n, ps) mblen (s, n)
85 # define mbsinit(ps) (*(ps) == 0)
87 static const mbstate_t mbstate_zero;
100 # define memcpy(d, s, n) bcopy ((s), (d), (n))
105 # define MEMPCPY(d, s, n) __mempcpy (d, s, n)
107 # ifndef HAVE_MEMPCPY
108 # define MEMPCPY(d, s, n) ((void *) ((char *) memcpy (d, s, n) + (n)))
113 # if defined (__GNUC__) || (defined (__STDC__) && __STDC__)
114 # define __P(args) args
116 # define __P(args) ()
118 #endif /* Not __P. */
136 #define TYPE_SIGNED(t) ((t) -1 < 0)
138 /* Bound on length of the string representing an integer value of type t.
139 Subtract one for the sign bit if t is signed;
140 302 / 1000 is log10 (2) rounded up;
141 add one for integer division truncation;
142 add one more for a minus sign if t is signed. */
143 #define INT_STRLEN_BOUND(t) \
144 ((sizeof (t) * CHAR_BIT - TYPE_SIGNED (t)) * 302 / 100 + 1 + TYPE_SIGNED (t))
146 #define TM_YEAR_BASE 1900
149 /* Nonzero if YEAR is a leap year (every 4 years,
150 except every 100th isn't, and every 400th is). */
151 # define __isleap(year) \
152 ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
157 # define gmtime_r __gmtime_r
158 # define localtime_r __localtime_r
159 # define tzname __tzname
160 # define tzset __tzset
162 # if ! HAVE_LOCALTIME_R
163 # if ! HAVE_TM_GMTOFF
164 /* Approximate gmtime_r as best we can in its absence. */
166 # define gmtime_r my_gmtime_r
167 static struct tm *gmtime_r __P ((const time_t *, struct tm *));
173 struct tm *l = gmtime (t);
179 # endif /* ! HAVE_TM_GMTOFF */
181 /* Approximate localtime_r as best we can in its absence. */
183 # define localtime_r my_ftime_localtime_r
184 static struct tm *localtime_r __P ((const time_t *, struct tm *));
190 struct tm *l = localtime (t);
196 # endif /* ! HAVE_LOCALTIME_R */
197 #endif /* ! defined _LIBC */
200 #if !defined memset && !defined HAVE_MEMSET && !defined _LIBC
201 /* Some systems lack the `memset' function and we don't want to
202 introduce additional dependencies. */
203 /* The SGI compiler reportedly barfs on the trailing null
204 if we use a string constant as the initializer. 28 June 1997, rms. */
205 static const char spaces[16] = /* " " */
206 { ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' };
207 static const char zeroes[16] = /* "0000000000000000" */
208 { '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0' };
210 # define memset_space(P, Len) \
216 int _this = _len > 16 ? 16 : _len; \
217 (P) = MEMPCPY ((P), spaces, _this); \
223 # define memset_zero(P, Len) \
229 int _this = _len > 16 ? 16 : _len; \
230 (P) = MEMPCPY ((P), zeroes, _this); \
236 # define memset_space(P, Len) (memset ((P), ' ', (Len)), (P) += (Len))
237 # define memset_zero(P, Len) (memset ((P), '0', (Len)), (P) += (Len))
244 int _delta = width - _n; \
245 int _incr = _n + (_delta > 0 ? _delta : 0); \
246 if (i + _incr >= maxsize) \
253 memset_zero (p, _delta); \
255 memset_space (p, _delta); \
266 memcpy_lowcase (p, (s), _n); \
267 else if (to_uppcase) \
268 memcpy_uppcase (p, (s), _n); \
270 memcpy ((PTR) p, (PTR) (s), _n))
275 # define TOUPPER(Ch) toupper (Ch)
276 # define TOLOWER(Ch) tolower (Ch)
278 # define TOUPPER(Ch) (islower (Ch) ? toupper (Ch) : (Ch))
279 # define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch))
281 /* We don't use `isdigit' here since the locale dependent
282 interpretation is not what we want here. We only need to accept
283 the arabic digits in the ASCII range. One day there is perhaps a
284 more reliable way to accept other sets of digits. */
285 #define ISDIGIT(Ch) ((unsigned int) (Ch) - '0' <= 9)
287 static char *memcpy_lowcase __P ((char *dest, const char *src, size_t len));
290 memcpy_lowcase (dest, src, len)
296 dest[len] = TOLOWER ((unsigned char) src[len]);
300 static char *memcpy_uppcase __P ((char *dest, const char *src, size_t len));
303 memcpy_uppcase (dest, src, len)
309 dest[len] = TOUPPER ((unsigned char) src[len]);
315 /* Yield the difference between *A and *B,
316 measured in seconds, ignoring leap seconds. */
317 # define tm_diff ftime_tm_diff
318 static int tm_diff __P ((const struct tm *, const struct tm *));
324 /* Compute intervening leap days correctly even if year is negative.
325 Take care to avoid int overflow in leap day calculations,
326 but it's OK to assume that A and B are close to each other. */
327 int a4 = (a->tm_year >> 2) + (TM_YEAR_BASE >> 2) - ! (a->tm_year & 3);
328 int b4 = (b->tm_year >> 2) + (TM_YEAR_BASE >> 2) - ! (b->tm_year & 3);
329 int a100 = a4 / 25 - (a4 % 25 < 0);
330 int b100 = b4 / 25 - (b4 % 25 < 0);
331 int a400 = a100 >> 2;
332 int b400 = b100 >> 2;
333 int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
334 int years = a->tm_year - b->tm_year;
335 int days = (365 * years + intervening_leap_days
336 + (a->tm_yday - b->tm_yday));
337 return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour))
338 + (a->tm_min - b->tm_min))
339 + (a->tm_sec - b->tm_sec));
341 #endif /* ! HAVE_TM_GMTOFF */
345 /* The number of days from the first day of the first ISO week of this
346 year to the year day YDAY with week day WDAY. ISO weeks start on
347 Monday; the first ISO week has the year's first Thursday. YDAY may
348 be as small as YDAY_MINIMUM. */
349 #define ISO_WEEK_START_WDAY 1 /* Monday */
350 #define ISO_WEEK1_WDAY 4 /* Thursday */
351 #define YDAY_MINIMUM (-366)
352 static int iso_week_days __P ((int, int));
357 iso_week_days (yday, wday)
361 /* Add enough to the first operand of % to make it nonnegative. */
362 int big_enough_multiple_of_7 = (-YDAY_MINIMUM / 7 + 2) * 7;
364 - (yday - wday + ISO_WEEK1_WDAY + big_enough_multiple_of_7) % 7
365 + ISO_WEEK1_WDAY - ISO_WEEK_START_WDAY);
369 #if !(defined _NL_CURRENT || HAVE_STRFTIME)
370 static char const weekday_name[][10] =
372 "Sunday", "Monday", "Tuesday", "Wednesday",
373 "Thursday", "Friday", "Saturday"
375 static char const month_name[][10] =
377 "January", "February", "March", "April", "May", "June",
378 "July", "August", "September", "October", "November", "December"
384 # define my_strftime emacs_strftime
385 /* Emacs 20.2 uses `-Dstrftime=emacs_strftime' when compiling,
386 because that's how strftime used to be configured.
387 Undo this, since it gets in the way of accessing the underlying strftime,
388 which is needed for things like %Ec in Solaris.
389 The following two lines can be removed once Emacs stops compiling with
390 `-Dstrftime=emacs_strftime'. */
392 size_t strftime __P ((char *, size_t, const char *, const struct tm *));
394 # define my_strftime strftime
397 #if !defined _LIBC && HAVE_TZNAME && HAVE_TZSET
398 /* Solaris 2.5 tzset sometimes modifies the storage returned by localtime.
399 Work around this bug by copying *tp before it might be munged. */
400 size_t _strftime_copytm __P ((char *, size_t, const char *,
403 my_strftime (s, maxsize, format, tp)
411 return _strftime_copytm (s, maxsize, format, &tmcopy);
414 # define my_strftime(S, Maxsize, Format, Tp) \
415 _strftime_copytm (S, Maxsize, Format, Tp)
419 /* Write information from TP into S according to the format
420 string FORMAT, writing no more that MAXSIZE characters
421 (including the terminating '\0') and returning number of
422 characters written. If S is NULL, nothing will be written
423 anywhere, so to determine how many characters would be
424 written, use NULL for S and (size_t) UINT_MAX for MAXSIZE. */
426 my_strftime (s, maxsize, format, tp)
432 int hour12 = tp->tm_hour;
434 const char *const a_wkday = _NL_CURRENT (LC_TIME, ABDAY_1 + tp->tm_wday);
435 const char *const f_wkday = _NL_CURRENT (LC_TIME, DAY_1 + tp->tm_wday);
436 const char *const a_month = _NL_CURRENT (LC_TIME, ABMON_1 + tp->tm_mon);
437 const char *const f_month = _NL_CURRENT (LC_TIME, MON_1 + tp->tm_mon);
438 const char *const ampm = _NL_CURRENT (LC_TIME,
439 hour12 > 11 ? PM_STR : AM_STR);
440 size_t aw_len = strlen (a_wkday);
441 size_t am_len = strlen (a_month);
442 size_t ap_len = strlen (ampm);
445 const char *const f_wkday = weekday_name[tp->tm_wday];
446 const char *const f_month = month_name[tp->tm_mon];
447 const char *const a_wkday = f_wkday;
448 const char *const a_month = f_month;
449 const char *const ampm = "AMPM" + 2 * (hour12 > 11);
455 #if defined _NL_CURRENT || !HAVE_STRFTIME
456 size_t wkday_len = strlen (f_wkday);
457 size_t month_len = strlen (f_month);
467 /* The POSIX test suite assumes that setting
468 the environment variable TZ to a new value before calling strftime()
469 will influence the result (the %Z format) even if the information in
470 TP is computed with a totally different time zone.
471 This is bogus: though POSIX allows bad behavior like this,
472 POSIX does not require it. Do the right thing instead. */
473 zone = (const char *) tp->tm_zone;
476 /* POSIX.1 8.1.1 requires that whenever strftime() is called, the
477 time zone names contained in the external variable `tzname' shall
478 be set as if the tzset() function had been called. */
483 if (!(zone && *zone) && tp->tm_isdst >= 0)
484 zone = tzname[tp->tm_isdst];
487 zone = ""; /* POSIX.2 requires the empty string here. */
489 zonelen = strlen (zone);
494 if (hour12 == 0) hour12 = 12;
496 for (f = format; *f != '\0'; ++f)
498 int pad = 0; /* Padding for number ('-', '_', or 0). */
499 int modifier; /* Field modifier ('E', 'O', or 0). */
500 int digits; /* Max digits for numeric format. */
501 int number_value; /* Numeric value to be printed. */
502 int negative_number; /* 1 if the number is negative. */
505 char buf[1 + (sizeof (int) < sizeof (time_t)
506 ? INT_STRLEN_BOUND (time_t)
507 : INT_STRLEN_BOUND (int))];
521 case '\a': case '\b': case '\t': case '\n':
522 case '\v': case '\f': case '\r':
523 case ' ': case '!': case '"': case '#': case '&': case'\'':
524 case '(': case ')': case '*': case '+': case ',': case '-':
525 case '.': case '/': case '0': case '1': case '2': case '3':
526 case '4': case '5': case '6': case '7': case '8': case '9':
527 case ':': case ';': case '<': case '=': case '>': case '?':
528 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
529 case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
530 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
531 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
532 case 'Y': case 'Z': case '[': case'\\': case ']': case '^':
533 case '_': case 'a': case 'b': case 'c': case 'd': case 'e':
534 case 'f': case 'g': case 'h': case 'i': case 'j': case 'k':
535 case 'l': case 'm': case 'n': case 'o': case 'p': case 'q':
536 case 'r': case 's': case 't': case 'u': case 'v': case 'w':
537 case 'x': case 'y': case 'z': case '{': case '|': case '}':
539 /* The C Standard requires these 98 characters (plus '%') to
540 be in the basic execution character set. None of these
541 characters can start a multibyte sequence, so they need
542 not be analyzed further. */
547 /* Copy this multibyte sequence until we reach its end, find
548 an error, or come back to the initial shift state. */
550 mbstate_t mbstate = mbstate_zero;
555 size_t bytes = mbrlen (f + len, (size_t) -1, &mbstate);
560 if (bytes == (size_t) -2 || bytes == (size_t) -1)
568 while (! mbsinit (&mbstate));
575 #else /* ! DO_MULTIBYTE */
577 /* Either multibyte encodings are not supported, or they are
578 safe for formats, so any non-'%' byte can be copied through. */
585 #endif /* ! DO_MULTIBYTE */
587 /* Check for flags that can modify a format. */
592 /* This influences the number formats. */
599 /* This changes textual output. */
613 /* As a GNU extension we allow to specify the field width. */
623 while (ISDIGIT (*f));
626 /* Check for modifiers. */
639 /* Now do the specified format. */
643 #define DO_NUMBER(d, v) \
644 digits = width == -1 ? d : width; \
645 number_value = v; goto do_number
646 #define DO_NUMBER_SPACEPAD(d, v) \
647 digits = width == -1 ? d : width; \
648 number_value = v; goto do_number_spacepad
664 #if defined _NL_CURRENT || !HAVE_STRFTIME
665 cpy (aw_len, a_wkday);
668 goto underlying_strftime;
679 #if defined _NL_CURRENT || !HAVE_STRFTIME
680 cpy (wkday_len, f_wkday);
683 goto underlying_strftime;
687 case 'h': /* POSIX.2 extension. */
690 #if defined _NL_CURRENT || !HAVE_STRFTIME
691 cpy (am_len, a_month);
694 goto underlying_strftime;
705 #if defined _NL_CURRENT || !HAVE_STRFTIME
706 cpy (month_len, f_month);
709 goto underlying_strftime;
716 if (! (modifier == 'E'
717 && *(subfmt = _NL_CURRENT (LC_TIME, ERA_D_T_FMT)) != '\0'))
718 subfmt = _NL_CURRENT (LC_TIME, D_T_FMT);
721 goto underlying_strftime;
723 subfmt = "%a %b %e %H:%M:%S %Y";
730 size_t len = my_strftime (NULL, maxsize - i, subfmt, tp);
731 if (len == 0 && *subfmt)
733 add (len, my_strftime (p, maxsize - i, subfmt, tp));
736 while (old_start < p)
738 *old_start = TOUPPER ((unsigned char) *old_start);
744 #if HAVE_STRFTIME && ! (defined _NL_CURRENT && HAVE_STRUCT_ERA_ENTRY)
747 /* The relevant information is available only via the
748 underlying strftime implementation, so use that. */
751 char ubuf[1024]; /* enough for any single format in practice */
759 len = strftime (ubuf, sizeof ubuf, ufmt, tp);
760 if (len == 0 && ubuf[0] != '\0')
767 case 'C': /* POSIX.2 extension. */
772 #if HAVE_STRUCT_ERA_ENTRY
773 struct era_entry *era = _nl_get_era_entry (tp);
776 size_t len = strlen (era->name_fmt);
777 cpy (len, era->name_fmt);
782 goto underlying_strftime;
788 int year = tp->tm_year + TM_YEAR_BASE;
789 DO_NUMBER (1, year / 100 - (year % 100 < 0));
796 if (! (modifier == 'E'
797 && *(subfmt = _NL_CURRENT (LC_TIME, ERA_D_FMT)) != '\0'))
798 subfmt = _NL_CURRENT (LC_TIME, D_FMT);
802 goto underlying_strftime;
807 case 'D': /* POSIX.2 extension. */
817 DO_NUMBER (2, tp->tm_mday);
819 case 'e': /* POSIX.2 extension. */
823 DO_NUMBER_SPACEPAD (2, tp->tm_mday);
825 /* All numeric formats set DIGITS and NUMBER_VALUE and then
826 jump to one of these two labels. */
829 /* Force `_' flag unless overwritten by `0' flag. */
834 /* Format the number according to the MODIFIER flag. */
836 if (modifier == 'O' && 0 <= number_value)
839 /* Get the locale specific alternate representation of
840 the number NUMBER_VALUE. If none exist NULL is returned. */
841 const char *cp = _nl_get_alt_digit (number_value);
845 size_t digitlen = strlen (cp);
854 goto underlying_strftime;
859 unsigned int u = number_value;
861 bufp = buf + sizeof (buf);
862 negative_number = number_value < 0;
868 *--bufp = u % 10 + '0';
869 while ((u /= 10) != 0);
872 do_number_sign_and_padding:
878 int padding = digits - (buf + sizeof (buf) - bufp);
882 while (0 < padding--)
887 bufp += negative_number;
888 while (0 < padding--)
895 cpy (buf + sizeof (buf) - bufp, bufp);
908 DO_NUMBER (2, tp->tm_hour);
914 DO_NUMBER (2, hour12);
916 case 'k': /* GNU extension. */
920 DO_NUMBER_SPACEPAD (2, tp->tm_hour);
922 case 'l': /* GNU extension. */
926 DO_NUMBER_SPACEPAD (2, hour12);
932 DO_NUMBER (3, 1 + tp->tm_yday);
938 DO_NUMBER (2, tp->tm_min);
944 DO_NUMBER (2, tp->tm_mon + 1);
946 case 'n': /* POSIX.2 extension. */
952 #if !defined _NL_CURRENT && HAVE_STRFTIME
963 #if defined _NL_CURRENT || !HAVE_STRFTIME
967 goto underlying_strftime;
970 case 'R': /* GNU extension. */
974 case 'r': /* POSIX.2 extension. */
976 if (*(subfmt = _NL_CURRENT (LC_TIME, T_FMT_AMPM)) == '\0')
978 subfmt = "%I:%M:%S %p";
985 DO_NUMBER (2, tp->tm_sec);
987 case 's': /* GNU extension. */
995 /* Generate string value for T using time_t arithmetic;
996 this works even if sizeof (long) < sizeof (time_t). */
998 bufp = buf + sizeof (buf);
999 negative_number = t < 0;
1006 if (negative_number)
1010 /* Adjust if division truncates to minus infinity. */
1011 if (0 < -1 % 10 && d < 0)
1023 goto do_number_sign_and_padding;
1027 if (modifier == 'O')
1030 if (! (modifier == 'E'
1031 && *(subfmt = _NL_CURRENT (LC_TIME, ERA_T_FMT)) != '\0'))
1032 subfmt = _NL_CURRENT (LC_TIME, T_FMT);
1036 goto underlying_strftime;
1041 case 'T': /* POSIX.2 extension. */
1042 subfmt = "%H:%M:%S";
1045 case 't': /* POSIX.2 extension. */
1050 case 'u': /* POSIX.2 extension. */
1051 DO_NUMBER (1, (tp->tm_wday - 1 + 7) % 7 + 1);
1054 if (modifier == 'E')
1057 DO_NUMBER (2, (tp->tm_yday - tp->tm_wday + 7) / 7);
1060 case 'g': /* GNU extension. */
1061 case 'G': /* GNU extension. */
1062 if (modifier == 'E')
1065 int year = tp->tm_year + TM_YEAR_BASE;
1066 int days = iso_week_days (tp->tm_yday, tp->tm_wday);
1070 /* This ISO week belongs to the previous year. */
1072 days = iso_week_days (tp->tm_yday + (365 + __isleap (year)),
1077 int d = iso_week_days (tp->tm_yday - (365 + __isleap (year)),
1081 /* This ISO week belongs to the next year. */
1090 DO_NUMBER (2, (year % 100 + 100) % 100);
1093 DO_NUMBER (1, year);
1096 DO_NUMBER (2, days / 7 + 1);
1101 if (modifier == 'E')
1104 DO_NUMBER (2, (tp->tm_yday - (tp->tm_wday - 1 + 7) % 7 + 7) / 7);
1107 if (modifier == 'E')
1110 DO_NUMBER (1, tp->tm_wday);
1113 if (modifier == 'E')
1115 #if HAVE_STRUCT_ERA_ENTRY
1116 struct era_entry *era = _nl_get_era_entry (tp);
1119 subfmt = strchr (era->name_fmt, '\0') + 1;
1124 goto underlying_strftime;
1128 if (modifier == 'O')
1131 DO_NUMBER (1, tp->tm_year + TM_YEAR_BASE);
1134 if (modifier == 'E')
1136 #if HAVE_STRUCT_ERA_ENTRY
1137 struct era_entry *era = _nl_get_era_entry (tp);
1140 int delta = tp->tm_year - era->start_date[0];
1141 DO_NUMBER (1, (era->offset
1142 + (era->direction == '-' ? -delta : delta)));
1146 goto underlying_strftime;
1150 DO_NUMBER (2, (tp->tm_year % 100 + 100) % 100);
1158 cpy (zonelen, zone);
1161 case 'z': /* GNU extension. */
1162 if (tp->tm_isdst < 0)
1168 diff = tp->tm_gmtoff;
1177 if (lt == (time_t) -1)
1179 /* mktime returns -1 for errors, but -1 is also a
1180 valid time_t value. Check whether an error really
1183 localtime_r (<, &tm);
1185 if ((ltm.tm_sec ^ tm.tm_sec)
1186 | (ltm.tm_min ^ tm.tm_min)
1187 | (ltm.tm_hour ^ tm.tm_hour)
1188 | (ltm.tm_mday ^ tm.tm_mday)
1189 | (ltm.tm_mon ^ tm.tm_mon)
1190 | (ltm.tm_year ^ tm.tm_year))
1194 if (! gmtime_r (<, >m))
1197 diff = tm_diff (<m, >m);
1209 DO_NUMBER (4, (diff / 60) * 100 + diff % 60);
1212 case '\0': /* GNU extension: % at end of format. */
1216 /* Unknown format; output the format, including the '%',
1217 since this is most likely the right thing to do if a
1218 multibyte string has been misparsed. */
1222 for (flen = 1; f[1 - flen] != '%'; flen++)
1224 cpy (flen, &f[1 - flen]);