Simplify EMACS_TIME-related code.
[bpt/emacs.git] / src / editfns.c
index bbaeaea..9e36655 100644 (file)
@@ -64,7 +64,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 extern Lisp_Object w32_get_internal_run_time (void);
 #endif
 
-static Lisp_Object format_time_string (char const *, ptrdiff_t, EMACS_TIME,
+static Lisp_Object format_time_string (char const *, ptrdiff_t, struct timespec,
                                       bool, struct tm *);
 static int tm_diff (struct tm *, struct tm *);
 static void update_buffer_properties (ptrdiff_t, ptrdiff_t);
@@ -1420,7 +1420,7 @@ least significant 16 bits.  USEC and PSEC are the microsecond and
 picosecond counts.  */)
   (void)
 {
-  return make_lisp_time (current_emacs_time ());
+  return make_lisp_time (current_timespec ());
 }
 
 DEFUN ("get-internal-run-time", Fget_internal_run_time, Sget_internal_run_time,
@@ -1450,7 +1450,7 @@ does the same thing as `current-time'.  */)
       usecs -= 1000000;
       secs++;
     }
-  return make_lisp_time (make_emacs_time (secs, usecs * 1000));
+  return make_lisp_time (make_timespec (secs, usecs * 1000));
 #else /* ! HAVE_GETRUSAGE  */
 #ifdef WINDOWSNT
   return w32_get_internal_run_time ();
@@ -1481,10 +1481,10 @@ make_time (time_t t)
    UNKNOWN_MODTIME_NSECS; in that case, the Lisp list contains a
    correspondingly negative picosecond count.  */
 Lisp_Object
-make_lisp_time (EMACS_TIME t)
+make_lisp_time (struct timespec t)
 {
-  int ns = EMACS_NSECS (t);
-  return make_time_tail (EMACS_SECS (t), list2i (ns / 1000, ns % 1000 * 1000));
+  int ns = t.tv_nsec;
+  return make_time_tail (t.tv_sec, list2i (ns / 1000, ns % 1000 * 1000));
 }
 
 /* Decode a Lisp list SPECIFIED_TIME that represents a time.
@@ -1529,7 +1529,7 @@ disassemble_lisp_time (Lisp_Object specified_time, Lisp_Object *phigh,
    list, generate the corresponding time value.
 
    If RESULT is not null, store into *RESULT the converted time;
-   this can fail if the converted time does not fit into EMACS_TIME.
+   this can fail if the converted time does not fit into struct timespec.
    If *DRESULT is not null, store into *DRESULT the number of
    seconds since the start of the POSIX Epoch.
 
@@ -1537,7 +1537,7 @@ disassemble_lisp_time (Lisp_Object specified_time, Lisp_Object *phigh,
 bool
 decode_time_components (Lisp_Object high, Lisp_Object low, Lisp_Object usec,
                        Lisp_Object psec,
-                       EMACS_TIME *result, double *dresult)
+                       struct timespec *result, double *dresult)
 {
   EMACS_INT hi, lo, us, ps;
   if (! (INTEGERP (high) && INTEGERP (low)
@@ -1565,7 +1565,7 @@ decode_time_components (Lisp_Object high, Lisp_Object low, Lisp_Object usec,
          /* Return the greatest representable time that is not greater
             than the requested time.  */
          time_t sec = hi;
-         *result = make_emacs_time ((sec << 16) + lo, us * 1000 + ps / 1000);
+         *result = make_timespec ((sec << 16) + lo, us * 1000 + ps / 1000);
        }
       else
        {
@@ -1583,15 +1583,15 @@ decode_time_components (Lisp_Object high, Lisp_Object low, Lisp_Object usec,
 /* Decode a Lisp list SPECIFIED_TIME that represents a time.
    If SPECIFIED_TIME is nil, use the current time.
 
-   Round the time down to the nearest EMACS_TIME value.
+   Round the time down to the nearest struct timespec value.
    Return seconds since the Epoch.
    Signal an error if unsuccessful.  */
-EMACS_TIME
+struct timespec
 lisp_time_argument (Lisp_Object specified_time)
 {
-  EMACS_TIME t;
+  struct timespec t;
   if (NILP (specified_time))
-    t = current_emacs_time ();
+    t = current_timespec ();
   else
     {
       Lisp_Object high, low, usec, psec;
@@ -1613,12 +1613,12 @@ lisp_seconds_argument (Lisp_Object specified_time)
   else
     {
       Lisp_Object high, low, usec, psec;
-      EMACS_TIME t;
+      struct timespec t;
       if (! (disassemble_lisp_time (specified_time, &high, &low, &usec, &psec)
             && decode_time_components (high, low, make_number (0),
                                        make_number (0), &t, 0)))
        error ("Invalid time specification");
-      return EMACS_SECS (t);
+      return t.tv_sec;
     }
 }
 
@@ -1639,8 +1639,8 @@ or (if you need time as a string) `format-time-string'.  */)
   double t;
   if (NILP (specified_time))
     {
-      EMACS_TIME now = current_emacs_time ();
-      t = EMACS_SECS (now) + EMACS_NSECS (now) / 1e9;
+      struct timespec now = current_timespec ();
+      t = now.tv_sec + now.tv_nsec / 1e9;
     }
   else
     {
@@ -1758,7 +1758,7 @@ For example, to produce full ISO 8601 format, use "%Y-%m-%dT%T%z".
 usage: (format-time-string FORMAT-STRING &optional TIME UNIVERSAL)  */)
   (Lisp_Object format_string, Lisp_Object timeval, Lisp_Object universal)
 {
-  EMACS_TIME t = lisp_time_argument (timeval);
+  struct timespec t = lisp_time_argument (timeval);
   struct tm tm;
 
   CHECK_STRING (format_string);
@@ -1770,20 +1770,20 @@ usage: (format-time-string FORMAT-STRING &optional TIME UNIVERSAL)  */)
 
 static Lisp_Object
 format_time_string (char const *format, ptrdiff_t formatlen,
-                   EMACS_TIME t, bool ut, struct tm *tmp)
+                   struct timespec t, bool ut, struct tm *tmp)
 {
   char buffer[4000];
   char *buf = buffer;
   ptrdiff_t size = sizeof buffer;
   size_t len;
   Lisp_Object bufstring;
-  int ns = EMACS_NSECS (t);
+  int ns = t.tv_nsec;
   struct tm *tm;
   USE_SAFE_ALLOCA;
 
   while (1)
     {
-      time_t *taddr = emacs_secs_addr (&t);
+      time_t *taddr = &t.tv_sec;
       block_input ();
 
       synchronize_system_time_locale ();
@@ -2068,17 +2068,17 @@ in this case, `current-time-zone' returns a list containing nil for
 the data it can't find.  */)
   (Lisp_Object specified_time)
 {
-  EMACS_TIME value;
+  struct timespec value;
   int offset;
   struct tm *t;
   struct tm localtm;
   Lisp_Object zone_offset, zone_name;
 
   zone_offset = Qnil;
-  value = make_emacs_time (lisp_seconds_argument (specified_time), 0);
+  value = make_timespec (lisp_seconds_argument (specified_time), 0);
   zone_name = format_time_string ("%Z", sizeof "%Z" - 1, value, 0, &localtm);
   block_input ();
-  t = gmtime (emacs_secs_addr (&value));
+  t = gmtime (&value.tv_sec);
   if (t)
     offset = tm_diff (&localtm, t);
   unblock_input ();