diff --git a/src/win32/compat.hpp b/src/win32/compat.hpp new file mode 100644 index 0000000..8457617 --- /dev/null +++ b/src/win32/compat.hpp @@ -0,0 +1,34 @@ +/* + Copyright 2010-2012 Grégory Soutadé + + This file is part of KissCount. + + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . +*/ + +#ifndef COMPAT_H +#define COMPAT_H + +#ifdef WIN32 + +#include +#include +#include + +struct tm *localtime_r (const time_t *, struct tm *); +struct tm *gmtime_r (const time_t *, struct tm *); + +#endif + +#endif diff --git a/src/win32/gmtime_r.cpp b/src/win32/gmtime_r.cpp new file mode 100644 index 0000000..15f3395 --- /dev/null +++ b/src/win32/gmtime_r.cpp @@ -0,0 +1,52 @@ +/* + Copyright 2010-2012 Grégory Soutadé + + This file is part of KissCount. + + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . +*/ + + +#ifdef WIN32 + +#include "compat.hpp" + +// From http://old.nabble.com/Porting-localtime_r-and-gmtime_r-td15282276.html +struct tm * +localtime_r (const time_t *timer, struct tm *result) +{ + struct tm *local_result; + local_result = localtime (timer); + + if (local_result == NULL || result == NULL) + return NULL; + + memcpy (result, local_result, sizeof (result)); + return result; +} + +struct tm * +gmtime_r (const time_t *timer, struct tm *result) +{ + struct tm *local_result; + local_result = gmtime (timer); + + if (local_result == NULL || result == NULL) + return NULL; + + memcpy (result, local_result, sizeof (result)); + return result; +} + +#endif