| 1 | --- a/compat/compat-2.6.32.c |
| 2 | +++ b/compat/compat-2.6.32.c |
| 3 | @@ -117,3 +117,100 @@ void __dev_addr_unsync(struct dev_addr_l |
| 4 | } |
| 5 | EXPORT_SYMBOL_GPL(__dev_addr_unsync); |
| 6 | |
| 7 | +/* |
| 8 | + * Nonzero if YEAR is a leap year (every 4 years, |
| 9 | + * except every 100th isn't, and every 400th is). |
| 10 | + */ |
| 11 | +static int __isleap(long year) |
| 12 | +{ |
| 13 | + return (year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0); |
| 14 | +} |
| 15 | + |
| 16 | +/* do a mathdiv for long type */ |
| 17 | +static long math_div(long a, long b) |
| 18 | +{ |
| 19 | + return a / b - (a % b < 0); |
| 20 | +} |
| 21 | + |
| 22 | +/* How many leap years between y1 and y2, y1 must less or equal to y2 */ |
| 23 | +static long leaps_between(long y1, long y2) |
| 24 | +{ |
| 25 | + long leaps1 = math_div(y1 - 1, 4) - math_div(y1 - 1, 100) |
| 26 | + + math_div(y1 - 1, 400); |
| 27 | + long leaps2 = math_div(y2 - 1, 4) - math_div(y2 - 1, 100) |
| 28 | + + math_div(y2 - 1, 400); |
| 29 | + return leaps2 - leaps1; |
| 30 | +} |
| 31 | + |
| 32 | +/* How many days come before each month (0-12). */ |
| 33 | +static const unsigned short __mon_yday[2][13] = { |
| 34 | + /* Normal years. */ |
| 35 | + {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}, |
| 36 | + /* Leap years. */ |
| 37 | + {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366} |
| 38 | +}; |
| 39 | + |
| 40 | +#define SECS_PER_HOUR (60 * 60) |
| 41 | +#define SECS_PER_DAY (SECS_PER_HOUR * 24) |
| 42 | + |
| 43 | +/** |
| 44 | + * time_to_tm - converts the calendar time to local broken-down time |
| 45 | + * |
| 46 | + * @totalsecs the number of seconds elapsed since 00:00:00 on January 1, 1970, |
| 47 | + * Coordinated Universal Time (UTC). |
| 48 | + * @offset offset seconds adding to totalsecs. |
| 49 | + * @result pointer to struct tm variable to receive broken-down time |
| 50 | + */ |
| 51 | +void time_to_tm(time_t totalsecs, int offset, struct tm *result) |
| 52 | +{ |
| 53 | + long days, rem, y; |
| 54 | + const unsigned short *ip; |
| 55 | + |
| 56 | + days = totalsecs / SECS_PER_DAY; |
| 57 | + rem = totalsecs % SECS_PER_DAY; |
| 58 | + rem += offset; |
| 59 | + while (rem < 0) { |
| 60 | + rem += SECS_PER_DAY; |
| 61 | + --days; |
| 62 | + } |
| 63 | + while (rem >= SECS_PER_DAY) { |
| 64 | + rem -= SECS_PER_DAY; |
| 65 | + ++days; |
| 66 | + } |
| 67 | + |
| 68 | + result->tm_hour = rem / SECS_PER_HOUR; |
| 69 | + rem %= SECS_PER_HOUR; |
| 70 | + result->tm_min = rem / 60; |
| 71 | + result->tm_sec = rem % 60; |
| 72 | + |
| 73 | + /* January 1, 1970 was a Thursday. */ |
| 74 | + result->tm_wday = (4 + days) % 7; |
| 75 | + if (result->tm_wday < 0) |
| 76 | + result->tm_wday += 7; |
| 77 | + |
| 78 | + y = 1970; |
| 79 | + |
| 80 | + while (days < 0 || days >= (__isleap(y) ? 366 : 365)) { |
| 81 | + /* Guess a corrected year, assuming 365 days per year. */ |
| 82 | + long yg = y + math_div(days, 365); |
| 83 | + |
| 84 | + /* Adjust DAYS and Y to match the guessed year. */ |
| 85 | + days -= (yg - y) * 365 + leaps_between(y, yg); |
| 86 | + y = yg; |
| 87 | + } |
| 88 | + |
| 89 | + result->tm_year = y - 1900; |
| 90 | + |
| 91 | + result->tm_yday = days; |
| 92 | + |
| 93 | + ip = __mon_yday[__isleap(y)]; |
| 94 | + for (y = 11; days < ip[y]; y--) |
| 95 | + continue; |
| 96 | + days -= ip[y]; |
| 97 | + |
| 98 | + result->tm_mon = y; |
| 99 | + result->tm_mday = days + 1; |
| 100 | +} |
| 101 | +EXPORT_SYMBOL(time_to_tm); |
| 102 | +/* source: kernel/time/timeconv.c*/ |
| 103 | + |
| 104 | --- a/compat/compat-2.6.39.c |
| 105 | +++ b/compat/compat-2.6.39.c |
| 106 | @@ -10,6 +10,7 @@ |
| 107 | |
| 108 | #include <linux/compat.h> |
| 109 | #include <linux/tty.h> |
| 110 | +#include <linux/sched.h> |
| 111 | |
| 112 | #ifdef CONFIG_COMPAT_BLUETOOTH |
| 113 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)) |
| 114 | --- a/compat/kstrtox.c |
| 115 | +++ b/compat/kstrtox.c |
| 116 | @@ -11,6 +11,14 @@ |
| 117 | * |
| 118 | * If -E is returned, result is not touched. |
| 119 | */ |
| 120 | +#include <linux/kernel.h> |
| 121 | +/* |
| 122 | + * kstrto* was included in kernel 2.6.38.4 and causes conflicts with the |
| 123 | + * version included in compat-wireless. We use strict_strtol to check if |
| 124 | + * kstrto* is already available. |
| 125 | + */ |
| 126 | +#ifndef strict_strtol |
| 127 | + |
| 128 | #include <linux/ctype.h> |
| 129 | #include <linux/errno.h> |
| 130 | #include <linux/kernel.h> |
| 131 | @@ -225,3 +233,4 @@ int kstrtos8(const char *s, unsigned int |
| 132 | return 0; |
| 133 | } |
| 134 | EXPORT_SYMBOL(kstrtos8); |
| 135 | +#endif /* #ifndef strict_strtol */ |
| 136 | --- a/include/linux/compat-2.6.32.h |
| 137 | +++ b/include/linux/compat-2.6.32.h |
| 138 | @@ -96,6 +96,34 @@ struct dev_pm_ops name = { \ |
| 139 | |
| 140 | #define lockdep_assert_held(l) do { } while (0) |
| 141 | |
| 142 | +/* |
| 143 | + * Similar to the struct tm in userspace <time.h>, but it needs to be here so |
| 144 | + * that the kernel source is self contained. |
| 145 | + */ |
| 146 | +struct tm { |
| 147 | + /* |
| 148 | + * the number of seconds after the minute, normally in the range |
| 149 | + * 0 to 59, but can be up to 60 to allow for leap seconds |
| 150 | + */ |
| 151 | + int tm_sec; |
| 152 | + /* the number of minutes after the hour, in the range 0 to 59*/ |
| 153 | + int tm_min; |
| 154 | + /* the number of hours past midnight, in the range 0 to 23 */ |
| 155 | + int tm_hour; |
| 156 | + /* the day of the month, in the range 1 to 31 */ |
| 157 | + int tm_mday; |
| 158 | + /* the number of months since January, in the range 0 to 11 */ |
| 159 | + int tm_mon; |
| 160 | + /* the number of years since 1900 */ |
| 161 | + long tm_year; |
| 162 | + /* the number of days since Sunday, in the range 0 to 6 */ |
| 163 | + int tm_wday; |
| 164 | + /* the number of days since January 1, in the range 0 to 365 */ |
| 165 | + int tm_yday; |
| 166 | +}; |
| 167 | + |
| 168 | +void time_to_tm(time_t totalsecs, int offset, struct tm *result); |
| 169 | + |
| 170 | #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)) */ |
| 171 | |
| 172 | #endif /* LINUX_26_32_COMPAT_H */ |
| 173 | --- a/include/linux/compat-2.6.39.h |
| 174 | +++ b/include/linux/compat-2.6.39.h |
| 175 | @@ -94,6 +94,12 @@ static inline struct msi_desc *irq_desc_ |
| 176 | } |
| 177 | #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29)) */ |
| 178 | |
| 179 | +/* |
| 180 | + * kstrto* was included in kernel 2.6.38.4 and causes conflicts with the |
| 181 | + * version included in compat-wireless. We use strict_strtol to check if |
| 182 | + * kstrto* is already available. |
| 183 | + */ |
| 184 | +#ifndef strict_strtol |
| 185 | /* Internal, do not use. */ |
| 186 | int __must_check _kstrtoul(const char *s, unsigned int base, unsigned long *res); |
| 187 | int __must_check _kstrtol(const char *s, unsigned int base, long *res); |
| 188 | @@ -153,6 +159,7 @@ int __must_check kstrtou16(const char *s |
| 189 | int __must_check kstrtos16(const char *s, unsigned int base, s16 *res); |
| 190 | int __must_check kstrtou8(const char *s, unsigned int base, u8 *res); |
| 191 | int __must_check kstrtos8(const char *s, unsigned int base, s8 *res); |
| 192 | +#endif /* ifndef strict_strtol */ |
| 193 | |
| 194 | #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39)) */ |
| 195 | |
| 196 | |