From dfa8fb919d257a5c1b1006d2f32483242579f02a Mon Sep 17 00:00:00 2001 From: Matthew Blue Date: Sat, 19 May 2018 11:30:46 -0400 Subject: [PATCH] sys/timex: fix incompatible atmega time.h --- cpu/atmega_common/include/vendor/time.h | 6 ++++++ sys/include/tm.h | 4 ++++ sys/timex/tm.c | 4 ++++ tests/struct_tm_utility/main.c | 6 ++++++ 4 files changed, 20 insertions(+) diff --git a/cpu/atmega_common/include/vendor/time.h b/cpu/atmega_common/include/vendor/time.h index 64b0d891af..cd1ed88c03 100644 --- a/cpu/atmega_common/include/vendor/time.h +++ b/cpu/atmega_common/include/vendor/time.h @@ -153,6 +153,12 @@ extern "C" { int16_t tm_isdst; /**< Daylight Saving Time flag */ }; + /** + ATmega compatibility problem define + NOTE: Added for RIOT compatibility + */ +#define ATMEGA_INCOMPATIBLE_TIME_H + #ifndef __DOXYGEN__ /* We have to provide clock_t / CLOCKS_PER_SEC so that libstdc++-v3 can be built. We define CLOCKS_PER_SEC via a symbol _CLOCKS_PER_SEC_ diff --git a/sys/include/tm.h b/sys/include/tm.h index d2a195de28..ab954d529c 100644 --- a/sys/include/tm.h +++ b/sys/include/tm.h @@ -84,7 +84,11 @@ int tm_doomsday(int year) CONST; * @param[out] wday Returns the day of the week. * @param[out] yday Returns the day of the year (Jan 1st is 0). */ +#ifndef ATMEGA_INCOMPATIBLE_TIME_H void tm_get_wyday(int year, int mon, int mday, int *wday, int *yday); +#else +void tm_get_wyday(int year, int mon, int mday, int8_t *wday, int16_t *yday); +#endif /** * @brief Fills in `struct tm::tm_wday` and `struct tm::tm_yday` given a date. diff --git a/sys/timex/tm.c b/sys/timex/tm.c index 1b9fe742ab..4efa58b153 100644 --- a/sys/timex/tm.c +++ b/sys/timex/tm.c @@ -49,7 +49,11 @@ int tm_doomsday(int year) return result; } +#ifndef ATMEGA_INCOMPATIBLE_TIME_H void tm_get_wyday(int year, int mon, int mday, int *wday, int *yday) +#else +void tm_get_wyday(int year, int mon, int mday, int8_t *wday, int16_t *yday) +#endif { int is_leap_year = tm_is_leap_year(year); *yday = TM_MON_DAYS_ACCU[mon] + mday + (mon <= TM_MON_FEB ? 0 : is_leap_year) - 1; diff --git a/tests/struct_tm_utility/main.c b/tests/struct_tm_utility/main.c index eb9176a94e..2565688519 100644 --- a/tests/struct_tm_utility/main.c +++ b/tests/struct_tm_utility/main.c @@ -113,7 +113,13 @@ static int cmd_day(int argc, char **argv) puts("The supplied date is invalid, but no error should occur."); } +#ifndef ATMEGA_INCOMPATIBLE_TIME_H int wday, yday; +#else + int8_t wday; + int16_t yday; +#endif + tm_get_wyday(year, mon - 1, day, &wday, &yday); printf("What weekday was %04d-%02d-%02d? The %d(th) day of the year was a %.3s.\n", year, mon, day, yday + 1, DAY_NAMES[wday]);