ia64/xen-unstable

changeset 19638:9535ef2be909

minios: replace mktime implementation

In the efforts to clarify MiniOS license it came to my attention that
few portions of MiniOS were taken from other GPL projects, one of them
is the mktime implementation. This patch replaces the current GPL
licensed mktime implementation with a different and BSD licensed
version.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue May 26 09:54:53 2009 +0100 (2009-05-26)
parents 97f2e7c576ab
children 205b1badbcfd
files extras/mini-os/arch/ia64/time.c
line diff
     1.1 --- a/extras/mini-os/arch/ia64/time.c	Tue May 26 09:52:59 2009 +0100
     1.2 +++ b/extras/mini-os/arch/ia64/time.c	Tue May 26 09:54:53 2009 +0100
     1.3 @@ -1,26 +1,9 @@
     1.4  /* 
     1.5   * Done by Dietmar Hahn <dietmar.hahn@fujitsu-siemens.com>
     1.6   * Description: simple ia64 specific time handling
     1.7 - * mktime() is taken from Linux (see copyright below)
     1.8   * Parts are taken from FreeBSD.
     1.9   *
    1.10   ****************************************************************************
    1.11 - * For the copy of the mktime() from linux.
    1.12 - * This program is free software; you can redistribute it and/or modify
    1.13 - * it under the terms of the GNU General Public License as published by
    1.14 - * the Free Software Foundation; either version 2 of the License, or
    1.15 - * (at your option) any later version.
    1.16 - *
    1.17 - * This program is distributed in the hope that it will be useful,
    1.18 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.19 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.20 - * GNU General Public License for more details.
    1.21 - *
    1.22 - * You should have received a copy of the GNU General Public License
    1.23 - * along with this program; if not, write to the Free Software
    1.24 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.25 - *
    1.26 - ****************************************************************************
    1.27   *
    1.28   * Redistribution and use in source and binary forms, with or without
    1.29   * modification, are permitted provided that the following conditions
    1.30 @@ -57,6 +40,49 @@ static uint64_t itc_frequency;
    1.31  static uint64_t processor_frequency;
    1.32  static uint64_t itm_val;
    1.33  
    1.34 +static int is_leap_year(int year)
    1.35 +{
    1.36 +	if( year % 4 == 0 )
    1.37 +	{
    1.38 +		if( year % 100 == 0 )
    1.39 +		{
    1.40 +			if( year % 400 == 0 ) return 1;
    1.41 +			else return 0;
    1.42 +		}
    1.43 +		return 1;
    1.44 +	}
    1.45 +	return 0;
    1.46 +}
    1.47 +
    1.48 +static int count_leap_years(int epoch, int year)
    1.49 +{
    1.50 +	int i, result = 0;
    1.51 +	for( i = epoch ; i < year ; i++ ) if( is_leap_year(i) ) result++;
    1.52 +	return result;
    1.53 +}
    1.54 +
    1.55 +static int get_day(int year, int mon, int day) {
    1.56 +	int result;
    1.57 +	switch(mon)
    1.58 +	{
    1.59 +		case 0: result = 0; break;
    1.60 +		case 1: result = 31; break; /* 1: 31 */
    1.61 +		case 2: result = 59; break; /* 2: 31+28 */
    1.62 +		case 3: result = 90; break; /* 3: 59+31 */
    1.63 +		case 4: result = 120;break; /* 4: 90+30 */
    1.64 +		case 5: result = 151;break; /* 5: 120+31 */
    1.65 +		case 6: result = 181;break; /* 6: 151+30 */
    1.66 +		case 7: result = 212;break; /* 7: 181+31 */
    1.67 +		case 8: result = 243;break; /* 8: 212+31 */
    1.68 +		case 9: result = 273;break; /* 9: 243+30 */
    1.69 +		case 10:result = 304;break; /* 10:273+31 */
    1.70 +		case 11:result = 334;break; /* 11:304+30 */
    1.71 +		default: break;
    1.72 +	}
    1.73 +	if( is_leap_year(year) && mon > 2 ) result++;
    1.74 +	result += day - 1;
    1.75 +	return result;
    1.76 +}
    1.77  
    1.78  /*
    1.79   * mktime() is take from Linux. See copyright above.
    1.80 @@ -64,38 +90,24 @@ static uint64_t itm_val;
    1.81   * Assumes input in normal date format, i.e. 1980-12-31 23:59:59
    1.82   * => year=1980, mon=12, day=31, hour=23, min=59, sec=59.
    1.83   *
    1.84 - * [For the Julian calendar (which was used in Russia before 1917,
    1.85 - * Britain & colonies before 1752, anywhere else before 1582,
    1.86 - * and is still in use by some communities) leave out the
    1.87 - * -year/100+year/400 terms, and add 10.]
    1.88 - *
    1.89 - * This algorithm was first published by Gauss (I think).
    1.90 - *
    1.91   * WARNING: this function will overflow on 2106-02-07 06:28:16 on
    1.92   * machines were long is 32-bit! (However, as time_t is signed, we
    1.93   * will already get problems at other places on 2038-01-19 03:14:08)
    1.94   */
    1.95 -static unsigned long
    1.96 -_mktime(const unsigned int year0, const unsigned int mon0,
    1.97 -       const unsigned int day, const unsigned int hour,
    1.98 -       const unsigned int min, const unsigned int sec)
    1.99 +static unsigned long _mktime(const unsigned int year, const unsigned int mon,
   1.100 +			    const unsigned int day, const unsigned int hour,
   1.101 +		            const unsigned int min, const unsigned int sec)
   1.102  {
   1.103 -	unsigned int mon = mon0, year = year0;
   1.104 +	unsigned long result = 0;
   1.105  
   1.106 -	/* 1..12 -> 11,12,1..10 */
   1.107 -	if (0 >= (int) (mon -= 2)) {
   1.108 -		mon += 12;	/* Puts Feb last since it has leap day */
   1.109 -		year -= 1;
   1.110 -	}
   1.111 +	result = sec;
   1.112 +	result += min * 60;
   1.113 +	result += hour * 3600;
   1.114 +	result += get_day(year, mon - 1, day) * 86400;
   1.115 +	result += (year - 1970) * 31536000;
   1.116 +	result += count_leap_years(1970, year) * 86400;
   1.117  
   1.118 -	return (
   1.119 -		(
   1.120 -		 ((unsigned long)
   1.121 -		  (year/4 - year/100 + year/400 + 367*mon/12 + day) +
   1.122 -		   year*365 - 719499
   1.123 -		 ) * 24 + hour /* now have hours */
   1.124 -		) * 60 + min /* now have minutes */
   1.125 -	       ) * 60 + sec; /* finally seconds */
   1.126 +	return result;
   1.127  }
   1.128  
   1.129  static inline uint64_t