comparison src/strftime.c @ 442:abe6d1db359e r21-2-36

Import from CVS: tag r21-2-36
author cvs
date Mon, 13 Aug 2007 11:35:02 +0200
parents 3ecd8885ac67
children 943eaba38521
comparison
equal deleted inserted replaced
441:72a7cfa4a488 442:abe6d1db359e
92 92
93 #ifndef STDC_HEADERS 93 #ifndef STDC_HEADERS
94 time_t mktime (); 94 time_t mktime ();
95 #endif 95 #endif
96 96
97 #if defined(WINDOWSNT) || defined(__CYGWIN32__) 97 #if defined(WIN32_NATIVE) || defined(CYGWIN)
98 #include <time.h> 98 #include <time.h>
99 #else 99 #else
100 #if defined(HAVE_TZNAME) 100 #if defined(HAVE_TZNAME)
101 extern char *tzname[2]; 101 extern char *tzname[2];
102 #endif 102 #endif
103 #endif /* WINDOWSNT */ 103 #endif /* WIN32_NATIVE */
104 104
105 #ifdef emacs 105 #ifdef emacs
106 #define strftime emacs_strftime 106 #define strftime emacs_strftime
107 #endif 107 #endif
108 108
110 enum padding 110 enum padding
111 { 111 {
112 none, blank, zero 112 none, blank, zero
113 }; 113 };
114 114
115 static char CONST* CONST days[] = 115 static char const* const days[] =
116 { 116 {
117 "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" 117 "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
118 }; 118 };
119 119
120 static char CONST * CONST months[] = 120 static char const * const months[] =
121 { 121 {
122 "January", "February", "March", "April", "May", "June", 122 "January", "February", "March", "April", "May", "June",
123 "July", "August", "September", "October", "November", "December" 123 "July", "August", "September", "October", "November", "December"
124 }; 124 };
125 125
172 } 172 }
173 173
174 /* Like strncpy except return the number of characters copied. */ 174 /* Like strncpy except return the number of characters copied. */
175 175
176 static int 176 static int
177 add_str (char *to, CONST char *from, int max) 177 add_str (char *to, const char *from, int max)
178 { 178 {
179 int i; 179 int i;
180 180
181 for (i = 0; from[i] && i <= max; ++i) 181 for (i = 0; from[i] && i <= max; ++i)
182 to[i] = from[i]; 182 to[i] = from[i];
201 201
202 /* Return the week in the year of the time in TM, with the weeks 202 /* Return the week in the year of the time in TM, with the weeks
203 starting on Sundays. */ 203 starting on Sundays. */
204 204
205 static int 205 static int
206 sun_week (CONST struct tm *tm) 206 sun_week (const struct tm *tm)
207 { 207 {
208 int dl; 208 int dl;
209 209
210 /* Set `dl' to the day in the year of the last day of the week previous 210 /* Set `dl' to the day in the year of the last day of the week previous
211 to the one containing the day specified in TM. If the day specified 211 to the one containing the day specified in TM. If the day specified
218 218
219 /* Return the week in the year of the time in TM, with the weeks 219 /* Return the week in the year of the time in TM, with the weeks
220 starting on Mondays. */ 220 starting on Mondays. */
221 221
222 static int 222 static int
223 mon_week (CONST struct tm *tm) 223 mon_week (const struct tm *tm)
224 { 224 {
225 int dl, wday; 225 int dl, wday;
226 226
227 if (tm->tm_wday == 0) 227 if (tm->tm_wday == 0)
228 wday = 6; 228 wday = 6;
231 dl = tm->tm_yday - wday; 231 dl = tm->tm_yday - wday;
232 return dl <= 0 ? 0 : dl / 7 + (dl % 7 != 0); 232 return dl <= 0 ? 0 : dl / 7 + (dl % 7 != 0);
233 } 233 }
234 234
235 #if !defined(HAVE_TM_ZONE) && !defined(HAVE_TZNAME) 235 #if !defined(HAVE_TM_ZONE) && !defined(HAVE_TZNAME)
236 char *zone_name (const struct tm *tp);
236 char * 237 char *
237 zone_name (CONST struct tm *tp) 238 zone_name (const struct tm *tp)
238 { 239 {
239 char *timezone (); 240 char *timezone ();
240 struct timeval tv; 241 struct timeval tv;
241 struct timezone tz; 242 struct timezone tz;
242 243
249 results in STRING. 250 results in STRING.
250 Return the number of characters (not including terminating null) 251 Return the number of characters (not including terminating null)
251 that were put into STRING, or 0 if the length would have 252 that were put into STRING, or 0 if the length would have
252 exceeded MAX. */ 253 exceeded MAX. */
253 254
254 size_t strftime (char *string, size_t max, CONST char *format, 255 size_t strftime (char *string, size_t max, const char *format,
255 CONST struct tm *tm); 256 const struct tm *tm);
256 257
257 size_t 258 size_t
258 strftime (char *string, size_t max, CONST char *format, CONST struct tm *tm) 259 strftime (char *string, size_t max, const char *format, const struct tm *tm)
259 { 260 {
260 enum padding pad; /* Type of padding to apply. */ 261 enum padding pad; /* Type of padding to apply. */
261 size_t length = 0; /* Characters put in STRING so far. */ 262 size_t length = 0; /* Characters put in STRING so far. */
262 263
263 for (; *format && length < max; ++format) 264 for (; *format && length < max; ++format)