home *** CD-ROM | disk | FTP | other *** search
/ ftp.uv.es / 2014.11.ftp.uv.es.tar / ftp.uv.es / pub / unix / elm-2.4-pl20.tar.Z / elm-2.4-pl20.tar / lib / getarpdate.c < prev    next >
C/C++ Source or Header  |  1993-01-12  |  4KB  |  170 lines

  1. static char rcsid[] = "@(#)$Id: getarpdate.c,v 5.5 1992/12/12 01:29:26 syd Exp $";
  2.  
  3. /*******************************************************************************
  4.  *  The Elm Mail System  -  $Revision: 5.5 $   $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.5  1992/12/12  01:29:26  syd
  17.  * Fix double inclusion of sys/types.h
  18.  * From: Tom Moore <tmoore@wnas.DaytonOH.NCR.COM>
  19.  *
  20.  * Revision 5.4  1992/11/15  02:18:15  syd
  21.  * Change most of the rest of the BSDs to TZNAME
  22.  * From: Syd
  23.  *
  24.  * Revision 5.3  1992/11/15  02:10:58  syd
  25.  * change tzname ifdef from ndefBSD to ifdef TZNAME on its own
  26.  * configure variable
  27.  * From: Syd
  28.  *
  29.  * Revision 5.2  1992/11/07  19:27:30  syd
  30.  * Symbol change for AIX370
  31.  * From: uri@watson.ibm.com
  32.  *
  33.  * Revision 5.1  1992/10/03  22:41:36  syd
  34.  * Initial checkin as of 2.4 Release at PL0
  35.  *
  36.  *
  37.  ******************************************************************************/
  38.  
  39. /** 
  40.  
  41. **/
  42.  
  43. #include "headers.h"
  44.  
  45. #ifdef I_TIME
  46. #  include <time.h>
  47. #endif
  48. #ifdef I_SYSTIME
  49. #  include <sys/time.h>
  50. #endif
  51. #ifdef BSD
  52. #  include <sys/timeb.h>
  53. #endif
  54.  
  55. #include <ctype.h>
  56.  
  57. #ifndef    _POSIX_SOURCE
  58. extern struct tm *localtime();
  59. extern struct tm *gmtime();
  60. extern time_t      time();
  61. #endif
  62.  
  63. static char *arpa_dayname[] = { "Sun", "Mon", "Tue", "Wed", "Thu",
  64.           "Fri", "Sat", "" };
  65.  
  66. static char *arpa_monname[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  67.           "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", ""};
  68.  
  69. #ifdef TZNAME
  70.   extern char *tzname[];
  71. #else
  72.   char *timezone();
  73. #endif
  74.  
  75. #ifdef _AIX370
  76. #undef ALTCHECK
  77. #endif /* _AIX370 */
  78.  
  79. char *
  80. get_arpa_date()
  81. {
  82.     /** returns an ARPA standard date.  The format for the date
  83.         according to DARPA document RFC-822 is exemplified by;
  84.  
  85.                      Mon, 12 Aug 85 6:29:08 MST
  86.  
  87.     **/
  88.  
  89.     static char buffer[SLEN];    /* static character buffer       */
  90.     struct tm *the_time;        /* Time structure, see CTIME(3C) */
  91.     time_t       junk;        /* time in seconds....         */
  92.     long       tzmin;        /* number of minutes off gmt      */
  93.     char      *tzsign;        /* + or - gmt              */
  94.  
  95. #ifndef TZNAME
  96. # ifndef TZ_MINUTESWEST
  97.     struct timeb    loc_time;
  98.  
  99.     junk = time((time_t *) 0);
  100.     ftime(&loc_time);
  101. # else /* TZ_MINUTESWEST */
  102.     struct  timeval  time_val;        
  103.     struct  timezone time_zone;
  104.  
  105.     gettimeofday(&time_val, &time_zone);
  106.     junk = time_val.tv_sec;
  107. # endif /* TZ_MINUTESWEST */
  108.  
  109. #else /* TZNAME */
  110.     extern    time_t    timezone;
  111. # ifdef ALTCHECK
  112.     extern    time_t    altzone;
  113. # endif
  114.  
  115.     junk = time((time_t *) 0);    /* this must be here for it to work! */
  116. #endif /* TZNAME */
  117.  
  118.     the_time = localtime(&junk);
  119.     if (the_time->tm_year < 100)
  120.         the_time->tm_year += 1900;
  121. #ifndef TZNAME
  122. # ifdef TZ_MINUTESWEST
  123.     if (the_time->tm_isdst && time_zone.tz_dsttime != DST_NONE)
  124.         tzmin = - (time_zone.tz_minuteswest - 60);
  125.     else
  126.         tzmin = - time_zone.tz_minuteswest;
  127. # else /* TZ_MINUTESWEST */
  128.     tzmin = the_time->tm_gmtoff / 60;
  129. # endif /* TZ_MINUTESWEST */
  130. #else /* TZNAME */
  131. # ifdef ALTCHECK
  132.     if (the_time->tm_isdst)
  133.         tzmin = - (altzone / 60);
  134.     else
  135.         tzmin = - (timezone / 60);
  136. # else /* ALTCHECK */
  137.     tzmin = - (timezone / 60);
  138. # endif /* ALTCHECK */
  139. #endif /* TZNAME */
  140.  
  141.     if (tzmin >= 0)
  142.         tzsign = "+";
  143.     else {
  144.         tzsign = "-";
  145.         tzmin = -tzmin;
  146.     }
  147.  
  148.     sprintf(buffer, "%s, %d %s %d %02d:%02d:%02d %s%02d%02d (%s)",
  149.       arpa_dayname[the_time->tm_wday],
  150.       the_time->tm_mday,
  151.       arpa_monname[the_time->tm_mon], the_time->tm_year,
  152.       the_time->tm_hour, the_time->tm_min, the_time->tm_sec,
  153.       tzsign, tzmin / 60, tzmin % 60,
  154. #ifndef TZNAME
  155. #ifdef TZ_MINUTESWEST
  156. # ifdef GOULD_NP1
  157.       the_time->tm_zone);
  158. # else
  159.       timezone(time_zone.tz_minuteswest, the_time->tm_isdst));
  160. # endif
  161. #else
  162.       timezone(loc_time.timezone, the_time->tm_isdst));
  163. #endif
  164. #else
  165.       tzname[the_time->tm_isdst]);
  166. #endif
  167.     
  168.     return( (char *) buffer);
  169. }
  170.