Add os_gmtime() as wrapper for gmtime()

This commit is contained in:
Jouni Malinen 2011-10-18 00:23:42 +03:00 committed by Jouni Malinen
parent 4b2a77aba2
commit 96b2cb226a
5 changed files with 72 additions and 0 deletions

View file

@ -70,6 +70,16 @@ int os_get_time(struct os_time *t);
int os_mktime(int year, int month, int day, int hour, int min, int sec, int os_mktime(int year, int month, int day, int hour, int min, int sec,
os_time_t *t); os_time_t *t);
struct os_tm {
int sec; /* 0..59 or 60 for leap seconds */
int min; /* 0..59 */
int hour; /* 0..23 */
int day; /* 1..31 */
int month; /* 1..12 */
int year; /* Four digit year */
};
int os_gmtime(os_time_t t, struct os_tm *tm);
/** /**
* os_daemonize - Run in the background (detach from the controlling terminal) * os_daemonize - Run in the background (detach from the controlling terminal)

View file

@ -70,6 +70,25 @@ int os_mktime(int year, int month, int day, int hour, int min, int sec,
} }
int os_gmtime(os_time_t t, struct os_tm *tm)
{
time_t t2;
struct tm *tm2;
t2 = t;
tm2 = gmtime(&t);
if (tm2 == NULL)
return -1;
tm->sec = tm2->tm_sec;
tm->min = tm2->tm_min;
tm->hour = tm2->tm_hour;
tm->day = tm2->tm_mday;
tm->month = tm2->tm_mon + 1;
tm->year = tm2->tm_year + 1900;
return 0;
}
int os_daemonize(const char *pid_file) int os_daemonize(const char *pid_file)
{ {
if (daemon(0, 0)) { if (daemon(0, 0)) {

View file

@ -38,6 +38,11 @@ int os_mktime(int year, int month, int day, int hour, int min, int sec,
return -1; return -1;
} }
int os_gmtime(os_time_t t, struct os_tm *tm)
{
return -1;
}
int os_daemonize(const char *pid_file) int os_daemonize(const char *pid_file)
{ {

View file

@ -106,6 +106,25 @@ int os_mktime(int year, int month, int day, int hour, int min, int sec,
} }
int os_gmtime(os_time_t t, struct os_tm *tm)
{
time_t t2;
struct tm *tm2;
t2 = t;
tm2 = gmtime(&t);
if (tm2 == NULL)
return -1;
tm->sec = tm2->tm_sec;
tm->min = tm2->tm_min;
tm->hour = tm2->tm_hour;
tm->day = tm2->tm_mday;
tm->month = tm2->tm_mon + 1;
tm->year = tm2->tm_year + 1900;
return 0;
}
#ifdef __APPLE__ #ifdef __APPLE__
#include <fcntl.h> #include <fcntl.h>
static int os_daemon(int nochdir, int noclose) static int os_daemon(int nochdir, int noclose)

View file

@ -92,6 +92,25 @@ int os_mktime(int year, int month, int day, int hour, int min, int sec,
} }
int os_gmtime(os_time_t t, struct os_tm *tm)
{
time_t t2;
struct tm *tm2;
t2 = t;
tm2 = gmtime(&t);
if (tm2 == NULL)
return -1;
tm->sec = tm2->tm_sec;
tm->min = tm2->tm_min;
tm->hour = tm2->tm_hour;
tm->day = tm2->tm_mday;
tm->month = tm2->tm_mon + 1;
tm->year = tm2->tm_year + 1900;
return 0;
}
int os_daemonize(const char *pid_file) int os_daemonize(const char *pid_file)
{ {
/* TODO */ /* TODO */