tzstrftime.c revision dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0
1dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#ifndef lint
2dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#ifndef NOID
3dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic char	elsieid[] = "@(#)strftime.c	8.1";
4dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
5dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** Based on the UCB version with the ID appearing below.
6dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** This is ANSIish only when "multibyte character == plain character".
7dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project*/
8dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif /* !defined NOID */
9dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif /* !defined lint */
10dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
11dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include <time.h>
12dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include <tzfile.h>
13dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include <limits.h>
14dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include <cutils/tztime.h>
15dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
16dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
17dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** Copyright (c) 1989 The Regents of the University of California.
18dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** All rights reserved.
19dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project**
20dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** Redistribution and use in source and binary forms are permitted
21dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** provided that the above copyright notice and this paragraph are
22dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** duplicated in all such forms and that any documentation,
23dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** advertising materials, and other materials related to such
24dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** distribution and use acknowledge that the software was developed
25dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** by the University of California, Berkeley. The name of the
26dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** University may not be used to endorse or promote products derived
27dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** from this software without specific prior written permission.
28dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
29dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
30dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
31dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project*/
32dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
33dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#ifndef LIBC_SCCS
34dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#ifndef lint
35dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic const char	sccsid[] = "@(#)strftime.c	5.4 (Berkeley) 3/14/89";
36dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif /* !defined lint */
37dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif /* !defined LIBC_SCCS */
38dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
39dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include <ctype.h>
40dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
41dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define P(x) x
42dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
43dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic char *	_add P((const char *, char *, const char *, int));
44dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic char *	_conv P((int, const char *, char *, const char *));
45dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic char *	_fmt P((const char *, const struct tm *, char *, const char *,
46dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			int *, const struct strftime_locale *Locale));
47dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic char *	_yconv P((int, int, int, int, char *, const char *, int));
48dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic char *	getformat P((int, char *, char *, char *, char *));
49dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
50dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectextern char *	tzname[];
51dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
52dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
53dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
54dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
55dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
56dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/* from private.h */
57dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
58dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#ifndef TYPE_BIT
59dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define TYPE_BIT(type)  (sizeof (type) * CHAR_BIT)
60dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif /* !defined TYPE_BIT */
61dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
62dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#ifndef TYPE_SIGNED
63dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define TYPE_SIGNED(type) (((type) -1) < 0)
64dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif /* !defined TYPE_SIGNED */
65dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
66dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#ifndef INT_STRLEN_MAXIMUM
67dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
68dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * ** 302 / 1000 is log10(2.0) rounded up.
69dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * ** Subtract one for the sign bit if the type is signed;
70dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * ** add one for integer division truncation;
71dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * ** add one more for a minus sign if the type is signed.
72dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * */
73dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define INT_STRLEN_MAXIMUM(type) \
74dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
75dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    1 + TYPE_SIGNED(type))
76dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif /* !defined INT_STRLEN_MAXIMUM */
77dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
78dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/* end of part from private.h */
79dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
80dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
81dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
82dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
83dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#ifndef YEAR_2000_NAME
84dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define YEAR_2000_NAME	"CHECK_STRFTIME_FORMATS_FOR_TWO_DIGIT_YEARS"
85dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif /* !defined YEAR_2000_NAME */
86dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
87dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define IN_NONE	0
88dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define IN_SOME	1
89dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define IN_THIS	2
90dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define IN_ALL	3
91dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
92dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define FORCE_LOWER_CASE 0x100
93dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
94dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectsize_t
95dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstrftime_tz(s, maxsize, format, t, Locale)
96dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectchar * const		s;
97dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectconst size_t		maxsize;
98dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectconst char * const	format;
99dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectconst struct tm * const	t;
100dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectconst struct strftime_locale *Locale;
101dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project{
102dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	char *	p;
103dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	int	warn;
104dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
105dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	warn = IN_NONE;
106dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize, &warn, Locale);
107dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#if 0
108dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	if (warn != IN_NONE && getenv(YEAR_2000_NAME) != NULL) {
109dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		(void) fprintf(stderr, "\n");
110dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		if (format == NULL)
111dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			(void) fprintf(stderr, "NULL strftime format ");
112dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		else	(void) fprintf(stderr, "strftime format \"%s\" ",
113dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				format);
114dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		(void) fprintf(stderr, "yields only two digits of years in ");
115dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		if (warn == IN_SOME)
116dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			(void) fprintf(stderr, "some locales");
117dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		else if (warn == IN_THIS)
118dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			(void) fprintf(stderr, "the current locale");
119dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		else	(void) fprintf(stderr, "all locales");
120dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		(void) fprintf(stderr, "\n");
121dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	}
122dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif /* !defined NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU */
123dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	if (p == s + maxsize)
124dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		return 0;
125dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	*p = '\0';
126dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	return p - s;
127dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project}
128dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
129dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic char *getformat(int modifier, char *normal, char *underscore,
130dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                       char *dash, char *zero) {
131dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    switch (modifier) {
132dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    case '_':
133dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        return underscore;
134dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
135dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    case '-':
136dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        return dash;
137dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
138dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    case '0':
139dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        return zero;
140dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    }
141dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
142dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    return normal;
143dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project}
144dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
145dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic char *
146dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project_fmt(format, t, pt, ptlim, warnp, Locale)
147dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectconst char *		format;
148dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectconst struct tm * const	t;
149dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectchar *			pt;
150dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectconst char * const	ptlim;
151dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectint *			warnp;
152dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectconst struct strftime_locale *Locale;
153dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project{
154dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	for ( ; *format; ++format) {
155dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		if (*format == '%') {
156dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            int modifier = 0;
157dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectlabel:
158dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			switch (*++format) {
159dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case '\0':
160dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				--format;
161dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				break;
162dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'A':
163dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _add((t->tm_wday < 0 ||
164dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					t->tm_wday >= DAYSPERWEEK) ?
165dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					"?" : Locale->weekday[t->tm_wday],
166dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					pt, ptlim, modifier);
167dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
168dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'a':
169dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _add((t->tm_wday < 0 ||
170dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					t->tm_wday >= DAYSPERWEEK) ?
171dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					"?" : Locale->wday[t->tm_wday],
172dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					pt, ptlim, modifier);
173dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
174dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'B':
175dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _add((t->tm_mon < 0 ||
176dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					t->tm_mon >= MONSPERYEAR) ?
177dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					"?" : Locale->month[t->tm_mon],
178dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					pt, ptlim, modifier);
179dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
180dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'b':
181dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'h':
182dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _add((t->tm_mon < 0 ||
183dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					t->tm_mon >= MONSPERYEAR) ?
184dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					"?" : Locale->mon[t->tm_mon],
185dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					pt, ptlim, modifier);
186dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
187dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'C':
188dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				/*
189dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** %C used to do a...
190dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				**	_fmt("%a %b %e %X %Y", t);
191dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** ...whereas now POSIX 1003.2 calls for
192dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** something completely different.
193dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** (ado, 1993-05-24)
194dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				*/
195dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _yconv(t->tm_year, TM_YEAR_BASE, 1, 0,
196dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					pt, ptlim, modifier);
197dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
198dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'c':
199dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				{
200dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				int warn2 = IN_SOME;
201dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
202dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _fmt(Locale->c_fmt, t, pt, ptlim, warnp, Locale);
203dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				if (warn2 == IN_ALL)
204dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					warn2 = IN_THIS;
205dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				if (warn2 > *warnp)
206dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					*warnp = warn2;
207dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				}
208dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
209dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'D':
210dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                pt = _fmt("%m/%d/%y", t, pt, ptlim, warnp, Locale);
211dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
212dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'd':
213dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                pt = _conv(t->tm_mday,
214dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                           getformat(modifier, "%02d",
215dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                                     "%2d", "%d", "%02d"),
216dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                           pt, ptlim);
217dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
218dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'E':
219dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'O':
220dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				/*
221dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** C99 locale modifiers.
222dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** The sequences
223dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				**	%Ec %EC %Ex %EX %Ey %EY
224dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				**	%Od %oe %OH %OI %Om %OM
225dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				**	%OS %Ou %OU %OV %Ow %OW %Oy
226dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** are supposed to provide alternate
227dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** representations.
228dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				*/
229dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				goto label;
230dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            case '_':
231dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            case '-':
232dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            case '0':
233dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            case '^':
234dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            case '#':
235dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                modifier = *format;
236dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                goto label;
237dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'e':
238dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _conv(t->tm_mday,
239dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                           getformat(modifier, "%2d",
240dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                                     "%2d", "%d", "%02d"),
241dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                           pt, ptlim);
242dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
243dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'F':
244dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _fmt("%Y-%m-%d", t, pt, ptlim, warnp, Locale);
245dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
246dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'H':
247dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _conv(t->tm_hour,
248dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                           getformat(modifier, "%02d",
249dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                                     "%2d", "%d", "%02d"),
250dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                           pt, ptlim);
251dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
252dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'I':
253dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _conv((t->tm_hour % 12) ?
254dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					(t->tm_hour % 12) : 12,
255dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					getformat(modifier, "%02d",
256dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                                  "%2d", "%d", "%02d"),
257dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                        pt, ptlim);
258dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
259dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'j':
260dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _conv(t->tm_yday + 1,
261dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                           getformat(modifier, "%03d", "%3d", "%d", "%03d"),
262dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                           pt, ptlim);
263dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
264dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'k':
265dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				/*
266dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** This used to be...
267dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				**	_conv(t->tm_hour % 12 ?
268dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				**		t->tm_hour % 12 : 12, 2, ' ');
269dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** ...and has been changed to the below to
270dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** match SunOS 4.1.1 and Arnold Robbins'
271dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** strftime version 3.0. That is, "%k" and
272dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** "%l" have been swapped.
273dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** (ado, 1993-05-24)
274dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				*/
275dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _conv(t->tm_hour,
276dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                           getformat(modifier, "%2d",
277dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                                     "%2d", "%d", "%02d"),
278dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                           pt, ptlim);
279dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
280dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#ifdef KITCHEN_SINK
281dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'K':
282dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				/*
283dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** After all this time, still unclaimed!
284dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				*/
285dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _add("kitchen sink", pt, ptlim, modifier);
286dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
287dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif /* defined KITCHEN_SINK */
288dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'l':
289dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				/*
290dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** This used to be...
291dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				**	_conv(t->tm_hour, 2, ' ');
292dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** ...and has been changed to the below to
293dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** match SunOS 4.1.1 and Arnold Robbin's
294dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** strftime version 3.0. That is, "%k" and
295dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** "%l" have been swapped.
296dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** (ado, 1993-05-24)
297dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				*/
298dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _conv((t->tm_hour % 12) ?
299dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					(t->tm_hour % 12) : 12,
300dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					getformat(modifier, "%2d",
301dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                                  "%2d", "%d", "%02d"),
302dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                        pt, ptlim);
303dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
304dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'M':
305dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _conv(t->tm_min,
306dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                           getformat(modifier, "%02d",
307dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                                     "%2d", "%d", "%02d"),
308dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                           pt, ptlim);
309dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
310dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'm':
311dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _conv(t->tm_mon + 1,
312dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                           getformat(modifier, "%02d",
313dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                                     "%2d", "%d", "%02d"),
314dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                           pt, ptlim);
315dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
316dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'n':
317dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _add("\n", pt, ptlim, modifier);
318dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
319dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'p':
320dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _add((t->tm_hour >= (HOURSPERDAY / 2)) ?
321dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					Locale->pm :
322dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					Locale->am,
323dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					pt, ptlim, modifier);
324dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
325dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'P':
326dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _add((t->tm_hour >= (HOURSPERDAY / 2)) ?
327dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					Locale->pm :
328dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					Locale->am,
329dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					pt, ptlim, FORCE_LOWER_CASE);
330dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
331dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'R':
332dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _fmt("%H:%M", t, pt, ptlim, warnp, Locale);
333dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
334dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'r':
335dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _fmt("%I:%M:%S %p", t, pt, ptlim, warnp, Locale);
336dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
337dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'S':
338dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _conv(t->tm_sec,
339dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                           getformat(modifier, "%02d",
340dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                                     "%2d", "%d", "%02d"),
341dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                           pt, ptlim);
342dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
343dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 's':
344dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				{
345dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					struct tm	tm;
346dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					char		buf[INT_STRLEN_MAXIMUM(
347dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project								time_t) + 1];
348dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					time_t		mkt;
349dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
350dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					tm = *t;
351dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					mkt = mktime(&tm);
352dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					if (TYPE_SIGNED(time_t))
353dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						(void) sprintf(buf, "%ld",
354dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project							(long) mkt);
355dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					else	(void) sprintf(buf, "%lu",
356dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project							(unsigned long) mkt);
357dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					pt = _add(buf, pt, ptlim, modifier);
358dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				}
359dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
360dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'T':
361dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _fmt("%H:%M:%S", t, pt, ptlim, warnp, Locale);
362dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
363dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 't':
364dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _add("\t", pt, ptlim, modifier);
365dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
366dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'U':
367dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _conv((t->tm_yday + DAYSPERWEEK -
368dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					t->tm_wday) / DAYSPERWEEK,
369dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					getformat(modifier, "%02d",
370dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                                  "%2d", "%d", "%02d"),
371dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                        pt, ptlim);
372dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
373dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'u':
374dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				/*
375dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** From Arnold Robbins' strftime version 3.0:
376dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** "ISO 8601: Weekday as a decimal number
377dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** [1 (Monday) - 7]"
378dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** (ado, 1993-05-24)
379dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				*/
380dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _conv((t->tm_wday == 0) ?
381dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					DAYSPERWEEK : t->tm_wday, "%d", pt, ptlim);
382dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
383dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'V':	/* ISO 8601 week number */
384dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'G':	/* ISO 8601 year (four digits) */
385dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'g':	/* ISO 8601 year (two digits) */
386dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
387dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** From Arnold Robbins' strftime version 3.0: "the week number of the
388dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** year (the first Monday as the first day of week 1) as a decimal number
389dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** (01-53)."
390dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** (ado, 1993-05-24)
391dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project**
392dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** From "http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html" by Markus Kuhn:
393dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** "Week 01 of a year is per definition the first week which has the
394dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** Thursday in this year, which is equivalent to the week which contains
395dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** the fourth day of January. In other words, the first week of a new year
396dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** is the week which has the majority of its days in the new year. Week 01
397dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** might also contain days from the previous year and the week before week
398dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** 01 of a year is the last week (52 or 53) of the previous year even if
399dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** it contains days from the new year. A week starts with Monday (day 1)
400dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** and ends with Sunday (day 7). For example, the first week of the year
401dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** 1997 lasts from 1996-12-30 to 1997-01-05..."
402dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** (ado, 1996-01-02)
403dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project*/
404dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				{
405dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					int	year;
406dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					int	base;
407dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					int	yday;
408dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					int	wday;
409dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					int	w;
410dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
411dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					year = t->tm_year;
412dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					base = TM_YEAR_BASE;
413dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					yday = t->tm_yday;
414dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					wday = t->tm_wday;
415dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					for ( ; ; ) {
416dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						int	len;
417dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						int	bot;
418dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						int	top;
419dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
420dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						len = isleap_sum(year, base) ?
421dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project							DAYSPERLYEAR :
422dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project							DAYSPERNYEAR;
423dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						/*
424dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						** What yday (-3 ... 3) does
425dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						** the ISO year begin on?
426dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						*/
427dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						bot = ((yday + 11 - wday) %
428dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project							DAYSPERWEEK) - 3;
429dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						/*
430dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						** What yday does the NEXT
431dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						** ISO year begin on?
432dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						*/
433dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						top = bot -
434dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project							(len % DAYSPERWEEK);
435dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						if (top < -3)
436dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project							top += DAYSPERWEEK;
437dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						top += len;
438dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						if (yday >= top) {
439dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project							++base;
440dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project							w = 1;
441dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project							break;
442dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						}
443dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						if (yday >= bot) {
444dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project							w = 1 + ((yday - bot) /
445dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project								DAYSPERWEEK);
446dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project							break;
447dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						}
448dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						--base;
449dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						yday += isleap_sum(year, base) ?
450dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project							DAYSPERLYEAR :
451dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project							DAYSPERNYEAR;
452dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					}
453dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#ifdef XPG4_1994_04_09
454dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					if ((w == 52 &&
455dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						t->tm_mon == TM_JANUARY) ||
456dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						(w == 1 &&
457dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						t->tm_mon == TM_DECEMBER))
458dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project							w = 53;
459dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif /* defined XPG4_1994_04_09 */
460dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					if (*format == 'V')
461dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						pt = _conv(w,
462dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                                           getformat(modifier,
463dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                                                     "%02d",
464dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                                                     "%2d",
465dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                                                     "%d",
466dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                                                     "%02d"),
467dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project							   pt, ptlim);
468dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					else if (*format == 'g') {
469dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						*warnp = IN_ALL;
470dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						pt = _yconv(year, base, 0, 1,
471dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project							pt, ptlim, modifier);
472dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					} else	pt = _yconv(year, base, 1, 1,
473dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project							pt, ptlim, modifier);
474dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				}
475dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
476dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'v':
477dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				/*
478dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** From Arnold Robbins' strftime version 3.0:
479dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** "date as dd-bbb-YYYY"
480dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** (ado, 1993-05-24)
481dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				*/
482dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _fmt("%e-%b-%Y", t, pt, ptlim, warnp, Locale);
483dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
484dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'W':
485dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _conv((t->tm_yday + DAYSPERWEEK -
486dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					(t->tm_wday ?
487dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					(t->tm_wday - 1) :
488dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					(DAYSPERWEEK - 1))) / DAYSPERWEEK,
489dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					getformat(modifier, "%02d",
490dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                                  "%2d", "%d", "%02d"),
491dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                        pt, ptlim);
492dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
493dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'w':
494dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _conv(t->tm_wday, "%d", pt, ptlim);
495dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
496dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'X':
497dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _fmt(Locale->X_fmt, t, pt, ptlim, warnp, Locale);
498dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
499dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'x':
500dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				{
501dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				int	warn2 = IN_SOME;
502dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
503dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _fmt(Locale->x_fmt, t, pt, ptlim, &warn2, Locale);
504dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				if (warn2 == IN_ALL)
505dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					warn2 = IN_THIS;
506dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				if (warn2 > *warnp)
507dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					*warnp = warn2;
508dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				}
509dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
510dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'y':
511dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				*warnp = IN_ALL;
512dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _yconv(t->tm_year, TM_YEAR_BASE, 0, 1,
513dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					pt, ptlim, modifier);
514dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
515dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'Y':
516dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _yconv(t->tm_year, TM_YEAR_BASE, 1, 1,
517dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					pt, ptlim, modifier);
518dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
519dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'Z':
520dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#ifdef TM_ZONE
521dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				if (t->TM_ZONE != NULL)
522dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					pt = _add(t->TM_ZONE, pt, ptlim,
523dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                                  modifier);
524dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				else
525dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif /* defined TM_ZONE */
526dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				if (t->tm_isdst >= 0)
527dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					pt = _add(tzname[t->tm_isdst != 0],
528dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project						pt, ptlim, modifier);
529dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				/*
530dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** C99 says that %Z must be replaced by the
531dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** empty string if the time zone is not
532dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** determinable.
533dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				*/
534dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
535dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case 'z':
536dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				{
537dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				int		diff;
538dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				char const *	sign;
539dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
540dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				if (t->tm_isdst < 0)
541dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					continue;
542dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#ifdef TM_GMTOFF
543dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				diff = t->TM_GMTOFF;
544dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#else /* !defined TM_GMTOFF */
545dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				/*
546dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** C99 says that the UTC offset must
547dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** be computed by looking only at
548dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** tm_isdst. This requirement is
549dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** incorrect, since it means the code
550dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** must rely on magic (in this case
551dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** altzone and timezone), and the
552dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** magic might not have the correct
553dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** offset. Doing things correctly is
554dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** tricky and requires disobeying C99;
555dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** see GNU C strftime for details.
556dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** For now, punt and conform to the
557dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** standard, even though it's incorrect.
558dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				**
559dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** C99 says that %z must be replaced by the
560dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** empty string if the time zone is not
561dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** determinable, so output nothing if the
562dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				** appropriate variables are not available.
563dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				*/
564dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				if (t->tm_isdst == 0)
565dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#ifdef USG_COMPAT
566dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					diff = -timezone;
567dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#else /* !defined USG_COMPAT */
568dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					continue;
569dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif /* !defined USG_COMPAT */
570dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				else
571dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#ifdef ALTZONE
572dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					diff = -altzone;
573dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#else /* !defined ALTZONE */
574dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					continue;
575dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif /* !defined ALTZONE */
576dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif /* !defined TM_GMTOFF */
577dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				if (diff < 0) {
578dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					sign = "-";
579dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					diff = -diff;
580dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				} else	sign = "+";
581dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _add(sign, pt, ptlim, modifier);
582dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				diff /= SECSPERMIN;
583dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				diff = (diff / MINSPERHOUR) * 100 +
584dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					(diff % MINSPERHOUR);
585dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _conv(diff,
586dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                           getformat(modifier, "%04d",
587dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                                     "%4d", "%d", "%04d"),
588dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                           pt, ptlim);
589dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				}
590dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
591dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case '+':
592dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				pt = _fmt(Locale->date_fmt, t, pt, ptlim,
593dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					warnp, Locale);
594dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				continue;
595dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			case '%':
596dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			/*
597dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			** X311J/88-090 (4.12.3.5): if conversion char is
598dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			** undefined, behavior is undefined. Print out the
599dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			** character itself as printf(3) also does.
600dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			*/
601dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			default:
602dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				break;
603dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			}
604dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		}
605dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		if (pt == ptlim)
606dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			break;
607dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		*pt++ = *format;
608dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	}
609dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	return pt;
610dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project}
611dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
612dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic char *
613dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project_conv(n, format, pt, ptlim)
614dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectconst int		n;
615dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectconst char * const	format;
616dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectchar * const		pt;
617dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectconst char * const	ptlim;
618dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project{
619dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	char	buf[INT_STRLEN_MAXIMUM(int) + 1];
620dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
621dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	(void) sprintf(buf, format, n);
622dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	return _add(buf, pt, ptlim, 0);
623dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project}
624dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
625dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic char *
626dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project_add(str, pt, ptlim, modifier)
627dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectconst char *		str;
628dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectchar *			pt;
629dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectconst char * const	ptlim;
630dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectint                     modifier;
631dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project{
632dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        int c;
633dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
634dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        switch (modifier) {
635dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        case FORCE_LOWER_CASE:
636dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                while (pt < ptlim && (*pt = tolower(*str++)) != '\0') {
637dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        ++pt;
638dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                }
639dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                break;
640dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
641dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        case '^':
642dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                while (pt < ptlim && (*pt = toupper(*str++)) != '\0') {
643dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        ++pt;
644dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                }
645dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                break;
646dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
647dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        case '#':
648dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                while (pt < ptlim && (c = *str++) != '\0') {
649dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        if (isupper(c)) {
650dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                c = tolower(c);
651dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        } else if (islower(c)) {
652dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                c = toupper(c);
653dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        }
654dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        *pt = c;
655dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        ++pt;
656dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                }
657dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
658dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                break;
659dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
660dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        default:
661dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                while (pt < ptlim && (*pt = *str++) != '\0') {
662dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        ++pt;
663dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                }
664dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        }
665dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
666dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	return pt;
667dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project}
668dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
669dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
670dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** POSIX and the C Standard are unclear or inconsistent about
671dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** what %C and %y do if the year is negative or exceeds 9999.
672dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** Use the convention that %C concatenated with %y yields the
673dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** same output as %Y, and that %Y contains at least 4 bytes,
674dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** with more only if necessary.
675dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project*/
676dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
677dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic char *
678dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project_yconv(a, b, convert_top, convert_yy, pt, ptlim, modifier)
679dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectconst int		a;
680dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectconst int		b;
681dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectconst int		convert_top;
682dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectconst int		convert_yy;
683dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectchar *			pt;
684dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectconst char * const	ptlim;
685dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectint                     modifier;
686dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project{
687dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	register int	lead;
688dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	register int	trail;
689dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
690dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define DIVISOR	100
691dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	trail = a % DIVISOR + b % DIVISOR;
692dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	lead = a / DIVISOR + b / DIVISOR + trail / DIVISOR;
693dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	trail %= DIVISOR;
694dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	if (trail < 0 && lead > 0) {
695dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		trail += DIVISOR;
696dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		--lead;
697dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	} else if (lead < 0 && trail > 0) {
698dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		trail -= DIVISOR;
699dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		++lead;
700dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	}
701dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	if (convert_top) {
702dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		if (lead == 0 && trail < 0)
703dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			pt = _add("-0", pt, ptlim, modifier);
704dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		else	pt = _conv(lead, getformat(modifier, "%02d",
705dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                                   "%2d", "%d", "%02d"),
706dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                   pt, ptlim);
707dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	}
708dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	if (convert_yy)
709dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		pt = _conv(((trail < 0) ? -trail : trail),
710dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                           getformat(modifier, "%02d", "%2d", "%d", "%02d"),
711dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                           pt, ptlim);
712dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	return pt;
713dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project}
714dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
715dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#ifdef LOCALE_HOME
716dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic struct lc_time_T *
717dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project_loc P((void))
718dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project{
719dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	static const char	locale_home[] = LOCALE_HOME;
720dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	static const char	lc_time[] = "LC_TIME";
721dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	static char *		locale_buf;
722dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
723dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	int			fd;
724dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	int			oldsun;	/* "...ain't got nothin' to do..." */
725dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	char *			lbuf;
726dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	char *			name;
727dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	char *			p;
728dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	const char **		ap;
729dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	const char *		plim;
730dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	char			filename[FILENAME_MAX];
731dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	struct stat		st;
732dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	size_t			namesize;
733dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	size_t			bufsize;
734dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
735dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	/*
736dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	** Use localebuf.mon[0] to signal whether locale is already set up.
737dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	*/
738dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	if (localebuf.mon[0])
739dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		return &localebuf;
740dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	name = setlocale(LC_TIME, (char *) NULL);
741dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	if (name == NULL || *name == '\0')
742dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		goto no_locale;
743dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	/*
744dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	** If the locale name is the same as our cache, use the cache.
745dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	*/
746dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	lbuf = locale_buf;
747dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	if (lbuf != NULL && strcmp(name, lbuf) == 0) {
748dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		p = lbuf;
749dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		for (ap = (const char **) &localebuf;
750dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			ap < (const char **) (&localebuf + 1);
751dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				++ap)
752dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					*ap = p += strlen(p) + 1;
753dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		return &localebuf;
754dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	}
755dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	/*
756dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	** Slurp the locale file into the cache.
757dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	*/
758dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	namesize = strlen(name) + 1;
759dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	if (sizeof filename <
760dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		((sizeof locale_home) + namesize + (sizeof lc_time)))
761dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			goto no_locale;
762dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	oldsun = 0;
763dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	(void) sprintf(filename, "%s/%s/%s", locale_home, name, lc_time);
764dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	fd = open(filename, O_RDONLY);
765dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	if (fd < 0) {
766dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		/*
767dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		** Old Sun systems have a different naming and data convention.
768dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		*/
769dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		oldsun = 1;
770dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		(void) sprintf(filename, "%s/%s/%s", locale_home,
771dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			lc_time, name);
772dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		fd = open(filename, O_RDONLY);
773dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		if (fd < 0)
774dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			goto no_locale;
775dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	}
776dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	if (fstat(fd, &st) != 0)
777dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		goto bad_locale;
778dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	if (st.st_size <= 0)
779dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		goto bad_locale;
780dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	bufsize = namesize + st.st_size;
781dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	locale_buf = NULL;
782dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	lbuf = (lbuf == NULL) ? malloc(bufsize) : realloc(lbuf, bufsize);
783dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	if (lbuf == NULL)
784dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		goto bad_locale;
785dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	(void) strcpy(lbuf, name);
786dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	p = lbuf + namesize;
787dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	plim = p + st.st_size;
788dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	if (read(fd, p, (size_t) st.st_size) != st.st_size)
789dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		goto bad_lbuf;
790dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	if (close(fd) != 0)
791dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		goto bad_lbuf;
792dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	/*
793dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	** Parse the locale file into localebuf.
794dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	*/
795dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	if (plim[-1] != '\n')
796dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		goto bad_lbuf;
797dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	for (ap = (const char **) &localebuf;
798dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		ap < (const char **) (&localebuf + 1);
799dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project			++ap) {
800dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				if (p == plim)
801dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					goto bad_lbuf;
802dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				*ap = p;
803dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				while (*p != '\n')
804dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project					++p;
805dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project				*p++ = '\0';
806dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	}
807dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	if (oldsun) {
808dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		/*
809dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		** SunOS 4 used an obsolescent format; see localdtconv(3).
810dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		** c_fmt had the ``short format for dates and times together''
811dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		** (SunOS 4 date, "%a %b %e %T %Z %Y" in the C locale);
812dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		** date_fmt had the ``long format for dates''
813dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		** (SunOS 4 strftime %C, "%A, %B %e, %Y" in the C locale).
814dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		** Discard the latter in favor of the former.
815dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		*/
816dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		localebuf.date_fmt = localebuf.c_fmt;
817dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	}
818dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	/*
819dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	** Record the successful parse in the cache.
820dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	*/
821dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	locale_buf = lbuf;
822dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
823dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	return &localebuf;
824dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
825dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectbad_lbuf:
826dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	free(lbuf);
827dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectbad_locale:
828dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	(void) close(fd);
829dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectno_locale:
830dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	localebuf = C_time_locale;
831dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	locale_buf = NULL;
832dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	return &localebuf;
833dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project}
834dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif /* defined LOCALE_HOME */
835