File: rfc822_mkdate.c

package info (click to toggle)
courier 0.60.0-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 52,288 kB
  • ctags: 12,677
  • sloc: ansic: 165,348; cpp: 24,820; sh: 16,410; perl: 6,839; makefile: 3,621; yacc: 289; sed: 16
file content (113 lines) | stat: -rw-r--r-- 1,504 bytes parent folder | download | duplicates (16)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
** Copyright 1998 - 1999 Double Precision, Inc.
** See COPYING for distribution information.
*/

/*
** $Id: rfc822_mkdate.c,v 1.4 2002/04/09 02:49:55 mrsam Exp $
*/

#include	"rfc822.h"

#include	<sys/types.h>
#include	<time.h>
#include	<stdio.h>
#include	<string.h>
#if	HAVE_UNISTD_H
#include	<unistd.h>
#endif

static const char * const months[]={
	"Jan",
	"Feb",
	"Mar",
	"Apr",
	"May",
	"Jun",
	"Jul",
	"Aug",
	"Sep",
	"Oct",
	"Nov",
	"Dec"};

static const char * const wdays[]={
	"Sun",
	"Mon",
	"Tue",
	"Wed",
	"Thu",
	"Fri",
	"Sat"};

void rfc822_mkdate_buf(time_t t, char *buf)
{
struct	tm *p;
int	offset;

#if	USE_TIME_ALTZONE

	p=localtime(&t);
	offset= -(int)timezone;

	if (p->tm_isdst > 0)
		offset= -(int)altzone;

	if (offset % 60)
	{
		offset=0;
		p=gmtime(&t);
	}
	offset /= 60;
#else
#if	USE_TIME_DAYLIGHT

	p=localtime(&t);
	offset= -(int)timezone;

	if (p->tm_isdst > 0)
		offset += 60*60;
	if (offset % 60)
	{
		offset=0;
		p=gmtime(&t);
	}
	offset /= 60;
#else
#if	USE_TIME_GMTOFF
	p=localtime(&t);
	offset= p->tm_gmtoff;

	if (offset % 60)
	{
		offset=0;
		p=gmtime(&t);
	}
	offset /= 60;
#else
	p=gmtime(&t);
	offset=0;
#endif
#endif
#endif

	offset = (offset % 60) + offset / 60 * 100;

	sprintf(buf, "%s, %02d %s %04d %02d:%02d:%02d %+05d",
		wdays[p->tm_wday],
		p->tm_mday,
		months[p->tm_mon],
		p->tm_year+1900,
		p->tm_hour,
		p->tm_min,
		p->tm_sec,
		offset);
}

const char *rfc822_mkdate(time_t t)
{
static char buf[50];

	rfc822_mkdate_buf(t, buf);
	return (buf);
}