Add win32 directory (for compatibility)

This commit is contained in:
Grégory Soutadé 2012-02-29 20:58:30 +01:00
parent 1aa4de222f
commit bb1df8296b
2 changed files with 86 additions and 0 deletions

34
src/win32/compat.hpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef COMPAT_H
#define COMPAT_H
#ifdef WIN32
#include <stdlib.h>
#include <time.h>
#include <string.h>
struct tm *localtime_r (const time_t *, struct tm *);
struct tm *gmtime_r (const time_t *, struct tm *);
#endif
#endif

52
src/win32/gmtime_r.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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