|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1983 Eric P. Allman ! 3: * Copyright (c) 1988 Regents of the University of California. ! 4: * All rights reserved. ! 5: * ! 6: * Redistribution and use in source and binary forms are permitted provided ! 7: * that: (1) source distributions retain this entire copyright notice and ! 8: * comment, and (2) distributions including binaries display the following ! 9: * acknowledgement: ``This product includes software developed by the ! 10: * University of California, Berkeley and its contributors'' in the ! 11: * documentation or other materials provided with the distribution and in ! 12: * all advertising materials mentioning features or use of this software. ! 13: * Neither the name of the University nor the names of its contributors may ! 14: * be used to endorse or promote products derived from this software without ! 15: * specific prior written permission. ! 16: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED ! 17: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF ! 18: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 19: */ ! 20: ! 21: #ifndef lint ! 22: static char sccsid[] = "@(#)arpadate.c 5.11 (Berkeley) 6/1/90"; ! 23: #endif /* not lint */ ! 24: ! 25: # include "conf.h" ! 26: # include <time.h> ! 27: # include <sys/types.h> ! 28: # include "useful.h" ! 29: ! 30: /* ! 31: ** ARPADATE -- Create date in ARPANET format ! 32: ** ! 33: ** Parameters: ! 34: ** ud -- unix style date string. if NULL, one is created. ! 35: ** ! 36: ** Returns: ! 37: ** pointer to an ARPANET date field ! 38: ** ! 39: ** Side Effects: ! 40: ** none ! 41: ** ! 42: ** WARNING: ! 43: ** date is stored in a local buffer -- subsequent ! 44: ** calls will overwrite. ! 45: ** ! 46: ** Bugs: ! 47: ** Timezone is computed from local time, rather than ! 48: ** from whereever (and whenever) the message was sent. ! 49: ** To do better is very hard. ! 50: ** ! 51: ** Some sites are now inserting the timezone into the ! 52: ** local date. This routine should figure out what ! 53: ** the format is and work appropriately. ! 54: */ ! 55: ! 56: char * ! 57: arpadate(ud) ! 58: register char *ud; ! 59: { ! 60: register char *p; ! 61: register char *q; ! 62: register int off; ! 63: register int i; ! 64: register struct tm *lt; ! 65: time_t t; ! 66: struct tm gmt; ! 67: static char b[40]; ! 68: extern struct tm *localtime(), *gmtime(); ! 69: extern char *ctime(); ! 70: extern time_t time(); ! 71: ! 72: /* ! 73: ** Get current time. ! 74: ** This will be used if a null argument is passed and ! 75: ** to resolve the timezone. ! 76: */ ! 77: ! 78: (void) time(&t); ! 79: if (ud == NULL) ! 80: ud = ctime(&t); ! 81: ! 82: /* ! 83: ** Crack the UNIX date line in a singularly unoriginal way. ! 84: */ ! 85: ! 86: q = b; ! 87: ! 88: p = &ud[0]; /* Mon */ ! 89: *q++ = *p++; ! 90: *q++ = *p++; ! 91: *q++ = *p++; ! 92: *q++ = ','; ! 93: *q++ = ' '; ! 94: ! 95: p = &ud[8]; /* 16 */ ! 96: if (*p == ' ') ! 97: p++; ! 98: else ! 99: *q++ = *p++; ! 100: *q++ = *p++; ! 101: *q++ = ' '; ! 102: ! 103: p = &ud[4]; /* Sep */ ! 104: *q++ = *p++; ! 105: *q++ = *p++; ! 106: *q++ = *p++; ! 107: *q++ = ' '; ! 108: ! 109: p = &ud[22]; /* 79 */ ! 110: *q++ = *p++; ! 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: 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; ! 132: else if (lt->tm_year > gmt.tm_year) ! 133: off += 24 * 60; ! 134: else if (lt->tm_yday < gmt.tm_yday) ! 135: off -= 24 * 60; ! 136: else if (lt->tm_yday > gmt.tm_yday) ! 137: off += 24 * 60; ! 138: ! 139: *q++ = ' '; ! 140: if (off == 0) { ! 141: *q++ = 'G'; ! 142: *q++ = 'M'; ! 143: *q++ = 'T'; ! 144: } else { ! 145: if (off < 0) { ! 146: off = -off; ! 147: *q++ = '-'; ! 148: } else ! 149: *q++ = '+'; ! 150: ! 151: if (off >= 24*60) /* should be impossible */ ! 152: off = 23*60+59; /* if not, insert silly value */ ! 153: ! 154: *q++ = (off / 600) + '0'; ! 155: *q++ = (off / 60) % 10 + '0'; ! 156: off %= 60; ! 157: *q++ = (off / 10) + '0'; ! 158: *q++ = (off % 10) + '0'; ! 159: } ! 160: *q = '\0'; ! 161: ! 162: return (b); ! 163: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.