arpadate.c (302408) | arpadate.c (38032) |
---|---|
1/* | 1/* |
2 * Copyright (c) 1998-2001 Proofpoint, Inc. and its suppliers. 3 * All rights reserved. | 2 * Copyright (c) 1998 Sendmail, Inc. All rights reserved. |
4 * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved. 5 * Copyright (c) 1988, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * By using this file, you agree to the terms and conditions set 9 * forth in the LICENSE file which can be found at the top level of 10 * the sendmail distribution. 11 * 12 */ 13 | 3 * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved. 4 * Copyright (c) 1988, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * By using this file, you agree to the terms and conditions set 8 * forth in the LICENSE file which can be found at the top level of 9 * the sendmail distribution. 10 * 11 */ 12 |
14#include <sendmail.h> | 13#ifndef lint 14static char sccsid[] = "@(#)arpadate.c 8.12 (Berkeley) 5/19/98"; 15#endif /* not lint */ |
15 | 16 |
16SM_RCSID("@(#)$Id: arpadate.c,v 8.32 2013-11-22 20:51:55 ca Exp $") | 17# include "sendmail.h" |
17 18/* 19** ARPADATE -- Create date in ARPANET format 20** 21** Parameters: 22** ud -- unix style date string. if NULL, one is created. 23** 24** Returns: 25** pointer to an ARPANET date field 26** 27** Side Effects: 28** none 29** 30** WARNING: 31** date is stored in a local buffer -- subsequent 32** calls will overwrite. 33** 34** Bugs: 35** Timezone is computed from local time, rather than | 18 19/* 20** ARPADATE -- Create date in ARPANET format 21** 22** Parameters: 23** ud -- unix style date string. if NULL, one is created. 24** 25** Returns: 26** pointer to an ARPANET date field 27** 28** Side Effects: 29** none 30** 31** WARNING: 32** date is stored in a local buffer -- subsequent 33** calls will overwrite. 34** 35** Bugs: 36** Timezone is computed from local time, rather than |
36** from wherever (and whenever) the message was sent. | 37** from whereever (and whenever) the message was sent. |
37** To do better is very hard. 38** 39** Some sites are now inserting the timezone into the 40** local date. This routine should figure out what 41** the format is and work appropriately. 42*/ 43 44#ifndef TZNAME_MAX 45# define TZNAME_MAX 50 /* max size of timezone */ | 38** To do better is very hard. 39** 40** Some sites are now inserting the timezone into the 41** local date. This routine should figure out what 42** the format is and work appropriately. 43*/ 44 45#ifndef TZNAME_MAX 46# define TZNAME_MAX 50 /* max size of timezone */ |
46#endif /* ! TZNAME_MAX */ | 47#endif |
47 48/* values for TZ_TYPE */ 49#define TZ_NONE 0 /* no character timezone support */ 50#define TZ_TM_NAME 1 /* use tm->tm_name */ 51#define TZ_TM_ZONE 2 /* use tm->tm_zone */ 52#define TZ_TZNAME 3 /* use tzname[] */ 53#define TZ_TIMEZONE 4 /* use timezone() */ 54 --- 12 unchanged lines hidden (view full) --- 67 static char b[43 + TZNAME_MAX]; 68 69 /* 70 ** Get current time. 71 ** This will be used if a null argument is passed and 72 ** to resolve the timezone. 73 */ 74 | 48 49/* values for TZ_TYPE */ 50#define TZ_NONE 0 /* no character timezone support */ 51#define TZ_TM_NAME 1 /* use tm->tm_name */ 52#define TZ_TM_ZONE 2 /* use tm->tm_zone */ 53#define TZ_TZNAME 3 /* use tzname[] */ 54#define TZ_TIMEZONE 4 /* use timezone() */ 55 --- 12 unchanged lines hidden (view full) --- 68 static char b[43 + TZNAME_MAX]; 69 70 /* 71 ** Get current time. 72 ** This will be used if a null argument is passed and 73 ** to resolve the timezone. 74 */ 75 |
75 /* SM_REQUIRE(ud == NULL || strlen(ud) >= 23); */ 76 t = curtime(); | 76 (void) time(&t); |
77 if (ud == NULL) 78 ud = ctime(&t); 79 80 /* 81 ** Crack the UNIX date line in a singularly unoriginal way. 82 */ 83 84 q = b; --- 26 unchanged lines hidden (view full) --- 111 *q++ = *p++; 112 *q++ = ' '; 113 114 p = &ud[11]; /* 01:03:52 */ 115 for (i = 8; i > 0; i--) 116 *q++ = *p++; 117 118 /* | 77 if (ud == NULL) 78 ud = ctime(&t); 79 80 /* 81 ** Crack the UNIX date line in a singularly unoriginal way. 82 */ 83 84 q = b; --- 26 unchanged lines hidden (view full) --- 111 *q++ = *p++; 112 *q++ = ' '; 113 114 p = &ud[11]; /* 01:03:52 */ 115 for (i = 8; i > 0; i--) 116 *q++ = *p++; 117 118 /* |
119 ** should really get the timezone from the time in "ud" (which 120 ** is only different if a non-null arg was passed which is different 121 ** from the current time), but for all practical purposes, returning 122 ** the current local zone will do (its all that is ever needed). 123 */ 124 | 119 * should really get the timezone from the time in "ud" (which 120 * is only different if a non-null arg was passed which is different 121 * from the current time), but for all practical purposes, returning 122 * the current local zone will do (its all that is ever needed). 123 */ |
125 gmt = *gmtime(&t); 126 lt = localtime(&t); 127 128 off = (lt->tm_hour - gmt.tm_hour) * 60 + lt->tm_min - gmt.tm_min; 129 130 /* assume that offset isn't more than a day ... */ 131 if (lt->tm_year < gmt.tm_year) 132 off -= 24 * 60; --- 11 unchanged lines hidden (view full) --- 144 *q++ = 'M'; 145 *q++ = 'T'; 146 } 147 else 148 { 149 tz = NULL; 150#if TZ_TYPE == TZ_TM_NAME 151 tz = lt->tm_name; | 124 gmt = *gmtime(&t); 125 lt = localtime(&t); 126 127 off = (lt->tm_hour - gmt.tm_hour) * 60 + lt->tm_min - gmt.tm_min; 128 129 /* assume that offset isn't more than a day ... */ 130 if (lt->tm_year < gmt.tm_year) 131 off -= 24 * 60; --- 11 unchanged lines hidden (view full) --- 143 *q++ = 'M'; 144 *q++ = 'T'; 145 } 146 else 147 { 148 tz = NULL; 149#if TZ_TYPE == TZ_TM_NAME 150 tz = lt->tm_name; |
152#endif /* TZ_TYPE == TZ_TM_NAME */ | 151#endif |
153#if TZ_TYPE == TZ_TM_ZONE 154 tz = lt->tm_zone; | 152#if TZ_TYPE == TZ_TM_ZONE 153 tz = lt->tm_zone; |
155#endif /* TZ_TYPE == TZ_TM_ZONE */ | 154#endif |
156#if TZ_TYPE == TZ_TZNAME 157 { 158 extern char *tzname[]; 159 | 155#if TZ_TYPE == TZ_TZNAME 156 { 157 extern char *tzname[]; 158 |
160 if (lt->tm_isdst > 0) 161 tz = tzname[1]; 162 else if (lt->tm_isdst == 0) 163 tz = tzname[0]; 164 else 165 tz = NULL; | 159 tz = tzname[lt->tm_isdst]; |
166 } | 160 } |
167#endif /* TZ_TYPE == TZ_TZNAME */ | 161#endif |
168#if TZ_TYPE == TZ_TIMEZONE 169 { 170 extern char *timezone(); 171 172 tz = timezone(off, lt->tm_isdst); 173 } | 162#if TZ_TYPE == TZ_TIMEZONE 163 { 164 extern char *timezone(); 165 166 tz = timezone(off, lt->tm_isdst); 167 } |
174#endif /* TZ_TYPE == TZ_TIMEZONE */ | 168#endif |
175 if (off < 0) 176 { 177 off = -off; 178 *q++ = '-'; 179 } 180 else 181 *q++ = '+'; 182 --- 4 unchanged lines hidden (view full) --- 187 *q++ = (off / 60) % 10 + '0'; 188 off %= 60; 189 *q++ = (off / 10) + '0'; 190 *q++ = (off % 10) + '0'; 191 if (tz != NULL && *tz != '\0') 192 { 193 *q++ = ' '; 194 *q++ = '('; | 169 if (off < 0) 170 { 171 off = -off; 172 *q++ = '-'; 173 } 174 else 175 *q++ = '+'; 176 --- 4 unchanged lines hidden (view full) --- 181 *q++ = (off / 60) % 10 + '0'; 182 off %= 60; 183 *q++ = (off / 10) + '0'; 184 *q++ = (off % 10) + '0'; 185 if (tz != NULL && *tz != '\0') 186 { 187 *q++ = ' '; 188 *q++ = '('; |
195 while (*tz != '\0' && q < &b[sizeof(b) - 3]) | 189 while (*tz != '\0' && q < &b[sizeof b - 3]) |
196 *q++ = *tz++; 197 *q++ = ')'; 198 } 199 } 200 *q = '\0'; 201 | 190 *q++ = *tz++; 191 *q++ = ')'; 192 } 193 } 194 *q = '\0'; 195 |
202 return b; | 196 return (b); |
203} | 197} |