diff options
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/>. */ | |||
| 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 |
| 124 | int _cdecl _spawnlp (int, const char *, const char *, ...); | 130 | int _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. */ | ||
| 2710 | struct timeval | ||
| 2711 | make_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 | |||
| 3894 | DEFUN ("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. | ||
| 3897 | The time is returned as in the style of `current-time'. | ||
| 3898 | |||
| 3899 | On systems that can't determine the run time, `get-internal-run-time' | ||
| 3900 | does 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 | |||
| 4135 | void | ||
| 4136 | syms_of_sysdep (void) | ||
| 4137 | { | ||
| 4138 | defsubr (&Sget_internal_run_time); | ||
| 4139 | } | ||