Browse Source

Add os_gmtime() as wrapper for gmtime()

Jouni Malinen 13 years ago
parent
commit
96b2cb226a
5 changed files with 72 additions and 0 deletions
  1. 10 0
      src/utils/os.h
  2. 19 0
      src/utils/os_internal.c
  3. 5 0
      src/utils/os_none.c
  4. 19 0
      src/utils/os_unix.c
  5. 19 0
      src/utils/os_win32.c

+ 10 - 0
src/utils/os.h

@@ -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,
 	      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)

+ 19 - 0
src/utils/os_internal.c

@@ -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)
 {
 	if (daemon(0, 0)) {

+ 5 - 0
src/utils/os_none.c

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

+ 19 - 0
src/utils/os_unix.c

@@ -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__
 #include <fcntl.h>
 static int os_daemon(int nochdir, int noclose)

+ 19 - 0
src/utils/os_win32.c

@@ -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)
 {
 	/* TODO */