aboutsummaryrefslogtreecommitdiffstats
path: root/src/sysdep.c
diff options
context:
space:
mode:
authorPaul Eggert2018-10-03 09:10:00 -0700
committerPaul Eggert2018-10-06 23:31:03 -0700
commitb5d08da1e9ea7ee1334d810348c656babe6a15d2 (patch)
treee42a93a11f341db5cde167332790ebf9ad717525 /src/sysdep.c
parent44bf4a6b012f65327718b8c8334bfac1aee26370 (diff)
downloademacs-b5d08da1e9ea7ee1334d810348c656babe6a15d2.tar.gz
emacs-b5d08da1e9ea7ee1334d810348c656babe6a15d2.zip
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.c87
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/>. */
91#include <sys/file.h> 91#include <sys/file.h>
92#include <fcntl.h> 92#include <fcntl.h>
93 93
94#include "syssignal.h"
95#include "systime.h"
94#include "systty.h" 96#include "systty.h"
95#include "syswait.h" 97#include "syswait.h"
96 98
99#ifdef HAVE_SYS_RESOURCE_H
100# include <sys/resource.h>
101#endif
102
97#ifdef HAVE_SYS_UTSNAME_H 103#ifdef HAVE_SYS_UTSNAME_H
98#include <sys/utsname.h> 104# include <sys/utsname.h>
99#include <memory.h> 105# include <memory.h>
100#endif /* HAVE_SYS_UTSNAME_H */ 106#endif
101 107
102#include "keyboard.h" 108#include "keyboard.h"
103#include "frame.h" 109#include "frame.h"
@@ -118,18 +124,15 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
118#endif 124#endif
119 125
120#ifdef WINDOWSNT 126#ifdef WINDOWSNT
121#include <direct.h> 127# include <direct.h>
122/* In process.h which conflicts with the local copy. */ 128/* In process.h which conflicts with the local copy. */
123#define _P_WAIT 0 129# define _P_WAIT 0
124int _cdecl _spawnlp (int, const char *, const char *, ...); 130int _cdecl _spawnlp (int, const char *, const char *, ...);
125/* The following is needed for O_CLOEXEC, F_SETFD, FD_CLOEXEC, and 131/* The following is needed for O_CLOEXEC, F_SETFD, FD_CLOEXEC, and
126 several prototypes of functions called below. */ 132 several prototypes of functions called below. */
127#include <sys/socket.h> 133# include <sys/socket.h>
128#endif 134#endif
129 135
130#include "syssignal.h"
131#include "systime.h"
132
133/* ULLONG_MAX is missing on Red Hat Linux 7.3; see Bug#11781. */ 136/* ULLONG_MAX is missing on Red Hat Linux 7.3; see Bug#11781. */
134#ifndef ULLONG_MAX 137#ifndef ULLONG_MAX
135#define ULLONG_MAX TYPE_MAXIMUM (unsigned long long int) 138#define ULLONG_MAX TYPE_MAXIMUM (unsigned long long int)
@@ -2704,30 +2707,6 @@ emacs_perror (char const *message)
2704 errno = err; 2707 errno = err;
2705} 2708}
2706 2709
2707/* Return a struct timeval that is roughly equivalent to T.
2708 Use the least timeval not less than T.
2709 Return an extremal value if the result would overflow. */
2710struct timeval
2711make_timeval (struct timespec t)
2712{
2713 struct timeval tv;
2714 tv.tv_sec = t.tv_sec;
2715 tv.tv_usec = t.tv_nsec / 1000;
2716
2717 if (t.tv_nsec % 1000 != 0)
2718 {
2719 if (tv.tv_usec < 999999)
2720 tv.tv_usec++;
2721 else if (tv.tv_sec < TYPE_MAXIMUM (time_t))
2722 {
2723 tv.tv_sec++;
2724 tv.tv_usec = 0;
2725 }
2726 }
2727
2728 return tv;
2729}
2730
2731/* Set the access and modification time stamps of FD (a.k.a. FILE) to be 2710/* Set the access and modification time stamps of FD (a.k.a. FILE) to be
2732 ATIME and MTIME, respectively. 2711 ATIME and MTIME, respectively.
2733 FD must be either negative -- in which case it is ignored -- 2712 FD must be either negative -- in which case it is ignored --
@@ -3911,6 +3890,42 @@ system_process_attributes (Lisp_Object pid)
3911} 3890}
3912 3891
3913#endif /* !defined (WINDOWSNT) */ 3892#endif /* !defined (WINDOWSNT) */
3893
3894DEFUN ("get-internal-run-time", Fget_internal_run_time, Sget_internal_run_time,
3895 0, 0, 0,
3896 doc: /* Return the current run time used by Emacs.
3897The time is returned as in the style of `current-time'.
3898
3899On systems that can't determine the run time, `get-internal-run-time'
3900does the same thing as `current-time'. */)
3901 (void)
3902{
3903#ifdef HAVE_GETRUSAGE
3904 struct rusage usage;
3905 time_t secs;
3906 int usecs;
3907
3908 if (getrusage (RUSAGE_SELF, &usage) < 0)
3909 /* This shouldn't happen. What action is appropriate? */
3910 xsignal0 (Qerror);
3911
3912 /* Sum up user time and system time. */
3913 secs = usage.ru_utime.tv_sec + usage.ru_stime.tv_sec;
3914 usecs = usage.ru_utime.tv_usec + usage.ru_stime.tv_usec;
3915 if (usecs >= 1000000)
3916 {
3917 usecs -= 1000000;
3918 secs++;
3919 }
3920 return make_lisp_time (make_timespec (secs, usecs * 1000));
3921#else /* ! HAVE_GETRUSAGE */
3922#ifdef WINDOWSNT
3923 return w32_get_internal_run_time ();
3924#else /* ! WINDOWSNT */
3925 return Fcurrent_time ();
3926#endif /* WINDOWSNT */
3927#endif /* HAVE_GETRUSAGE */
3928}
3914 3929
3915/* Wide character string collation. */ 3930/* Wide character string collation. */
3916 3931
@@ -4116,3 +4131,9 @@ str_collate (Lisp_Object s1, Lisp_Object s2,
4116 return res; 4131 return res;
4117} 4132}
4118#endif /* WINDOWSNT */ 4133#endif /* WINDOWSNT */
4134
4135void
4136syms_of_sysdep (void)
4137{
4138 defsubr (&Sget_internal_run_time);
4139}