d9898ee8 |
1 | /* |
2 | ** Copyright 1998 - 1999 Double Precision, Inc. |
3 | ** See COPYING for distribution information. |
4 | */ |
5 | |
6 | /* |
d9898ee8 |
7 | */ |
8 | |
9 | #include "rfc822.h" |
10 | |
11 | #include <sys/types.h> |
12 | #include <time.h> |
13 | #include <stdio.h> |
14 | #include <string.h> |
15 | #if HAVE_UNISTD_H |
16 | #include <unistd.h> |
17 | #endif |
18 | |
19 | static const char * const months[]={ |
20 | "Jan", |
21 | "Feb", |
22 | "Mar", |
23 | "Apr", |
24 | "May", |
25 | "Jun", |
26 | "Jul", |
27 | "Aug", |
28 | "Sep", |
29 | "Oct", |
30 | "Nov", |
31 | "Dec"}; |
32 | |
33 | static const char * const wdays[]={ |
34 | "Sun", |
35 | "Mon", |
36 | "Tue", |
37 | "Wed", |
38 | "Thu", |
39 | "Fri", |
40 | "Sat"}; |
41 | |
42 | void rfc822_mkdate_buf(time_t t, char *buf) |
43 | { |
44 | struct tm *p; |
45 | int offset; |
46 | |
47 | #if USE_TIME_ALTZONE |
48 | |
49 | p=localtime(&t); |
50 | offset= -(int)timezone; |
51 | |
52 | if (p->tm_isdst > 0) |
53 | offset= -(int)altzone; |
54 | |
55 | if (offset % 60) |
56 | { |
57 | offset=0; |
58 | p=gmtime(&t); |
59 | } |
60 | offset /= 60; |
61 | #else |
62 | #if USE_TIME_DAYLIGHT |
63 | |
64 | p=localtime(&t); |
65 | offset= -(int)timezone; |
66 | |
67 | if (p->tm_isdst > 0) |
68 | offset += 60*60; |
69 | if (offset % 60) |
70 | { |
71 | offset=0; |
72 | p=gmtime(&t); |
73 | } |
74 | offset /= 60; |
75 | #else |
76 | #if USE_TIME_GMTOFF |
77 | p=localtime(&t); |
78 | offset= p->tm_gmtoff; |
79 | |
80 | if (offset % 60) |
81 | { |
82 | offset=0; |
83 | p=gmtime(&t); |
84 | } |
85 | offset /= 60; |
86 | #else |
87 | p=gmtime(&t); |
88 | offset=0; |
89 | #endif |
90 | #endif |
91 | #endif |
92 | |
93 | offset = (offset % 60) + offset / 60 * 100; |
94 | |
95 | sprintf(buf, "%s, %02d %s %04d %02d:%02d:%02d %+05d", |
96 | wdays[p->tm_wday], |
97 | p->tm_mday, |
98 | months[p->tm_mon], |
99 | p->tm_year+1900, |
100 | p->tm_hour, |
101 | p->tm_min, |
102 | p->tm_sec, |
103 | offset); |
104 | } |
105 | |
106 | const char *rfc822_mkdate(time_t t) |
107 | { |
108 | static char buf[50]; |
109 | |
110 | rfc822_mkdate_buf(t, buf); |
111 | return (buf); |
112 | } |