common: Avoid warning about implicit declaration of gnupg_fd_valid.
[gnupg.git] / common / gettime.c
index dd9c196..3e1ee55 100644 (file)
@@ -24,7 +24,7 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ * along with this program; if not, see <https://www.gnu.org/licenses/>.
  */
 
 #include <config.h>
@@ -60,6 +60,9 @@ time_t
 gnupg_get_time ()
 {
   time_t current = time (NULL);
+  if (current == (time_t)(-1))
+    log_fatal ("time() failed\n");
+
   if (timemode == NORMAL)
     return current;
   else if (timemode == FROZEN)
@@ -99,22 +102,16 @@ void
 gnupg_get_isotime (gnupg_isotime_t timebuf)
 {
   time_t atime = gnupg_get_time ();
+  struct tm *tp;
+  struct tm tmbuf;
 
-  if (atime == (time_t)(-1))
+  tp = gnupg_gmtime (&atime, &tmbuf);
+  if (!tp)
     *timebuf = 0;
   else
-    {
-      struct tm *tp;
-      struct tm tmbuf;
-
-      tp = gnupg_gmtime (&atime, &tmbuf);
-      if (!tp)
-        *timebuf = 0;
-      else
-        snprintf (timebuf, 16, "%04d%02d%02dT%02d%02d%02d",
-                  1900 + tp->tm_year, tp->tm_mon+1, tp->tm_mday,
-                  tp->tm_hour, tp->tm_min, tp->tm_sec);
-    }
+    snprintf (timebuf, 16, "%04d%02d%02dT%02d%02d%02d",
+              1900 + tp->tm_year, tp->tm_mon+1, tp->tm_mday,
+              tp->tm_hour, tp->tm_min, tp->tm_sec);
 }
 
 
@@ -136,7 +133,7 @@ gnupg_set_time (time_t newtime, int freeze)
   else if (freeze)
     {
       timemode = FROZEN;
-      timewarp = current;
+      timewarp = newtime == (time_t)-1 ? current : newtime;
     }
   else if (newtime > current)
     {
@@ -164,9 +161,6 @@ u32
 make_timestamp (void)
 {
   time_t t = gnupg_get_time ();
-
-  if (t == (time_t)-1)
-    log_fatal ("gnupg_get_time() failed\n");
   return (u32)t;
 }
 
@@ -746,10 +740,10 @@ rfctimestamp (u32 stamp)
   if (!tp)
     return NULL;
   return xtryasprintf ("%.3s, %02d %.3s %04d %02d:%02d:%02d +0000",
-                       ("SunMonTueWedThuFriSat" + (tp->tm_wday%7)*3),
+                       &"SunMonTueWedThuFriSat"[(tp->tm_wday%7)*3],
                        tp->tm_mday,
-                       ("JanFebMarAprMayJunJulAugSepOctNovDec"
-                        + (tp->tm_mon%12)*3),
+                       &"JanFebMarAprMayJunJulAugSepOctNovDec"
+                       [(tp->tm_mon%12)*3],
                        tp->tm_year + 1900,
                        tp->tm_hour,
                        tp->tm_min,