summaryrefslogtreecommitdiff
path: root/devdocs/c/chrono%2Ftimespec_getres.html
blob: b40a3243c10d2ded0b8b87fe331e7721d05f2117 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
    <h1 id="firstHeading" class="firstHeading">timespec_getres</h1>            <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code>&lt;time.h&gt;</code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c23"> <td> <pre data-language="c">int timespec_getres( struct timespec *ts, int base );</pre>
</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c23">(since C23)</span> </td> </tr>  </table> <p>If <code>ts</code> is non-null and <code>base</code> is supported by <code>timespec_get</code>, modifies <code>*ts</code> to hold the resolution of time provided by <code>timespec_get</code> for <code>base</code>. For each supported <code>base</code>, multiple calls to <code>timespec_getres</code> during the same program execution have identical results.</p>
<h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> ts </td> <td> - </td> <td> pointer to an object of type <code>struct timespec</code> </td>
</tr> <tr class="t-par"> <td> base </td> <td> - </td> <td> <code>TIME_UTC</code> or another nonzero integer value indicating the time base </td>
</tr>
</table> <h3 id="Return_value"> Return value</h3> <p>The value of <code>base</code> if <code>base</code> is supported, zero otherwise.</p>
<h3 id="Notes"> Notes</h3> <p>The POSIX function <a rel="nofollow" class="external text" href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_getres.html"><code>clock_getres(clock_id, ts)</code></a> may also be used to populate a <code>timespec</code> with the resolution of time identified by <code>clock_id</code>.</p>
<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include &lt;stdio.h&gt;
#include &lt;time.h&gt;
 
int main(void)
{
    char buff[128];
    struct timespec ts;
    const int res = timespec_getres(&amp;ts, TIME_UTC);
    if (res == TIME_UTC) {
        struct tm timer;
        strftime(buff, sizeof buff, "%D %T", gmtime_r(&amp;ts.tv_sec, &amp;timer));
        printf("Time resolution info: %s.%09ld UTC\n", buff, ts.tv_nsec);
    } else {
        printf("TIME_UTC base is not supported.");
    }
}</pre></div> <p>Possible output:</p>
<div class="text source-text"><pre data-language="c">Time resolution info: 01/01/70 00:00:00.000000001 UTC</pre></div> </div> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="timespec" title="c/chrono/timespec"> <span class="t-lines"><span>timespec</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-c11">(C11)</span></span></span></div> </td> <td> time in seconds and nanoseconds <br><span class="t-mark">(struct)</span> </td>
</tr> <tr class="t-dsc"> <td> <div><a href="timespec_get" title="c/chrono/timespec get"> <span class="t-lines"><span>timespec_get</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-c11">(C11)</span></span></span></div> </td> <td> returns the calendar time in seconds and nanoseconds based on a given time base <br> <span class="t-mark">(function)</span>  </td>
</tr> <tr class="t-dsc"> <td> <div><a href="time" title="c/chrono/time"> <span class="t-lines"><span>time</span></span></a></div> </td> <td> returns the current calendar time of the system as time since epoch <br> <span class="t-mark">(function)</span>  </td>
</tr> </table>           <div class="_attribution">
  <p class="_attribution-p">
    &copy; cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br>
    <a href="https://en.cppreference.com/w/c/chrono/timespec_getres" class="_attribution-link">https://en.cppreference.com/w/c/chrono/timespec_getres</a>
  </p>
</div>