home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / elm / elm2.4 / lib / getarpdate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-08  |  4.7 KB  |  191 lines

  1. static char rcsid[] = "@(#)$Id: getarpdate.c,v 5.8 1993/05/08 19:22:46 syd Exp $";
  2.  
  3. /*******************************************************************************
  4.  *  The Elm Mail System  -  $Revision: 5.8 $   $State: Exp $
  5.  *
  6.  *            Copyright (c) 1988-1992 USENET Community Trust
  7.  *            Copyright (c) 1986,1987 Dave Taylor
  8.  *******************************************************************************
  9.  * Bug reports, patches, comments, suggestions should be sent to:
  10.  *
  11.  *    Syd Weinstein, Elm Coordinator
  12.  *    elm@DSI.COM            dsinc!elm
  13.  *
  14.  *******************************************************************************
  15.  * $Log: getarpdate.c,v $
  16.  * Revision 5.8  1993/05/08  19:22:46  syd
  17.  * On the DEC Alpha, OSF/1 the following change made things happy.
  18.  * From: dave@opus.csd.uwm.edu (Dave Rasmussen)
  19.  *
  20.  * Revision 5.7  1993/04/21  01:45:39  syd
  21.  * Try and get getarpdate to work on AIX
  22.  * From: "William F. Pemberton" <wfp5p@holmes.acc.virginia.edu>
  23.  *
  24.  * Revision 5.6  1993/04/16  03:42:38  syd
  25.  * As per "William F. Pemberton" <wfp5p@holmes.acc.virginia.edu>
  26.  * IBMs have the date already adjusted for dst in the min decode
  27.  * From: Syd
  28.  *
  29.  * Revision 5.5  1992/12/12  01:29:26  syd
  30.  * Fix double inclusion of sys/types.h
  31.  * From: Tom Moore <tmoore@wnas.DaytonOH.NCR.COM>
  32.  *
  33.  * Revision 5.4  1992/11/15  02:18:15  syd
  34.  * Change most of the rest of the BSDs to TZNAME
  35.  * From: Syd
  36.  *
  37.  * Revision 5.3  1992/11/15  02:10:58  syd
  38.  * change tzname ifdef from ndefBSD to ifdef TZNAME on its own
  39.  * configure variable
  40.  * From: Syd
  41.  *
  42.  * Revision 5.2  1992/11/07  19:27:30  syd
  43.  * Symbol change for AIX370
  44.  * From: uri@watson.ibm.com
  45.  *
  46.  * Revision 5.1  1992/10/03  22:41:36  syd
  47.  * Initial checkin as of 2.4 Release at PL0
  48.  *
  49.  *
  50.  ******************************************************************************/
  51.  
  52. /** 
  53.  
  54. **/
  55.  
  56. #include "headers.h"
  57.  
  58. #ifdef I_TIME
  59. #  include <time.h>
  60. #endif
  61. #ifdef I_SYSTIME
  62. #  include <sys/time.h>
  63. #endif
  64. #ifdef BSD
  65. #  include <sys/timeb.h>
  66. #endif
  67.  
  68. #include <ctype.h>
  69.  
  70. #ifndef    _POSIX_SOURCE
  71. extern struct tm *localtime();
  72. extern struct tm *gmtime();
  73. extern time_t      time();
  74. #endif
  75.  
  76. static char *arpa_dayname[] = { "Sun", "Mon", "Tue", "Wed", "Thu",
  77.           "Fri", "Sat", "" };
  78.  
  79. static char *arpa_monname[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  80.           "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", ""};
  81.  
  82. #ifdef TZNAME
  83.   extern char *tzname[];
  84. #else
  85.   char *timezone();
  86. #endif
  87.  
  88. #ifdef _AIX370
  89. #undef ALTCHECK
  90. #endif /* _AIX370 */
  91.  
  92. char *
  93. get_arpa_date()
  94. {
  95.     /** returns an ARPA standard date.  The format for the date
  96.         according to DARPA document RFC-822 is exemplified by;
  97.  
  98.                      Mon, 12 Aug 85 6:29:08 MST
  99.  
  100.     **/
  101.  
  102.     static char buffer[SLEN];    /* static character buffer       */
  103.     struct tm *the_time;        /* Time structure, see CTIME(3C) */
  104.     time_t       junk;        /* time in seconds....         */
  105.     long       tzmin;        /* number of minutes off gmt      */
  106.     char      *tzsign;        /* + or - gmt              */
  107.  
  108. #if !defined(TZNAME) || defined(_AIX)
  109. # ifndef TZ_MINUTESWEST
  110.     struct timeb    loc_time;
  111.  
  112.     junk = time((time_t *) 0);
  113.     ftime(&loc_time);
  114. # else /* TZ_MINUTESWEST */
  115.     struct  timeval  time_val;        
  116.     struct  timezone time_zone;
  117.  
  118.     gettimeofday(&time_val, &time_zone);
  119.     junk = time_val.tv_sec;
  120. # endif /* TZ_MINUTESWEST */
  121.  
  122. #else /* TZNAME */
  123. # ifndef __osf__
  124.     extern    time_t    timezone;
  125. # endif /* __osf__ */
  126. # ifdef ALTCHECK
  127.     extern    time_t    altzone;
  128. # endif
  129.  
  130.     junk = time((time_t *) 0);    /* this must be here for it to work! */
  131. #endif /* TZNAME */
  132.  
  133.     the_time = localtime(&junk);
  134.     if (the_time->tm_year < 100)
  135.         the_time->tm_year += 1900;
  136. #if !defined(TZNAME) || defined(_AIX)
  137. # ifdef TZ_MINUTESWEST
  138. #  ifndef AIX
  139.     if (the_time->tm_isdst && time_zone.tz_dsttime != DST_NONE)
  140.         tzmin = - (time_zone.tz_minuteswest - 60);
  141.     else
  142. #  endif /* AIX */
  143.         tzmin = - time_zone.tz_minuteswest;
  144. # else /* TZ_MINUTESWEST */
  145.     tzmin = the_time->tm_gmtoff / 60;
  146. # endif /* TZ_MINUTESWEST */
  147. #else /* TZNAME */
  148. # ifdef ALTCHECK
  149.     if (the_time->tm_isdst)
  150.         tzmin = - (altzone / 60);
  151.     else
  152.         tzmin = - (timezone / 60);
  153. # else /* ALTCHECK */
  154.     tzmin = - (timezone / 60);
  155. # endif /* ALTCHECK */
  156. #endif /* TZNAME */
  157.  
  158.     if (tzmin >= 0)
  159.         tzsign = "+";
  160.     else {
  161.         tzsign = "-";
  162.         tzmin = -tzmin;
  163.     }
  164.  
  165.     sprintf(buffer, "%s, %d %s %d %02d:%02d:%02d %s%02d%02d (%s)",
  166.       arpa_dayname[the_time->tm_wday],
  167.       the_time->tm_mday,
  168.       arpa_monname[the_time->tm_mon], the_time->tm_year,
  169.       the_time->tm_hour, the_time->tm_min, the_time->tm_sec,
  170.       tzsign, tzmin / 60, tzmin % 60,
  171. #if !defined(TZNAME) || defined(_AIX)
  172. #ifdef TZ_MINUTESWEST
  173. # ifdef GOULD_NP1
  174.       the_time->tm_zone);
  175. # else
  176. #  ifndef _AIX
  177.       timezone(time_zone.tz_minuteswest, the_time->tm_isdst));
  178. #  else /* AIX has tzname */
  179.       tzname[the_time->tm_isdst]);      
  180. #  endif      
  181. # endif
  182. #else
  183.       timezone(loc_time.timezone, the_time->tm_isdst));
  184. #endif
  185. #else
  186.       tzname[the_time->tm_isdst]);
  187. #endif
  188.     
  189.     return( (char *) buffer);
  190. }
  191.