From: Walter Harms <wharms@bfs.de>
To: "linux-man@vger.kernel.org" <linux-man@vger.kernel.org>
Subject: timespec_get() part of C11
Date: Sat, 24 Apr 2021 17:41:42 +0000 [thread overview]
Message-ID: <f79cbb6ecda24a1e90fb3c242d97c218@bfs.de> (raw)
.\" Copyright (c) 2021 wharms
.\" %%%LICENSE_START(VERBATIM)
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" manual under the conditions for verbatim copying, provided that the
.\" entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one.
.\"
.\" Since the Linux kernel and libraries are constantly changing, this
.\" manual page may be incorrect or out-of-date. The author(s) assume no
.\" responsibility for errors or omissions, or for damages resulting from
.\" the use of the information contained herein. The author(s) may not
.\" have taken the same level of care in the production of this manual,
.\" which is licensed free of charge, as they might when working
.\" professionally.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\" %%%LICENSE_END
.\"
.ds N1 The example is simplified code and not production ready.
.de N2
.SH COLOPHON
This page is part of release 4.16 of the Linux
.I man-pages
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
\%https://www.kernel.org/doc/man\-pages/.
..
.TH timespec_get 1 "2021-04-20" Linux "User Manuals"
.SH NAME
timespec_get \- get time in high resolution
.SH SYNOPSIS
.B #include <time.h>
.PP
.BI "int timespec_get( struct timespec *"ts ", int " base ");"
.SH DESCRIPTION
The function
.B timespec_get()
will fill
.I ts
wth the current time. The argument is a
.I struct timespec
what is specified like:
.nf
struct timespec
{
time_t tv_sec; /* Seconds. */
long tv_nsec; /* Nanoseconds. */
};
.fi
The elements of the struct hold the seconds and nanoseconds since epoch.
The system clock will round the nanosecond argument.
.PP
The second argument
.B base
indicate the time base. POSIX requieres
.I TIME_UTC
only. All others are implementation defined.
.SH RETURN VALUE
The function will return
.I base
or 0 for failure.
.SH EXAMPLE
The example program will show the current time
in YYYY-MM-DD hh:mm:ss and then the nanoseconds .
.EX
/* compile with:
* gcc timespec.c -o timespec
*/
#include <stdio.h>
#include <time.h>
int main(void)
{
struct timespec ts;
char buf[30];
timespec_get(&ts, TIME_UTC);
strftime(buf, sizeof(buf), "%F %T", gmtime(&ts.tv_sec));
printf("Current time: %s ", buf);
printf("UTC and %ld nsec\\n", ts.tv_nsec);
return (0);
}
.EE
\*(N1
.SH NOTE
This function is equal to the POSIX function
.BR "clock_gettime(CLOCK_REALTIME, ts)" .
.PP
The ts.tv_sec is equal to the return value of
.BR time(NULL) .
.SH "CONFORMING TO"
The function is a C11 requirement and appears first time in
.BR "glibc 2.16 " .
.SH "SEE ALSO"
.BR clock_gettime(3) ,
.BR time (2),
.BR time (7)
\*(N2
next reply other threads:[~2021-04-24 17:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-24 17:41 Walter Harms [this message]
2021-04-28 20:20 ` timespec_get() part of C11 Alejandro Colomar (man-pages)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f79cbb6ecda24a1e90fb3c242d97c218@bfs.de \
--to=wharms@bfs.de \
--cc=linux-man@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox