2012-06-22 21:26:37 +00:00
|
|
|
/* gettime -- get the system clock
|
|
|
|
|
2024-01-20 19:45:04 +00:00
|
|
|
Copyright (C) 2002, 2004-2007, 2009-2024 Free Software Foundation, Inc.
|
2012-06-22 21:26:37 +00:00
|
|
|
|
Update from Gnulib
Make the following changes by hand, and run 'admin/merge-gnulib'.
* .gitignore: Add lib/malloc/*.gl.h.
* admin/merge-gnulib: Copy lib/af_alg.h and lib/save-cwd.h
directly from Gnulib, without worrying about Gnulib modules,
as these files are special cases.
(AVOIDED_MODULES): Remove malloc-posix.
* lib/malloc.c, lib/realloc.c, m4/malloc.m4, m4/realloc.m4:
* m4/year2038.m4: New files, copied from Gnulib.
* lib/malloca.c, lib/malloca.h:
* m4/close-stream.m4, m4/glibc21.m4, m4/malloca.m4:
Remove. These are either no longer present in Gnulib, or are no
longer needed by modules that Emacs uses.
* oldXMenu/AddPane.c, oldXmenu/Addsel.c: Include XmenuInt.h first;
needed for new Gnulib.
* src/xmenu.c: Call emacs_abort, not abort.
2021-10-04 19:11:39 +00:00
|
|
|
This file is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as
|
2022-02-23 19:11:52 +00:00
|
|
|
published by the Free Software Foundation, either version 3 of the
|
Update from Gnulib
Make the following changes by hand, and run 'admin/merge-gnulib'.
* .gitignore: Add lib/malloc/*.gl.h.
* admin/merge-gnulib: Copy lib/af_alg.h and lib/save-cwd.h
directly from Gnulib, without worrying about Gnulib modules,
as these files are special cases.
(AVOIDED_MODULES): Remove malloc-posix.
* lib/malloc.c, lib/realloc.c, m4/malloc.m4, m4/realloc.m4:
* m4/year2038.m4: New files, copied from Gnulib.
* lib/malloca.c, lib/malloca.h:
* m4/close-stream.m4, m4/glibc21.m4, m4/malloca.m4:
Remove. These are either no longer present in Gnulib, or are no
longer needed by modules that Emacs uses.
* oldXMenu/AddPane.c, oldXmenu/Addsel.c: Include XmenuInt.h first;
needed for new Gnulib.
* src/xmenu.c: Call emacs_abort, not abort.
2021-10-04 19:11:39 +00:00
|
|
|
License, or (at your option) any later version.
|
2012-06-22 21:26:37 +00:00
|
|
|
|
Update from Gnulib
Make the following changes by hand, and run 'admin/merge-gnulib'.
* .gitignore: Add lib/malloc/*.gl.h.
* admin/merge-gnulib: Copy lib/af_alg.h and lib/save-cwd.h
directly from Gnulib, without worrying about Gnulib modules,
as these files are special cases.
(AVOIDED_MODULES): Remove malloc-posix.
* lib/malloc.c, lib/realloc.c, m4/malloc.m4, m4/realloc.m4:
* m4/year2038.m4: New files, copied from Gnulib.
* lib/malloca.c, lib/malloca.h:
* m4/close-stream.m4, m4/glibc21.m4, m4/malloca.m4:
Remove. These are either no longer present in Gnulib, or are no
longer needed by modules that Emacs uses.
* oldXMenu/AddPane.c, oldXmenu/Addsel.c: Include XmenuInt.h first;
needed for new Gnulib.
* src/xmenu.c: Call emacs_abort, not abort.
2021-10-04 19:11:39 +00:00
|
|
|
This file is distributed in the hope that it will be useful,
|
2012-06-22 21:26:37 +00:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Update from Gnulib
Make the following changes by hand, and run 'admin/merge-gnulib'.
* .gitignore: Add lib/malloc/*.gl.h.
* admin/merge-gnulib: Copy lib/af_alg.h and lib/save-cwd.h
directly from Gnulib, without worrying about Gnulib modules,
as these files are special cases.
(AVOIDED_MODULES): Remove malloc-posix.
* lib/malloc.c, lib/realloc.c, m4/malloc.m4, m4/realloc.m4:
* m4/year2038.m4: New files, copied from Gnulib.
* lib/malloca.c, lib/malloca.h:
* m4/close-stream.m4, m4/glibc21.m4, m4/malloca.m4:
Remove. These are either no longer present in Gnulib, or are no
longer needed by modules that Emacs uses.
* oldXMenu/AddPane.c, oldXmenu/Addsel.c: Include XmenuInt.h first;
needed for new Gnulib.
* src/xmenu.c: Call emacs_abort, not abort.
2021-10-04 19:11:39 +00:00
|
|
|
GNU Lesser General Public License for more details.
|
2012-06-22 21:26:37 +00:00
|
|
|
|
Update from Gnulib
Make the following changes by hand, and run 'admin/merge-gnulib'.
* .gitignore: Add lib/malloc/*.gl.h.
* admin/merge-gnulib: Copy lib/af_alg.h and lib/save-cwd.h
directly from Gnulib, without worrying about Gnulib modules,
as these files are special cases.
(AVOIDED_MODULES): Remove malloc-posix.
* lib/malloc.c, lib/realloc.c, m4/malloc.m4, m4/realloc.m4:
* m4/year2038.m4: New files, copied from Gnulib.
* lib/malloca.c, lib/malloca.h:
* m4/close-stream.m4, m4/glibc21.m4, m4/malloca.m4:
Remove. These are either no longer present in Gnulib, or are no
longer needed by modules that Emacs uses.
* oldXMenu/AddPane.c, oldXmenu/Addsel.c: Include XmenuInt.h first;
needed for new Gnulib.
* src/xmenu.c: Call emacs_abort, not abort.
2021-10-04 19:11:39 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2017-09-13 09:07:03 +00:00
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
2012-06-22 21:26:37 +00:00
|
|
|
|
|
|
|
/* Written by Paul Eggert. */
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "timespec.h"
|
|
|
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
/* Get the system time into *TS. */
|
|
|
|
|
|
|
|
void
|
|
|
|
gettime (struct timespec *ts)
|
|
|
|
{
|
2018-09-17 04:24:04 +00:00
|
|
|
#if defined CLOCK_REALTIME && HAVE_CLOCK_GETTIME
|
|
|
|
clock_gettime (CLOCK_REALTIME, ts);
|
2022-01-04 21:13:25 +00:00
|
|
|
#elif defined HAVE_TIMESPEC_GET
|
|
|
|
timespec_get (ts, TIME_UTC);
|
2012-06-22 21:26:37 +00:00
|
|
|
#else
|
2018-09-17 04:24:04 +00:00
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday (&tv, NULL);
|
2023-05-16 05:09:04 +00:00
|
|
|
*ts = (struct timespec) { .tv_sec = tv.tv_sec,
|
|
|
|
.tv_nsec = tv.tv_usec * 1000 };
|
2018-09-17 04:24:04 +00:00
|
|
|
#endif
|
|
|
|
}
|
2012-06-22 21:26:37 +00:00
|
|
|
|
2018-09-17 04:24:04 +00:00
|
|
|
/* Return the current system time as a struct timespec. */
|
2012-06-22 21:26:37 +00:00
|
|
|
|
2018-09-17 04:24:04 +00:00
|
|
|
struct timespec
|
|
|
|
current_timespec (void)
|
|
|
|
{
|
|
|
|
struct timespec ts;
|
|
|
|
gettime (&ts);
|
|
|
|
return ts;
|
2012-06-22 21:26:37 +00:00
|
|
|
}
|