stoddard    00/01/17 11:42:20

  Added:       src/lib/apr/time/win32 timestr.c
  Log:
  Add timestr to Windows port. We really need a better way to use common files.
  
  Revision  Changes    Path
  1.1                  apache-2.0/src/lib/apr/time/win32/timestr.c
  
  Index: timestr.c
  ===================================================================
  /* ====================================================================
   * Copyright (c) 1999 The Apache Group.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * 4. The names "Apache Server" and "Apache Group" must not be used to
   *    endorse or promote products derived from this software without
   *    prior written permission. For written permission, please contact
   *    [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
   * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Group.
   * For more information on the Apache Group and the Apache HTTP server
   * project, please see <http://www.apache.org/>.
   *
   */
  
  #include "atime.h"
  #include "apr_portable.h"
  
  API_VAR_EXPORT const char ap_month_snames[12][4] =
  {
      "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", 
"Nov", "Dec"
  };
  API_VAR_EXPORT const char ap_day_snames[7][4] =
  {
      "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
  };
  
  ap_status_t ap_rfc822_date(char *date_str, ap_time_t t)
  {
      ap_exploded_time_t xt;
      const char *s;
      int real_year;
  
      ap_explode_gmt(&xt, t);
  
      /* example: "Sat, 08 Jan 2000 18:31:41 GMT" */
      /*           12345678901234567890123456789  */
  
      s = &ap_day_snames[xt.tm_wday][0];
      *date_str++ = *s++;
      *date_str++ = *s++;
      *date_str++ = *s++;
      *date_str++ = ',';
      *date_str++ = ' ';
      *date_str++ = xt.tm_mday / 10 + '0';
      *date_str++ = xt.tm_mday % 10 + '0';
      *date_str++ = ' ';
      s = &ap_month_snames[xt.tm_mon][0];
      *date_str++ = *s++;
      *date_str++ = *s++;
      *date_str++ = *s++;
      *date_str++ = ' ';
      real_year = 1900 + xt.tm_year;
      /* This routine isn't y10k ready. */
      *date_str++ = real_year / 1000 + '0';
      *date_str++ = real_year % 1000 / 100 + '0';
      *date_str++ = real_year % 100 / 10 + '0';
      *date_str++ = real_year % 10 + '0';
      *date_str++ = ' ';
      *date_str++ = xt.tm_hour / 10 + '0';
      *date_str++ = xt.tm_hour % 10 + '0';
      *date_str++ = ':';
      *date_str++ = xt.tm_min / 10 + '0';
      *date_str++ = xt.tm_min % 10 + '0';
      *date_str++ = ':';
      *date_str++ = xt.tm_sec / 10 + '0';
      *date_str++ = xt.tm_sec % 10 + '0';
      *date_str++ = ' ';
      *date_str++ = 'G';
      *date_str++ = 'M';
      *date_str++ = 'T';
      *date_str++ = 0;
      return APR_SUCCESS;
  }
  
  ap_status_t ap_ctime(char *date_str, ap_time_t t)
  {
      ap_exploded_time_t xt;
      const char *s;
      int real_year;
  
      /* example: "Wed Jun 30 21:49:08 1993" */
      /*           123456789012345678901234  */
  
      ap_explode_localtime(&xt, t);
      s = &ap_day_snames[xt.tm_wday][0];
      *date_str++ = *s++;
      *date_str++ = *s++;
      *date_str++ = *s++;
      *date_str++ = ' ';
      s = &ap_month_snames[xt.tm_mon][0];
      *date_str++ = *s++;
      *date_str++ = *s++;
      *date_str++ = *s++;
      *date_str++ = ' ';
      *date_str++ = xt.tm_mday / 10 + '0';
      *date_str++ = xt.tm_mday % 10 + '0';
      *date_str++ = ' ';
      *date_str++ = xt.tm_hour / 10 + '0';
      *date_str++ = xt.tm_hour % 10 + '0';
      *date_str++ = ':';
      *date_str++ = xt.tm_min / 10 + '0';
      *date_str++ = xt.tm_min % 10 + '0';
      *date_str++ = ':';
      *date_str++ = xt.tm_sec / 10 + '0';
      *date_str++ = xt.tm_sec % 10 + '0';
      *date_str++ = ' ';
      real_year = 1900 + xt.tm_year;
      *date_str++ = real_year / 1000 + '0';
      *date_str++ = real_year % 1000 / 100 + '0';
      *date_str++ = real_year % 100 / 10 + '0';
      *date_str++ = real_year % 10 + '0';
      *date_str++ = 0;
  
      return APR_SUCCESS;
  }
  
  ap_status_t ap_strftime(char *s, ap_size_t *retsize, ap_size_t max, 
                          const char *format, ap_exploded_time_t *xt)
  {
      struct tm tm;
      memset(&tm, 0, sizeof(struct tm));
      tm.tm_sec  = xt->tm_sec;
      tm.tm_min  = xt->tm_min;
      tm.tm_hour = xt->tm_hour;
      tm.tm_mday = xt->tm_mday;
      tm.tm_mon  = xt->tm_mon;
      tm.tm_year = xt->tm_year;
      tm.tm_wday = xt->tm_wday;
      tm.tm_yday = xt->tm_yday;
      tm.tm_isdst = xt->tm_isdst;
      (*retsize) = strftime(s, max, format, &tm);
      return APR_SUCCESS;
  }
  
  
  

Reply via email to