-
Notifications
You must be signed in to change notification settings - Fork 39
/
strftime.c
63 lines (59 loc) · 1.43 KB
/
strftime.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <locale.h>
#include <string.h>
int
main(int argc, char *argv[])
{
time_t t;
struct tm *tm;
char *fmtchars = "aAbBcCdDeFgGhHIjklmMnOpPrRsStTuUVwWxXyYzZ+";
char *p;
char *opt_E = "cCxXyY";
char *opt_O = "deHImMSuUvwWy";
setlocale(LC_ALL, "");
time(&t);
tm = localtime(&t);
for (p = fmtchars; *p; p++) {
char fmt[16];
char buf[256];
printf("%%%c=", *p);
fmt[0] = '"';
fmt[1] = '%';
fmt[2] = *p;
fmt[3] = '"';
fmt[4] = '\0';
if (strftime(buf, sizeof buf, fmt, tm) == 0)
puts("FAILED");
else
puts(buf);
if (strchr(opt_E, *p)) {
printf("%%E%c=", *p);
fmt[0] = '"';
fmt[1] = '%';
fmt[2] = 'E';
fmt[3] = *p;
fmt[4] = '"';
fmt[5] = '\0';
if (strftime(buf, sizeof buf, fmt, tm) == 0)
puts("FAILED");
else
puts(buf);
}
if (strchr(opt_O, *p)) {
printf("%%O%c=", *p);
fmt[0] = '"';
fmt[1] = '%';
fmt[2] = 'O';
fmt[3] = *p;
fmt[4] = '"';
fmt[5] = '\0';
if (strftime(buf, sizeof buf, fmt, tm) == 0)
puts("FAILED");
else
puts(buf);
}
}
exit(0);
}