retire BIOS_SEG and umap_bios
[minix3.git] / lib / libc / time / strftime.c
blob62020d6c2bb8ba788be1b1024fd79a71325e5280
1 /* $NetBSD: strftime.c,v 1.21 2010/12/16 18:38:07 christos Exp $ */
3 #include <sys/cdefs.h>
4 #if defined(LIBC_SCCS) && !defined(lint)
5 #if 0
6 static char elsieid[] = "@(#)strftime.c 7.64";
7 static char elsieid[] = "@(#)strftime.c 8.3";
8 #else
9 __RCSID("$NetBSD: strftime.c,v 1.21 2010/12/16 18:38:07 christos Exp $");
10 #endif
11 #endif /* LIBC_SCCS and not lint */
13 #include "namespace.h"
16 ** Based on the UCB version with the ID appearing below.
17 ** This is ANSIish only when "multibyte character == plain character".
20 #include "private.h"
23 ** We don't use these extensions in strftime operation even when
24 ** supported by the local tzcode configuration. A strictly
25 ** conforming C application may leave them in undefined state.
28 #ifdef _LIBC
29 #undef TM_ZONE
30 #undef TM_GMTOFF
31 #endif
34 ** Copyright (c) 1989, 1993
35 ** The Regents of the University of California. All rights reserved.
37 ** Redistribution and use in source and binary forms, with or without
38 ** modification, are permitted provided that the following conditions
39 ** are met:
40 ** 1. Redistributions of source code must retain the above copyright
41 ** notice, this list of conditions and the following disclaimer.
42 ** 2. Redistributions in binary form must reproduce the above copyright
43 ** notice, this list of conditions and the following disclaimer in the
44 ** documentation and/or other materials provided with the distribution.
45 ** 3. All advertising materials mentioning features or use of this software
46 ** must display the following acknowledgement:
47 ** This product includes software developed by the University of
48 ** California, Berkeley and its contributors.
49 ** 4. Neither the name of the University nor the names of its contributors
50 ** may be used to endorse or promote products derived from this software
51 ** without specific prior written permission.
53 ** THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56 ** ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57 ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 ** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 ** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 ** SUCH DAMAGE.
66 #ifndef LIBC_SCCS
67 #ifndef lint
68 static const char sccsid[] = "@(#)strftime.c 5.4 (Berkeley) 3/14/89";
69 #endif /* !defined lint */
70 #endif /* !defined LIBC_SCCS */
72 #include "tzfile.h"
73 #include "fcntl.h"
74 #include "locale.h"
76 #ifdef __weak_alias
77 __weak_alias(strftime_z, _strftime_z)
78 #endif
80 #include "sys/localedef.h"
81 #define Locale _CurrentTimeLocale
82 #define c_fmt d_t_fmt
84 static char * _add(const char *, char *, const char *);
85 static char * _conv(int, const char *, char *, const char *);
86 static char * _fmt(const timezone_t, const char *, const struct tm *, char *,
87 const char *, int *);
88 static char * _yconv(int, int, int, int, char *, const char *);
90 extern char * tzname[];
92 #ifndef YEAR_2000_NAME
93 #define YEAR_2000_NAME "CHECK_STRFTIME_FORMATS_FOR_TWO_DIGIT_YEARS"
94 #endif /* !defined YEAR_2000_NAME */
96 #define IN_NONE 0
97 #define IN_SOME 1
98 #define IN_THIS 2
99 #define IN_ALL 3
101 size_t
102 strftime_z(const timezone_t sp, char * const s, const size_t maxsize,
103 const char * const format, const struct tm * const t)
105 char * p;
106 int warn;
108 warn = IN_NONE;
109 p = _fmt(sp, ((format == NULL) ? "%c" : format), t, s, s + maxsize,
110 &warn);
111 #ifndef NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU
112 if (warn != IN_NONE && getenv(YEAR_2000_NAME) != NULL) {
113 (void) fprintf(stderr, "\n");
114 if (format == NULL)
115 (void) fprintf(stderr, "NULL strftime format ");
116 else (void) fprintf(stderr, "strftime format \"%s\" ",
117 format);
118 (void) fprintf(stderr, "yields only two digits of years in ");
119 if (warn == IN_SOME)
120 (void) fprintf(stderr, "some locales");
121 else if (warn == IN_THIS)
122 (void) fprintf(stderr, "the current locale");
123 else (void) fprintf(stderr, "all locales");
124 (void) fprintf(stderr, "\n");
126 #endif /* !defined NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU */
127 if (p == s + maxsize)
128 return 0;
129 *p = '\0';
130 return p - s;
133 static char *
134 _fmt(const timezone_t sp, const char *format, const struct tm * const t,
135 char *pt, const char *const ptlim, int *warnp)
137 for ( ; *format; ++format) {
138 if (*format == '%') {
139 label:
140 switch (*++format) {
141 case '\0':
142 --format;
143 break;
144 case 'A':
145 pt = _add((t->tm_wday < 0 ||
146 t->tm_wday >= DAYSPERWEEK) ?
147 "?" : Locale->day[t->tm_wday],
148 pt, ptlim);
149 continue;
150 case 'a':
151 pt = _add((t->tm_wday < 0 ||
152 t->tm_wday >= DAYSPERWEEK) ?
153 "?" : Locale->abday[t->tm_wday],
154 pt, ptlim);
155 continue;
156 case 'B':
157 pt = _add((t->tm_mon < 0 ||
158 t->tm_mon >= MONSPERYEAR) ?
159 "?" : Locale->mon[t->tm_mon],
160 pt, ptlim);
161 continue;
162 case 'b':
163 case 'h':
164 pt = _add((t->tm_mon < 0 ||
165 t->tm_mon >= MONSPERYEAR) ?
166 "?" : Locale->abmon[t->tm_mon],
167 pt, ptlim);
168 continue;
169 case 'C':
171 ** %C used to do a...
172 ** _fmt("%a %b %e %X %Y", t);
173 ** ...whereas now POSIX 1003.2 calls for
174 ** something completely different.
175 ** (ado, 1993-05-24)
177 pt = _yconv(t->tm_year, TM_YEAR_BASE, 1, 0,
178 pt, ptlim);
179 continue;
180 case 'c':
182 int warn2 = IN_SOME;
184 pt = _fmt(sp, Locale->c_fmt, t, pt, ptlim, &warn2);
185 if (warn2 == IN_ALL)
186 warn2 = IN_THIS;
187 if (warn2 > *warnp)
188 *warnp = warn2;
190 continue;
191 case 'D':
192 pt = _fmt(sp, "%m/%d/%y", t, pt, ptlim, warnp);
193 continue;
194 case 'd':
195 pt = _conv(t->tm_mday, "%02d", pt, ptlim);
196 continue;
197 case 'E':
198 case 'O':
200 ** C99 locale modifiers.
201 ** The sequences
202 ** %Ec %EC %Ex %EX %Ey %EY
203 ** %Od %oe %OH %OI %Om %OM
204 ** %OS %Ou %OU %OV %Ow %OW %Oy
205 ** are supposed to provide alternate
206 ** representations.
208 goto label;
209 case 'e':
210 pt = _conv(t->tm_mday, "%2d", pt, ptlim);
211 continue;
212 case 'F':
213 pt = _fmt(sp, "%Y-%m-%d", t, pt, ptlim, warnp);
214 continue;
215 case 'H':
216 pt = _conv(t->tm_hour, "%02d", pt, ptlim);
217 continue;
218 case 'I':
219 pt = _conv((t->tm_hour % 12) ?
220 (t->tm_hour % 12) : 12,
221 "%02d", pt, ptlim);
222 continue;
223 case 'j':
224 pt = _conv(t->tm_yday + 1, "%03d", pt, ptlim);
225 continue;
226 case 'k':
228 ** This used to be...
229 ** _conv(t->tm_hour % 12 ?
230 ** t->tm_hour % 12 : 12, 2, ' ');
231 ** ...and has been changed to the below to
232 ** match SunOS 4.1.1 and Arnold Robbins'
233 ** strftime version 3.0. That is, "%k" and
234 ** "%l" have been swapped.
235 ** (ado, 1993-05-24)
237 pt = _conv(t->tm_hour, "%2d", pt, ptlim);
238 continue;
239 #ifdef KITCHEN_SINK
240 case 'K':
242 ** After all this time, still unclaimed!
244 pt = _add("kitchen sink", pt, ptlim);
245 continue;
246 #endif /* defined KITCHEN_SINK */
247 case 'l':
249 ** This used to be...
250 ** _conv(t->tm_hour, 2, ' ');
251 ** ...and has been changed to the below to
252 ** match SunOS 4.1.1 and Arnold Robbin's
253 ** strftime version 3.0. That is, "%k" and
254 ** "%l" have been swapped.
255 ** (ado, 1993-05-24)
257 pt = _conv((t->tm_hour % 12) ?
258 (t->tm_hour % 12) : 12,
259 "%2d", pt, ptlim);
260 continue;
261 case 'M':
262 pt = _conv(t->tm_min, "%02d", pt, ptlim);
263 continue;
264 case 'm':
265 pt = _conv(t->tm_mon + 1, "%02d", pt, ptlim);
266 continue;
267 case 'n':
268 pt = _add("\n", pt, ptlim);
269 continue;
270 case 'p':
271 pt = _add((t->tm_hour >= (HOURSPERDAY / 2)) ?
272 Locale->am_pm[1] :
273 Locale->am_pm[0],
274 pt, ptlim);
275 continue;
276 case 'R':
277 pt = _fmt(sp, "%H:%M", t, pt, ptlim, warnp);
278 continue;
279 case 'r':
280 pt = _fmt(sp, Locale->t_fmt_ampm, t, pt, ptlim,
281 warnp);
282 continue;
283 case 'S':
284 pt = _conv(t->tm_sec, "%02d", pt, ptlim);
285 continue;
286 case 's':
288 struct tm tm;
289 char buf[INT_STRLEN_MAXIMUM(
290 time_t) + 1];
291 time_t mkt;
293 tm = *t;
294 mkt = mktime(&tm);
295 /* CONSTCOND */
296 if (TYPE_SIGNED(time_t))
297 (void) snprintf(buf, sizeof(buf),
298 "%lld", (long long) mkt);
299 else (void) snprintf(buf, sizeof(buf),
300 "%llu", (unsigned long long)
301 mkt);
302 pt = _add(buf, pt, ptlim);
304 continue;
305 case 'T':
306 pt = _fmt(sp, "%H:%M:%S", t, pt, ptlim, warnp);
307 continue;
308 case 't':
309 pt = _add("\t", pt, ptlim);
310 continue;
311 case 'U':
312 pt = _conv((t->tm_yday + DAYSPERWEEK -
313 t->tm_wday) / DAYSPERWEEK,
314 "%02d", pt, ptlim);
315 continue;
316 case 'u':
318 ** From Arnold Robbins' strftime version 3.0:
319 ** "ISO 8601: Weekday as a decimal number
320 ** [1 (Monday) - 7]"
321 ** (ado, 1993-05-24)
323 pt = _conv((t->tm_wday == 0) ?
324 DAYSPERWEEK : t->tm_wday,
325 "%d", pt, ptlim);
326 continue;
327 case 'V': /* ISO 8601 week number */
328 case 'G': /* ISO 8601 year (four digits) */
329 case 'g': /* ISO 8601 year (two digits) */
331 ** From Arnold Robbins' strftime version 3.0: "the week number of the
332 ** year (the first Monday as the first day of week 1) as a decimal number
333 ** (01-53)."
334 ** (ado, 1993-05-24)
336 ** From "http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html" by Markus Kuhn:
337 ** "Week 01 of a year is per definition the first week which has the
338 ** Thursday in this year, which is equivalent to the week which contains
339 ** the fourth day of January. In other words, the first week of a new year
340 ** is the week which has the majority of its days in the new year. Week 01
341 ** might also contain days from the previous year and the week before week
342 ** 01 of a year is the last week (52 or 53) of the previous year even if
343 ** it contains days from the new year. A week starts with Monday (day 1)
344 ** and ends with Sunday (day 7). For example, the first week of the year
345 ** 1997 lasts from 1996-12-30 to 1997-01-05..."
346 ** (ado, 1996-01-02)
349 int year;
350 int base;
351 int yday;
352 int wday;
353 int w;
355 year = t->tm_year;
356 base = TM_YEAR_BASE;
357 yday = t->tm_yday;
358 wday = t->tm_wday;
359 for ( ; ; ) {
360 int len;
361 int bot;
362 int top;
364 len = isleap_sum(year, base) ?
365 DAYSPERLYEAR :
366 DAYSPERNYEAR;
368 ** What yday (-3 ... 3) does
369 ** the ISO year begin on?
371 bot = ((yday + 11 - wday) %
372 DAYSPERWEEK) - 3;
374 ** What yday does the NEXT
375 ** ISO year begin on?
377 top = bot -
378 (len % DAYSPERWEEK);
379 if (top < -3)
380 top += DAYSPERWEEK;
381 top += len;
382 if (yday >= top) {
383 ++base;
384 w = 1;
385 break;
387 if (yday >= bot) {
388 w = 1 + ((yday - bot) /
389 DAYSPERWEEK);
390 break;
392 --base;
393 yday += isleap_sum(year, base) ?
394 DAYSPERLYEAR :
395 DAYSPERNYEAR;
397 #ifdef XPG4_1994_04_09
398 if ((w == 52 &&
399 t->tm_mon == TM_JANUARY) ||
400 (w == 1 &&
401 t->tm_mon == TM_DECEMBER))
402 w = 53;
403 #endif /* defined XPG4_1994_04_09 */
404 if (*format == 'V')
405 pt = _conv(w, "%02d",
406 pt, ptlim);
407 else if (*format == 'g') {
408 *warnp = IN_ALL;
409 pt = _yconv(year, base, 0, 1,
410 pt, ptlim);
411 } else pt = _yconv(year, base, 1, 1,
412 pt, ptlim);
414 continue;
415 case 'v':
417 ** From Arnold Robbins' strftime version 3.0:
418 ** "date as dd-bbb-YYYY"
419 ** (ado, 1993-05-24)
421 pt = _fmt(sp, "%e-%b-%Y", t, pt, ptlim, warnp);
422 continue;
423 case 'W':
424 pt = _conv((t->tm_yday + DAYSPERWEEK -
425 (t->tm_wday ?
426 (t->tm_wday - 1) :
427 (DAYSPERWEEK - 1))) / DAYSPERWEEK,
428 "%02d", pt, ptlim);
429 continue;
430 case 'w':
431 pt = _conv(t->tm_wday, "%d", pt, ptlim);
432 continue;
433 case 'X':
434 pt = _fmt(sp, Locale->t_fmt, t, pt, ptlim, warnp);
435 continue;
436 case 'x':
438 int warn2 = IN_SOME;
440 pt = _fmt(sp, Locale->d_fmt, t, pt, ptlim, &warn2);
441 if (warn2 == IN_ALL)
442 warn2 = IN_THIS;
443 if (warn2 > *warnp)
444 *warnp = warn2;
446 continue;
447 case 'y':
448 *warnp = IN_ALL;
449 pt = _yconv(t->tm_year, TM_YEAR_BASE, 0, 1,
450 pt, ptlim);
451 continue;
452 case 'Y':
453 pt = _yconv(t->tm_year, TM_YEAR_BASE, 1, 1,
454 pt, ptlim);
455 continue;
456 case 'Z':
457 #ifdef TM_ZONE
458 if (t->TM_ZONE != NULL)
459 pt = _add(t->TM_ZONE, pt, ptlim);
460 else
461 #endif /* defined TM_ZONE */
462 if (t->tm_isdst >= 0)
463 pt = _add((sp ?
464 tzgetname(sp, t->tm_isdst) :
465 tzname[t->tm_isdst != 0]),
466 pt, ptlim);
468 ** C99 says that %Z must be replaced by the
469 ** empty string if the time zone is not
470 ** determinable.
472 continue;
473 case 'z':
475 int diff;
476 char const * sign;
478 if (t->tm_isdst < 0)
479 continue;
480 #ifdef TM_GMTOFF
481 diff = (int)t->TM_GMTOFF;
482 #else /* !defined TM_GMTOFF */
484 ** C99 says that the UTC offset must
485 ** be computed by looking only at
486 ** tm_isdst. This requirement is
487 ** incorrect, since it means the code
488 ** must rely on magic (in this case
489 ** altzone and timezone), and the
490 ** magic might not have the correct
491 ** offset. Doing things correctly is
492 ** tricky and requires disobeying C99;
493 ** see GNU C strftime for details.
494 ** For now, punt and conform to the
495 ** standard, even though it's incorrect.
497 ** C99 says that %z must be replaced by the
498 ** empty string if the time zone is not
499 ** determinable, so output nothing if the
500 ** appropriate variables are not available.
502 #ifndef STD_INSPIRED
503 if (t->tm_isdst == 0)
504 #ifdef USG_COMPAT
505 diff = -timezone;
506 #else /* !defined USG_COMPAT */
507 continue;
508 #endif /* !defined USG_COMPAT */
509 else
510 #ifdef ALTZONE
511 diff = -altzone;
512 #else /* !defined ALTZONE */
513 continue;
514 #endif /* !defined ALTZONE */
515 #else /* defined STD_INSPIRED */
517 struct tm tmp;
518 time_t lct, gct;
521 ** Get calendar time from t
522 ** being treated as local.
524 tmp = *t; /* mktime discards const */
525 lct = mktime(&tmp);
527 if (lct == (time_t)-1)
528 continue;
531 ** Get calendar time from t
532 ** being treated as GMT.
534 tmp = *t; /* mktime discards const */
535 gct = timegm(&tmp);
537 if (gct == (time_t)-1)
538 continue;
540 /* LINTED difference will fit int */
541 diff = (intmax_t)gct - (intmax_t)lct;
543 #endif /* defined STD_INSPIRED */
544 #endif /* !defined TM_GMTOFF */
545 if (diff < 0) {
546 sign = "-";
547 diff = -diff;
548 } else sign = "+";
549 pt = _add(sign, pt, ptlim);
550 diff /= SECSPERMIN;
551 diff = (diff / MINSPERHOUR) * 100 +
552 (diff % MINSPERHOUR);
553 pt = _conv(diff, "%04d", pt, ptlim);
555 continue;
556 #ifdef __minix
557 case '+':
558 pt = _fmt(sp, Locale->c_fmt, t, pt, ptlim, warnp);
559 continue;
560 #endif /* !__minix */
561 #if 0
562 case '+':
563 pt = _fmt(sp, Locale->date_fmt, t, pt, ptlim,
564 warnp);
565 continue;
566 #endif
567 case '%':
569 ** X311J/88-090 (4.12.3.5): if conversion char is
570 ** undefined, behavior is undefined. Print out the
571 ** character itself as printf(3) also does.
573 default:
574 break;
577 if (pt == ptlim)
578 break;
579 *pt++ = *format;
581 return pt;
584 size_t
585 strftime(char * const s, const size_t maxsize,
586 const char * const format, const struct tm * const t)
588 tzset();
589 return strftime_z(NULL, s, maxsize, format, t);
592 static char *
593 _conv(n, format, pt, ptlim)
594 const int n;
595 const char * const format;
596 char * const pt;
597 const char * const ptlim;
599 char buf[INT_STRLEN_MAXIMUM(int) + 1];
601 (void) snprintf(buf, sizeof(buf), format, n);
602 return _add(buf, pt, ptlim);
605 static char *
606 _add(str, pt, ptlim)
607 const char * str;
608 char * pt;
609 const char * const ptlim;
611 while (pt < ptlim && (*pt = *str++) != '\0')
612 ++pt;
613 return pt;
617 ** POSIX and the C Standard are unclear or inconsistent about
618 ** what %C and %y do if the year is negative or exceeds 9999.
619 ** Use the convention that %C concatenated with %y yields the
620 ** same output as %Y, and that %Y contains at least 4 bytes,
621 ** with more only if necessary.
624 static char *
625 _yconv(a, b, convert_top, convert_yy, pt, ptlim)
626 const int a;
627 const int b;
628 const int convert_top;
629 const int convert_yy;
630 char * pt;
631 const char * const ptlim;
633 register int lead;
634 register int trail;
636 #define DIVISOR 100
637 trail = a % DIVISOR + b % DIVISOR;
638 lead = a / DIVISOR + b / DIVISOR + trail / DIVISOR;
639 trail %= DIVISOR;
640 if (trail < 0 && lead > 0) {
641 trail += DIVISOR;
642 --lead;
643 } else if (lead < 0 && trail > 0) {
644 trail -= DIVISOR;
645 ++lead;
647 if (convert_top) {
648 if (lead == 0 && trail < 0)
649 pt = _add("-0", pt, ptlim);
650 else pt = _conv(lead, "%02d", pt, ptlim);
652 if (convert_yy)
653 pt = _conv(((trail < 0) ? -trail : trail), "%02d", pt, ptlim);
654 return pt;
657 #ifdef LOCALE_HOME
658 static struct lc_time_T *
659 _loc(void)
661 static const char locale_home[] = LOCALE_HOME;
662 static const char lc_time[] = "LC_TIME";
663 static char * locale_buf;
665 int fd;
666 int oldsun; /* "...ain't got nothin' to do..." */
667 char * lbuf;
668 char * name;
669 char * p;
670 const char ** ap;
671 const char * plim;
672 char filename[FILENAME_MAX];
673 struct stat st;
674 size_t namesize;
675 size_t bufsize;
678 ** Use localebuf.mon[0] to signal whether locale is already set up.
680 if (localebuf.mon[0])
681 return &localebuf;
682 name = setlocale(LC_TIME, (char *) NULL);
683 if (name == NULL || *name == '\0')
684 goto no_locale;
686 ** If the locale name is the same as our cache, use the cache.
688 lbuf = locale_buf;
689 if (lbuf != NULL && strcmp(name, lbuf) == 0) {
690 p = lbuf;
691 for (ap = (const char **) &localebuf;
692 ap < (const char **) (&localebuf + 1);
693 ++ap)
694 *ap = p += strlen(p) + 1;
695 return &localebuf;
698 ** Slurp the locale file into the cache.
700 namesize = strlen(name) + 1;
701 if (sizeof filename <
702 ((sizeof locale_home) + namesize + (sizeof lc_time)))
703 goto no_locale;
704 oldsun = 0;
705 (void) sprintf(filename, "%s/%s/%s", locale_home, name, lc_time);
706 fd = open(filename, O_RDONLY);
707 if (fd < 0) {
709 ** Old Sun systems have a different naming and data convention.
711 oldsun = 1;
712 (void) sprintf(filename, "%s/%s/%s", locale_home,
713 lc_time, name);
714 fd = open(filename, O_RDONLY);
715 if (fd < 0)
716 goto no_locale;
718 if (fstat(fd, &st) != 0)
719 goto bad_locale;
720 if (st.st_size <= 0)
721 goto bad_locale;
722 bufsize = namesize + st.st_size;
723 locale_buf = NULL;
724 lbuf = (lbuf == NULL) ? malloc(bufsize) : realloc(lbuf, bufsize);
725 if (lbuf == NULL)
726 goto bad_locale;
727 (void) strcpy(lbuf, name);
728 p = lbuf + namesize;
729 plim = p + st.st_size;
730 if (read(fd, p, (size_t) st.st_size) != st.st_size)
731 goto bad_lbuf;
732 if (close(fd) != 0)
733 goto bad_lbuf;
735 ** Parse the locale file into localebuf.
737 if (plim[-1] != '\n')
738 goto bad_lbuf;
739 for (ap = (const char **) &localebuf;
740 ap < (const char **) (&localebuf + 1);
741 ++ap) {
742 if (p == plim)
743 goto bad_lbuf;
744 *ap = p;
745 while (*p != '\n')
746 ++p;
747 *p++ = '\0';
749 if (oldsun) {
751 ** SunOS 4 used an obsolescent format; see localdtconv(3).
752 ** c_fmt had the ``short format for dates and times together''
753 ** (SunOS 4 date, "%a %b %e %T %Z %Y" in the C locale);
754 ** date_fmt had the ``long format for dates''
755 ** (SunOS 4 strftime %C, "%A, %B %e, %Y" in the C locale).
756 ** Discard the latter in favor of the former.
758 localebuf.date_fmt = localebuf.c_fmt;
761 ** Record the successful parse in the cache.
763 locale_buf = lbuf;
765 return &localebuf;
767 bad_lbuf:
768 free(lbuf);
769 bad_locale:
770 (void) close(fd);
771 no_locale:
772 localebuf = C_time_locale;
773 locale_buf = NULL;
774 return &localebuf;
776 #endif /* defined LOCALE_HOME */