diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2018-10-03 09:10:00 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2018-10-06 23:31:03 -0700 |
commit | b5d08da1e9ea7ee1334d810348c656babe6a15d2 (patch) | |
tree | e42a93a11f341db5cde167332790ebf9ad717525 /src/sysdep.c | |
parent | 44bf4a6b012f65327718b8c8334bfac1aee26370 (diff) | |
download | emacs-b5d08da1e9ea7ee1334d810348c656babe6a15d2.tar.gz |
Move timestamp-related stuff to timefns.c
This does not change behavior; it’s just long-overdue
refactoring (Bug#32902).
* src/emacs.c (main): Call init_timefns, syms_of_timefns.
* src/timefns.c: New file, containing timestamp-related stuff
from editfns.c and sysdep.c.
* src/Makefile.in (base_obj): Add timefns.o.
* src/editfns.c: Simplify by moving a big chunk to timefns.c.
Do not include systime.h, sys/resource.h, sys/param.h,
strftime.h, coding.h.
(HAVE_TZALLOC_BUG, TM_YEAR_BASE, HAVE_TM_GMTOFF, tzeqlen)
(local_tz, utc_tz, emacs_localtime_rz, emacs_mktime_z)
(invalid_time_zone_specification, xtzfree, tzlookup)
(TIME_T_MIN, TIME_T_MAX, time_overflow, invalid_time)
(check_time_validity, hi_time, lo_time, Fcurrent_time)
(time_add, time_subtract, time_arith, Ftime_add)
(Ftime_subtract, Ftime_less_p, Fget_internal_run_time)
(make_lisp_time, disassemble_lisp_time, decode_float_time)
(lisp_to_timespec, lisp_time_struct, lisp_time_argument)
(lisp_seconds_argument, Ffloat_time, emacs_nmemftime)
(Fformat_time_string, format_time_string, Fdecode_time)
(check_tm_member, Fencode_time, Fcurrent_time_string)
(tm_gmtoff, Fcurrent_time_zone, Fset_time_zone_rule)
(emacs_getenv_TZ, emacs_setenv_TZ): Move to timefns.c.
* src/emacs.c (main): Adjust to initialization changes.
* src/sysdep.c: Include <sys/resource.h> if it's present.
Regularize includes a bit.
(Fget_internal_run_time): Move here from editfns.c.
(init_timefns, syms_of_timefns): New functions.
* src/w32.h (w32_get_internal_run_time): Move decl here
so that it need not be cloned.
* test/src/editfns-tests.el:
* test/src/editfns-tests.el (format-time-string-with-zone)
(format-time-string-with-outlandish-zone)
(editfns-tests--have-leap-seconds)
(format-time-string-with-bignum-on-32-bit):
Move to ...
* test/src/timefns-tests.el: ... this new file.
Diffstat (limited to 'src/sysdep.c')
-rw-r--r-- | src/sysdep.c | 87 |
1 files changed, 54 insertions, 33 deletions
diff --git a/src/sysdep.c b/src/sysdep.c index 722d8138ded..06956863611 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -91,13 +91,19 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ #include <sys/file.h> #include <fcntl.h> +#include "syssignal.h" +#include "systime.h" #include "systty.h" #include "syswait.h" +#ifdef HAVE_SYS_RESOURCE_H +# include <sys/resource.h> +#endif + #ifdef HAVE_SYS_UTSNAME_H -#include <sys/utsname.h> -#include <memory.h> -#endif /* HAVE_SYS_UTSNAME_H */ +# include <sys/utsname.h> +# include <memory.h> +#endif #include "keyboard.h" #include "frame.h" @@ -118,18 +124,15 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ #endif #ifdef WINDOWSNT -#include <direct.h> +# include <direct.h> /* In process.h which conflicts with the local copy. */ -#define _P_WAIT 0 +# define _P_WAIT 0 int _cdecl _spawnlp (int, const char *, const char *, ...); /* The following is needed for O_CLOEXEC, F_SETFD, FD_CLOEXEC, and several prototypes of functions called below. */ -#include <sys/socket.h> +# include <sys/socket.h> #endif -#include "syssignal.h" -#include "systime.h" - /* ULLONG_MAX is missing on Red Hat Linux 7.3; see Bug#11781. */ #ifndef ULLONG_MAX #define ULLONG_MAX TYPE_MAXIMUM (unsigned long long int) @@ -2704,30 +2707,6 @@ emacs_perror (char const *message) errno = err; } -/* Return a struct timeval that is roughly equivalent to T. - Use the least timeval not less than T. - Return an extremal value if the result would overflow. */ -struct timeval -make_timeval (struct timespec t) -{ - struct timeval tv; - tv.tv_sec = t.tv_sec; - tv.tv_usec = t.tv_nsec / 1000; - - if (t.tv_nsec % 1000 != 0) - { - if (tv.tv_usec < 999999) - tv.tv_usec++; - else if (tv.tv_sec < TYPE_MAXIMUM (time_t)) - { - tv.tv_sec++; - tv.tv_usec = 0; - } - } - - return tv; -} - /* Set the access and modification time stamps of FD (a.k.a. FILE) to be ATIME and MTIME, respectively. FD must be either negative -- in which case it is ignored -- @@ -3911,6 +3890,42 @@ system_process_attributes (Lisp_Object pid) } #endif /* !defined (WINDOWSNT) */ + +DEFUN ("get-internal-run-time", Fget_internal_run_time, Sget_internal_run_time, + 0, 0, 0, + doc: /* Return the current run time used by Emacs. +The time is returned as in the style of `current-time'. + +On systems that can't determine the run time, `get-internal-run-time' +does the same thing as `current-time'. */) + (void) +{ +#ifdef HAVE_GETRUSAGE + struct rusage usage; + time_t secs; + int usecs; + + if (getrusage (RUSAGE_SELF, &usage) < 0) + /* This shouldn't happen. What action is appropriate? */ + xsignal0 (Qerror); + + /* Sum up user time and system time. */ + secs = usage.ru_utime.tv_sec + usage.ru_stime.tv_sec; + usecs = usage.ru_utime.tv_usec + usage.ru_stime.tv_usec; + if (usecs >= 1000000) + { + usecs -= 1000000; + secs++; + } + return make_lisp_time (make_timespec (secs, usecs * 1000)); +#else /* ! HAVE_GETRUSAGE */ +#ifdef WINDOWSNT + return w32_get_internal_run_time (); +#else /* ! WINDOWSNT */ + return Fcurrent_time (); +#endif /* WINDOWSNT */ +#endif /* HAVE_GETRUSAGE */ +} /* Wide character string collation. */ @@ -4116,3 +4131,9 @@ str_collate (Lisp_Object s1, Lisp_Object s2, return res; } #endif /* WINDOWSNT */ + +void +syms_of_sysdep (void) +{ + defsubr (&Sget_internal_run_time); +} |