]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
added boost timegm impl for cross platform support 5609/head
authorRohan Mars <code@rohanmars.com>
Wed, 19 Aug 2015 16:07:28 +0000 (09:07 -0700)
committerRohan Mars <code@rohanmars.com>
Tue, 25 Aug 2015 17:01:03 +0000 (10:01 -0700)
Signed-off-by: Rohan Mars <code@rohanmars.com>
COPYING
src/include/Makefile.am
src/include/timegm.h [new file with mode: 0644]
src/include/utime.h

diff --git a/COPYING b/COPYING
index 1b88923155cc8678a1aa12831fecd5ee65d73ea7..5efc838319c48d01f580ab8586753fa482108bfb 100644 (file)
--- a/COPYING
+++ b/COPYING
@@ -144,3 +144,8 @@ File: qa/workunits/erasure-code/jquery.js
 Files: qa/workunits/erasure-code/jquery.{flot.categories,flot}.js
   Copyright (c) 2007-2014 IOLA and Ole Laursen.
   Licensed under the MIT license.
+
+Files: src/include/timegm.h
+  Copyright (C) Copyright Howard Hinnant
+  Copyright (C) Copyright 2010-2011 Vicente J. Botet Escriba
+  License: Boost Software License, Version 1.0
index b3ceb24bf1a58b62b4b9c5fe7f92407b018e8cef..f09bad928c24c9bc67032bbb8cf3676ea413d74b 100644 (file)
@@ -112,4 +112,5 @@ noinst_HEADERS += \
        include/memory.h \
        include/rados/memory.h \
        include/unordered_set.h \
-       include/unordered_map.h
+       include/unordered_map.h \
+       include/timegm.h
diff --git a/src/include/timegm.h b/src/include/timegm.h
new file mode 100644 (file)
index 0000000..fb97043
--- /dev/null
@@ -0,0 +1,79 @@
+//  (C) Copyright Howard Hinnant
+//  (C) Copyright 2010-2011 Vicente J. Botet Escriba
+//  Use, modification and distribution are subject to the Boost Software License,
+//  Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+//  http://www.boost.org/LICENSE_1_0.txt).
+
+//===-------------------------- locale ------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// This code was adapted by Vicente from Howard Hinnant's experimental work
+// on chrono i/o to Boost and some functions from libc++/locale to emulate the missing time_get::get()
+
+#ifndef BOOST_CHRONO_IO_TIME_POINT_IO_H
+#define BOOST_CHRONO_IO_TIME_POINT_IO_H
+
+#include <time.h>
+
+static int32_t is_leap(int32_t year) {
+  if(year % 400 == 0)
+    return 1;
+  if(year % 100 == 0)
+    return 0;
+  if(year % 4 == 0)
+    return 1;
+  return 0;
+}
+
+static int32_t days_from_0(int32_t year) {
+  year--;
+  return 365 * year + (year / 400) - (year/100) + (year / 4);
+}
+
+int32_t static days_from_1970(int32_t year) {
+  static const int days_from_0_to_1970 = days_from_0(1970);
+  return days_from_0(year) - days_from_0_to_1970;
+}
+
+static int32_t days_from_1jan(int32_t year,int32_t month,int32_t day) {
+  static const int32_t days[2][12] =
+  {
+    { 0,31,59,90,120,151,181,212,243,273,304,334},
+    { 0,31,60,91,121,152,182,213,244,274,305,335}
+  };
+
+  return days[is_leap(year)][month-1] + day - 1;
+}
+
+static  time_t internal_timegm(tm const *t) {
+  int year = t->tm_year + 1900;
+  int month = t->tm_mon;
+  if(month > 11)
+  {
+    year += month/12;
+    month %= 12;
+  }
+  else if(month < 0)
+  {
+    int years_diff = (-month + 11)/12;
+    year -= years_diff;
+    month+=12 * years_diff;
+  }
+  month++;
+  int day = t->tm_mday;
+  int day_of_year = days_from_1jan(year,month,day);
+  int days_since_epoch = days_from_1970(year) + day_of_year ;
+
+  time_t seconds_in_day = 3600 * 24;
+  time_t result = seconds_in_day * days_since_epoch + 3600 * t->tm_hour + 60 * t->tm_min + t->tm_sec;
+
+  return result;
+}
+
+#endif
index 9f1007be8a7ba848523c853f42ceafeaa75c53d2..30780d1af3937311d6bd7dd5105d852ec2f4ead4 100644 (file)
@@ -21,6 +21,7 @@
 #include <errno.h>
 
 #include "include/types.h"
+#include "include/timegm.h"
 #include "common/strtol.h"
 
 
@@ -291,7 +292,7 @@ public:
         *nsec = (uint64_t)usec * 1000;
       }
     }
-    time_t t = timegm(&tm);
+    time_t t = internal_timegm(&tm);
     if (epoch)
       *epoch = (uint64_t)t;