chiark / gitweb /
Prep v233.7: Make all supportable API functions visible (v233 addition).
[elogind.git] / src / basic / time-util.c
index 397637f53b561e757ec3076fde92f6e29b2a549c..aadd3b7154858d1dbc1346a9ccaf808b32628ca9 100644 (file)
@@ -247,7 +247,7 @@ usec_t timeval_load(const struct timeval *tv) {
 struct timeval *timeval_store(struct timeval *tv, usec_t u) {
         assert(tv);
 
-        if (u == USEC_INFINITY||
+        if (u == USEC_INFINITY ||
             u / USEC_PER_SEC > TIME_T_MAX) {
                 tv->tv_sec = (time_t) -1;
                 tv->tv_usec = (suseconds_t) -1;
@@ -860,31 +860,27 @@ parse_usec:
 
 from_tm:
         x = mktime_or_timegm(&tm, utc);
-        if (x == (time_t) -1)
-                return -EOVERFLOW;
+        if (x < 0)
+                return -EINVAL;
 
         if (weekday >= 0 && tm.tm_wday != weekday)
                 return -EINVAL;
 
-        if (x < 0)
-                ret = 0;
-        else
-                ret = (usec_t) x * USEC_PER_SEC + x_usec;
-
+        ret = (usec_t) x * USEC_PER_SEC + x_usec;
         if (ret > USEC_TIMESTAMP_FORMATTABLE_MAX)
                 return -EINVAL;
 
 finish:
         if (ret + plus < ret) /* overflow? */
-                return -EOVERFLOW;
+                return -EINVAL;
         ret += plus;
         if (ret > USEC_TIMESTAMP_FORMATTABLE_MAX)
                 return -EINVAL;
 
-        if (ret > minus)
+        if (ret >= minus)
                 ret -= minus;
         else
-                ret = 0;
+                return -EINVAL;
 
         *usec = ret;
 
@@ -1311,6 +1307,12 @@ clockid_t clock_boottime_or_monotonic(void) {
 }
 #endif // 0
 
+#if 1 /// let's add a diagnostic push to silence -Wimplicit-fallthrough to elogind
+#  ifdef __GNUC__
+#    pragma GCC diagnostic push
+#    pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
+#  endif // __GNUC__
+#endif // 1
 bool clock_supported(clockid_t clock) {
         struct timespec ts;
 
@@ -1334,6 +1336,11 @@ bool clock_supported(clockid_t clock) {
                 return clock_gettime(clock, &ts) >= 0;
         }
 }
+#if 1 /// end diagnostic push in elogind
+#  ifdef __GNUC__
+#    pragma GCC diagnostic pop
+#  endif // __GNUC__
+#endif // 1
 
 #if 0 /// UNNEEDED by elogind
 int get_timezone(char **tz) {