# TIME - [Overview](#section537944755165622) - [Summary](#section506383298165622) - [Files](#files) - [Data Structures](#nested-classes) - [Macros](#define-members) - [Functions](#func-members) - [Details](#section1629487800165622) - [Function](#section1113575540165622) - [asctime\(\)](#ga416a0a99a5bab4c030e93d21152727f4) - [asctime\_r\(\)](#ga8eb1bca8a6fdc63173a83f1c8cb28e15) - [clock\_getres\(\)](#ga822b364014350d2d70bbd0ccaab1f476) - [clock\_gettime\(\)](#ga28ec1219021575a4b9a7c502b2e9a72c) - [clock\_nanosleep\(\)](#ga23d3356807a1cb25b5f64651c4aa7d33) - [clock\_settime\(\)](#ga04dbb6f7216d70a1b206741564d4d0fb) - [ctime\(\)](#ga6e58d33339fabd469b2f4790b0f2b843) - [ctime\_r\(\)](#gae6eed522503f70a5cf05be0be558b125) - [difftime\(\)](#ga1901c00eb89e8e35ea193c6a4676679c) - [ftime\(\)](#gad225ab16a149ff9aab8fb5c36f29ca0c) - [getdate\(\)](#gae85b268128fa533b20949464ce34165a) - [getitimer\(\)](#ga87cde44d5a31b1524f925d980c959985) - [gettimeofday\(\)](#ga5ef4514eca25b6c6b73c5a54b8bc9e2b) - [gmtime\(\)](#ga30d9732f32117a94652e28512905bfb9) - [gmtime\_r\(\)](#ga91bb7adea9b0b36acde8dba3012c01a5) - [localtime\(\)](#ga70311f8aa60fc5ebbd76c55ea10bc899) - [localtime\_r\(\)](#gad8c4ed240ddbd645502ac2f0a306aee0) - [mktime\(\)](#gafc0e3f373a3ea00b37714f1b621ae0b1) - [nanosleep\(\)](#gafbe0e411e8bf89275e7cd46d0aeedc4b) - [setitimer\(\)](#ga81245d77d2f570933cc81f13a101bff8) - [settimeofday\(\)](#ga6e6617fc349ed4777425d667ff250fa7) - [stime\(\)](#ga69f8377385b2eeee376712dc9f0e3f71) - [strftime\(\)](#gab94643a711fc91727b668553d4a8806b) - [strftime\_l\(\)](#ga74c011f36d0ad959f0312dec8a5c8dc8) - [strptime\(\)](#ga8454b83c5b4fb93a9dcdd72ab586de22) - [time\(\)](#gae7841e681c8c9d59818568d39553642c) - [timegm\(\)](#ga4fd5240e99b2a9bf19bc0fe39f6ffc07) - [timer\_create\(\)](#gaf7dce9c851a2e1a65aaf818b95487431) - [timer\_delete\(\)](#ga61fa078bdadbd957cfcdfb12d0592ac1) - [timer\_getoverrun\(\)](#ga6ecdedfd7f417a3d93aa7a18ff0ac582) - [timer\_gettime\(\)](#ga8f65c6a88588c951e0b11629e56714a4) - [timer\_settime\(\)](#gade973e87fffe05aed7f1e97c1d15178e) ## **Overview** **Description:** Provides time-related structures and functions. **Since:** 1.0 **Version:** 1.0 ## **Summary** ## Files

File Name

Description

sys/time.h

Provides structures and functions related to the system time.

timeb.h

Provides structures and functions related to the curren time.

time.h

Provides time-related structures and functions.

## Data Structures

Data Structure Name

Description

timeval

Describes a period of time, accurate to microseconds.

timespec

Describes a period of time, accurate to nanoseconds.

itimerval

Describes a timer.

timezone

Describes a time zone.

timeb

Describes the time, accurate to millisecond.

tm

Describes date and time information.

itimerspec

Sets a timer.

## Macros

Macro Name and Value

Description

ITIMER_REAL 0

Defines the timer that runs in real time.

CLOCK_REALTIME 0

Defines a real-time clock.

CLOCK_MONOTONIC 1

Defines a monotonic clock.

CLOCK_MONOTONIC_RAW 4

Defines a raw hardware-based monotonic clock.

CLOCK_REALTIME_COARSE 5

Defines a low-precision real-time clock.

CLOCK_MONOTONIC_COARSE 6

Defines a low-precision monotonic clock.

## Functions

Function

Description

gettimeofday (struct timeval *__restrict value, void *__restrict ovalue)

int

Obtains the system time and time zone.

getitimer (int w, struct itimerval *old)

int

Obtains the value of an intermittent timer.

setitimer (int w, const struct itimerval *__restrict value, struct itimerval *__restrict ovalue)

int

Sets the value for a timer.

settimeofday (const struct timeval *tv, const struct timezone *tz)

int

Sets the system time and time zone.

ftime (struct timeb *tp)

int

Obtains the current time, accurate to milliseconds.

time (time_t *t)

time_t

Obtains the time.

difftime (time_t time1, time_t time2)

double

Calculates the difference between two times, in seconds.

mktime (struct tm *tm)

time_t

Converts the broken-down time in the tm structure into seconds.

strftime (char *restrict s, size_t n, const char *restrict f, const struct tm *restrict tm)

size_t

Converts the broken-down time in the tm structure to a string in the required format.

gmtime (const time_t *t)

struct tm *

Converts the number of seconds to the UTC time in the tm structure.

localtime (const time_t *t)

struct tm *

Converts the number of seconds to the local time in the tm structure.

asctime (const struct tm *tm)

char *

Converts the broken-down time in the tm structure into a string.

ctime (const time_t *timep)

char *

Converts the date and time into a string.

strftime_l (char *__restrict s, size_t n, const char *__restrict f, const struct tm *__restrict tm, locale_t loc)

size_t

Converts the broken-down time in the tm structure to a string in a specified programming language and format.

gmtime_r (const time_t *__restrict t, struct tm *__restrict tm)

struct tm *

Converts the number of seconds to the UTC time in the tm structure. (This function is reentrant.)

localtime_r (const time_t *__restrict t, struct tm *__restrict tm)

struct tm *

Converts the number of seconds to the local time in the tm structure. (This function is reentrant.)

asctime_r (const struct tm *__restrict tm, char *__restrict buf)

char *

Converts the broken-down time in the tm structure into a string. (This function is reentrant.)

ctime_r (const time_t *t, char *buf)

char *

Converts the date and time into a string. (This function is reentrant.)

nanosleep (const struct timespec *tspec1, struct timespec *tspec2)

int

Pauses the current thread until a specified time arrives.

clock_getres (clockid_t id, struct timespec *tspec)

int

Obtains the precision of a clock.

clock_gettime (clockid_t id, struct timespec *tspec)

int

Obtains the time of a clock.

clock_settime (clockid_t id, const struct timespec *tspec)

int

Sets the time for a clock.

clock_nanosleep (clockid_t id, int flag, const struct timespec *tspec1, struct timespec *tspec2)

int

Pauses the current thread until a specified time of a clock arrives.

timer_create (clockid_t id, struct sigevent *__restrict evp, timer_t *__restrict t)

int

Creates a timer for the process.

timer_delete (timer_t t)

int

Deletes a timer for the process.

timer_settime (timer_t t, int flags, const struct itimerspec *__restrict val, struct itimerspec *__restrict old)

int

Sets a timer for the process.

timer_gettime (timer_t t, struct itimerspec *tspec)

int

Obtains a timer of the process.

timer_getoverrun (timer_t t)

int

Obtains the number of times that a timer overruns.

strptime (const char *s, const char *format, struct tm *tm)

char *

Converts a time string to the broken-down time in the tm structure.

getdate (const char *buf)

struct tm *

Converts a time string to the broken-down time in the tm structure.

stime (const time_t *t)

int

Sets the system time.

timegm (struct tm *tm)

time_t

Converts the broken-down time in the tm structure to the number of seconds.

## **Details** ## **Function** ## asctime\(\) ``` char* asctime (const struct [tm](tm.md) * tm) ``` **Description:** Converts the broken-down time in the [tm](tm.md) structure into a string. **Parameters:**

Name

Description

tm

Indicates the pointer to the broken-down time in the tm structure.

**Returns:** Returns the string in the format of **week month day hour:minute:second year**, for example, **Thu Jan 1 08:00:00 1970**. If the conversion fails, the program ends. ## asctime\_r\(\) ``` char* asctime_r (const struct [tm](tm.md) *__restrict tm, char *__restrict buf ) ``` **Description:** Converts the broken-down time in the [tm](tm.md) structure into a string. \(This function is reentrant.\) **Parameters:**

Name

Description

tm

Indicates the pointer to the broken-down time in the tm structure.

buf

Indicates the pointer to the buffer for storing the string.

**Returns:** Returns the string in the format of **week month day hour:minute:second year**, for example, **Thu Jan 1 08:00:00 1970**. If the conversion fails, the program ends. ## clock\_getres\(\) ``` int clock_getres ([clockid_t](UTILS.md#ga391e4a62662054e5d3e1e071b8e54329) id, struct [timespec](timespec.md) * tspec ) ``` **Description:** Obtains the precision of a clock. **Parameters:**

Name

Description

id

Indicates the clock ID, which can be CLOCK_REALTIME, CLOCK_REALTIME_COARSE, CLOCK_MONOTONIC, CLOCK_MONOTONIC_COARSE or CLOCK_MONOTONIC_RAW.

tspec

Indicates the pointer to the data obtained.

**Returns:** Returns **0** if the operation is successful; returns **-1** otherwise. ## clock\_gettime\(\) ``` int clock_gettime ([clockid_t](UTILS.md#ga391e4a62662054e5d3e1e071b8e54329) id, struct [timespec](timespec.md) * tspec ) ``` **Description:** Obtains the time of a clock. **Parameters:**

Name

Description

id

Indicates the clock ID, which can be CLOCK_REALTIME, CLOCK_REALTIME_COARSE, CLOCK_MONOTONIC, CLOCK_MONOTONIC_COARSE, or CLOCK_MONOTONIC_RAW.

tspec

Indicates the pointer to the time obtained.

**Attention:** [CLOCK\_REALTIME\_COARSE](TIME.md#gaccb072221e0afcac765ec2bb6e4eca04) and [CLOCK\_MONOTONIC\_COARSE](TIME.md#gaec7304645b1e13a52fa6dfb11f1c671b) are two new types of clock ID, which are optimized via virtual dynamic shared object \(vDSO\). **Returns:** Returns **0** if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.

errno

Description

EINVAL

Invalid input.

## clock\_nanosleep\(\) ``` int clock_nanosleep ([clockid_t](UTILS.md#ga391e4a62662054e5d3e1e071b8e54329) id, int flag, const struct [timespec](timespec.md) * tspec1, struct [timespec](timespec.md) * tspec2 ) ``` **Description:** Pauses the current thread until a specified time of a clock arrives. A sleeping thread cannot be woken up by a signal. **Parameters:**

Name

Description

id

Indicates the clock ID. Only CLOCK_REALTIME is supported.

flag

Indicates the clock type. This parameter must be set to 0

tspec1

Indicates the pointer to the minimum duration that the current thread is paused. Currently, the unit of precision is tick, and the discrepancy is fewer than 2 ticks.

tspec2

This parameter is not used yet.

**Returns:** Returns **0** if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.

errno

Description

EINVAL

Invalid input.

## clock\_settime\(\) ``` int clock_settime ([clockid_t](UTILS.md#ga391e4a62662054e5d3e1e071b8e54329) id, const struct [timespec](timespec.md) * tspec ) ``` **Description:** Sets the time for a clock. **Parameters:**

Name

Description

id

Indicates the clock ID. Only CLOCK_REALTIME is supported.

tspec

Indicates the pointer to the time to set.

**Returns:** Returns **0** if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.

errno

Description

EINVAL

Invalid input.

## ctime\(\) ``` char* ctime (const [time_t](UTILS.md#ga138ad62ac7715e7161bf6223e35d8323) * timep) ``` **Description:** Converts the date and time into a string. **Parameters:**

Name

Description

timep

Indicates the number of seconds to convert.

**Returns:** Returns the string in the format of **week month day hour:minute:second year**, for example, **Thu Jan 1 08:00:00 1970**. If the conversion fails, the program ends. ## ctime\_r\(\) ``` char* ctime_r (const [time_t](UTILS.md#ga138ad62ac7715e7161bf6223e35d8323) * t, char * buf ) ``` **Description:** Converts the date and time into a string. \(This function is reentrant.\) **Parameters:**

Name

Description

t

Indicates the pointer to the number of seconds to convert.

buf

Indicates the pointer to the buffer for storing the string.

**Returns:** Returns the string in the format of **week month day hour:minute:second year**, for example, **Thu Jan 1 08:00:00 1970**. If the conversion fails, the program ends. ## difftime\(\) ``` double difftime ([time_t](UTILS.md#ga138ad62ac7715e7161bf6223e35d8323) time1, [time_t](UTILS.md#ga138ad62ac7715e7161bf6223e35d8323) time2 ) ``` **Description:** Calculates the difference between two times, in seconds. **Parameters:**

Name

Description

time1

Indicates the first time.

time2

Indicates the second time.

**Returns:** Returns the difference, represented using a double. ## ftime\(\) ``` int ftime (struct [timeb](timeb.md) * tp) ``` **Description:** Obtains the current time, accurate to milliseconds. The time obtained is the total number of milliseconds elapsed since January 1, 1970 00:00:00 \(UTC\). **Parameters:**

Name

Description

tp

Indicates the pointer to the number of milliseconds. timezone and dstflag are set to 0.

**Returns:** Returns **0** if the operation is successful; returns **-1** otherwise. ## getdate\(\) ``` struct [tm](tm.md)* getdate (const char * buf) ``` **Description:** Converts a time string to the broken-down time in the [tm](tm.md) structure. **Parameters:**

Name

Description

buf

Indicates the pointer to the time string. The format is specified by the file defined by the environment variable DATEMSK.

**Returns:** Returns the time in the [tm](tm.md) structure if the operation is successful; returns **NULL** otherwise. ## getitimer\(\) ``` int getitimer (int w, struct [itimerval](itimerval.md) * old ) ``` **Description:** Obtains the value of an intermittent timer. **Parameters:**

Name

Description

w

Indicates the timer type. Only ITIMER_REAL is supported.

old

Indicates the pointer to the timer value.

**Returns:** Returns **0** if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.

errno

Description

EINVAL

Incorrect input or timer type.

## gettimeofday\(\) ``` int gettimeofday (struct [timeval](timeval.md) *__restrict value, void *__restrict ovalue ) ``` **Description:** Obtains the system time and time zone. **Parameters:**

Name

Description

value

Indicates the pointer to the timeval structure that contains the time.

ovalue

This parameter is used for compatibility only.

**Attention:** Currently, there is no time zone structure. The return value of **ovalue** is empty. **Returns:** Returns **0** if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.

errno

Description

EINVAL

Incorrect input.

## gmtime\(\) ``` struct [tm](tm.md)* gmtime (const [time_t](UTILS.md#ga138ad62ac7715e7161bf6223e35d8323) * t) ``` **Description:** Converts the number of seconds to the UTC time in the [tm](tm.md) structure. **Parameters:**

Name

Description

t

Indicates the pointer to the number of seconds to convert.

**Returns:** Returns the pointer to the UTC time in the [tm](tm.md) structure if the conversion is successful; returns **NULL** and sets **errno** to a value in the following table if the operation fails.

errno

Description

EOVERFLOW

Inappropriate input parameter.

## gmtime\_r\(\) ``` struct [tm](tm.md)* gmtime_r (const [time_t](UTILS.md#ga138ad62ac7715e7161bf6223e35d8323) *__restrict t, struct [tm](tm.md) *__restrict tm ) ``` **Description:** Converts the number of seconds to the UTC time in the [tm](tm.md) structure. \(This function is reentrant.\) This function is used in the multi-task environment. **Parameters:**

Name

Description

t

Indicates the pointer to the number of seconds to convert.

tm

Indicates the pointer to the tm structure.

**Returns:** Returns the pointer to the UTC time in the [tm](tm.md) structure if the conversion is successful; returns **NULL** and sets **errno** to a value in the following table if the operation fails.

errno

Description

EOVERFLOW

Inappropriate input parameter.

## localtime\(\) ``` struct [tm](tm.md)* localtime (const [time_t](UTILS.md#ga138ad62ac7715e7161bf6223e35d8323) * t) ``` **Description:** Converts the number of seconds to the local time in the [tm](tm.md) structure. **Parameters:**

Name

Description

t

Indicates the pointer to the number of seconds to convert.

**Returns:** Returns the pointer to the local time in the [tm](tm.md) structure if the conversion is successful; returns **NULL** and sets **errno** to a value in the following table if the operation fails.

errno

Description

EOVERFLOW

Inappropriate input parameter.

## localtime\_r\(\) ``` struct [tm](tm.md)* localtime_r (const [time_t](UTILS.md#ga138ad62ac7715e7161bf6223e35d8323) *__restrict t, struct [tm](tm.md) *__restrict tm ) ``` **Description:** Converts the number of seconds to the local time in the [tm](tm.md) structure. \(This function is reentrant.\) **Parameters:**

Name

Description

t

Indicates the pointer to the number of seconds to convert.

tm

Indicates the pointer to the tm structure.

**Returns:** Returns the pointer to the local time in the [tm](tm.md) structure if the conversion is successful; returns **NULL** and sets **errno** to a value in the following table if the operation fails.

errno

Description

EOVERFLOW

Inappropriate input parameter.

## mktime\(\) ``` [time_t](UTILS.md#ga138ad62ac7715e7161bf6223e35d8323) mktime (struct [tm](tm.md) * tm) ``` **Description:** Converts the broken-down time in the [tm](tm.md) structure into seconds. **Parameters:**

Name

Description

tm

Indicates the pointer to the broken-down time in the tm structure.

**Returns:** Returns the total number of seconds elapsed since January 1, 1970 00:00:00 \(UTC\) if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.

errno

Description

EOVERFLOW

Inappropriate input parameter.

## nanosleep\(\) ``` int nanosleep (const struct [timespec](timespec.md) * tspec1, struct [timespec](timespec.md) * tspec2 ) ``` **Description:** Pauses the current thread until a specified time arrives. A sleeping thread cannot be woken up by a signal. **Parameters:**

Name

Description

tspec1

Indicates the pointer to the minimum duration that the current thread is paused. Currently, the unit of precision is tick, and the discrepancy is fewer than 2 ticks.

tspec2

This parameter is not used yet.

**Returns:** Returns **0** if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.

errno

Description

EINVAL

Invalid input.

## setitimer\(\) ``` int setitimer (int w, const struct [itimerval](itimerval.md) *__restrict value, struct [itimerval](itimerval.md) *__restrict ovalue ) ``` **Description:** Sets the value for a timer. **Parameters:**

Name

Description

w

Indicates the timer type. Currently, only ITIMER_REAL is supported.

value

Indicates the pointer to the timer value to set.

ovalue

Indicates the pointer to the original timer value before the current setting, which can be NULL.

**Returns:** Returns **0** if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.

errno

Description

EINVAL

Incorrect input or timer type.

## settimeofday\(\) ``` int settimeofday (const struct [timeval](timeval.md) * tv, const struct [timezone](timezone.md) * tz ) ``` **Description:** Sets the system time and time zone. **Parameters:**

Name

Description

tv

Indicates the pointer to the time to set.

tz

Indicates the pointer to the time zone to set. This parameter is not used yet.

**Attention:** **tz** is invalid. The time is set internally using **clock\_settime**. **Returns:** Returns **0** if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.

errno

Description

EINVAL

Incorrect input.

## stime\(\) ``` int stime (const [time_t](UTILS.md#ga138ad62ac7715e7161bf6223e35d8323) * t) ``` **Description:** Sets the system time. **Parameters:**

Name

Description

t

Indicates the pointer to the number of seconds to set.

**Returns:** Returns **0** if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.

errno

Description

EINVAL

Invalid input.

## strftime\(\) ``` size_t strftime (char *restrict s, size_t n, const char *restrict f, const struct [tm](tm.md) *restrict tm ) ``` **Description:** Converts the broken-down time in the [tm](tm.md) structure to a string in the required format. **Parameters:**

Name

Description

s

Indicates the pointer to the string.

n

Indicates the size of the buffer for storing the string.

f

Indicates the pointer to the required format.

tm

Indicates the pointer to the broken-down time in the tm structure.

**Returns:** Returns the number of bytes in the string if the conversion is successful; returns **0** otherwise. ## strftime\_l\(\) ``` size_t strftime_l (char *__restrict s, size_t n, const char *__restrict f, const struct [tm](tm.md) *__restrict tm, locale_t loc ) ``` **Description:** Converts the broken-down time in the [tm](tm.md) structure to a string in a specified programming language and format. **Parameters:**

Name

Description

s

Indicates the pointer to the string.

n

Indicates the size of the buffer for storing the string.

f

Indicates the pointer to the required format.

tm

Indicates the pointer to the broken-down time in the tm structure.

loc

Indicates the required programming language. Currently, only C programming language is supported.

**Returns:** Returns the number of bytes in the string if the conversion is successful; returns **0** otherwise. ## strptime\(\) ``` char* strptime (const char * s, const char * format, struct [tm](tm.md) * tm ) ``` **Description:** Converts a time string to the broken-down time in the [tm](tm.md) structure. This function parses the input string **s** based on **format** and stores the result in the [tm](tm.md) structure. **Parameters:**

Name

Description

s

Indicates the pointer to the string that contains only time data.

format

Indicates the pointer to the required format.

tm

Indicates the pointer to the tm structure.

**Returns:** Returns the pointer to the position to which the string has been processed \(the next character to be processed\) upon the conversion completion if the operation is successful; returns **NULL** otherwise. ## time\(\) ``` [time_t](UTILS.md#ga138ad62ac7715e7161bf6223e35d8323) time ([time_t](UTILS.md#ga138ad62ac7715e7161bf6223e35d8323) * t) ``` **Description:** Obtains the time. The time obtained is the total number of seconds elapsed since January 1, 1970 00:00:00 \(UTC\). **Parameters:**

Name

Description

t

Indicates the pointer to the number of seconds. You can also pass NULL to use the return value.

**Returns:** Returns the number of seconds. ## timegm\(\) ``` [time_t](UTILS.md#ga138ad62ac7715e7161bf6223e35d8323) timegm (struct [tm](tm.md) * tm) ``` **Description:** Converts the broken-down time in the [tm](tm.md) structure to the number of seconds. **Parameters:**

Name

Description

tm

Indicates the pointer to the broken-down time in the tm structure to convert.

**Returns:** Returns the number of seconds if the operation is successful; returns **NULL** and sets **errno** to a value in the following table if the operation fails.

errno

Description

EOVERFLOW

The input parameter is too long.

## timer\_create\(\) ``` int timer_create ([clockid_t](UTILS.md#ga391e4a62662054e5d3e1e071b8e54329) id, struct [sigevent](sigevent.md) *__restrict evp, [timer_t](UTILS.md#gacea9f425ec91056458fd7cd0b0923d1a) *__restrict t ) ``` **Description:** Creates a timer for the process. **Parameters:**

Name

Description

id

Indicates the clock ID. Only CLOCK_REALTIME is supported.

evp

Indicates the pointer to the asynchronous notification signal and action, which can be NULL.

t

Indicates the pointer to the timer ID.

**Attention:** **sigev\_notify** in the **sigevent** structure must be [SIGEV\_SIGNAL](IPC.md#ga06d5881eeb84e6ac35f5b801c380dbb6). **Returns:** Returns **0** if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.

errno

Description

EINVAL

Invalid input.

ENOTSUP

The value of evp is not NULL and sigev_notify is not SIGEV_SIGNAL.

## timer\_delete\(\) ``` int timer_delete ([timer_t](UTILS.md#gacea9f425ec91056458fd7cd0b0923d1a) t) ``` **Description:** Deletes a timer for the process. **Parameters:**

Name

Description

t

Indicates the ID of the timer to delete.

**Returns:** Returns **0** if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.

errno

Description

EINVAL

Invalid input.

## timer\_getoverrun\(\) ``` int timer_getoverrun ([timer_t](UTILS.md#gacea9f425ec91056458fd7cd0b0923d1a) t) ``` **Description:** Obtains the number of times that a timer overruns. **Parameters:**

Name

Description

t

Indicates the ID of the timer to obtain.

**Returns:** Returns the number of times if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.

errno

Description

EINVAL

Invalid input.

## timer\_gettime\(\) ``` int timer_gettime ([timer_t](UTILS.md#gacea9f425ec91056458fd7cd0b0923d1a) t, struct [itimerspec](itimerspec.md) * tspec ) ``` **Description:** Obtains a timer of the process. **Parameters:**

Name

Description

t

Indicates the ID of the timer to obtain.

tspec

Indicates the pointer to the timer duration and interval.

**Returns:** Returns **0** if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.

errno

Description

EINVAL

Incorrect parameter or timer operation failure.

## timer\_settime\(\) ``` int timer_settime ([timer_t](UTILS.md#gacea9f425ec91056458fd7cd0b0923d1a) t, int flags, const struct [itimerspec](itimerspec.md) *__restrict val, struct [itimerspec](itimerspec.md) *__restrict old ) ``` **Description:** Sets a timer for the process. **Parameters:**

Name

Description

t

Indicates the ID of the timer to set.

flags

Indicates the type of the timer to set. This parameter is not supported and must be set to 0.

val

Indicates the pointer to the timer duration and interval to set.

old

Indicates the pointer to the timer duration and interval before the current setting.

**Returns:** Returns **0** if the operation is successful; returns **-1** and sets **errno** to a value in the following table if the operation fails.

errno

Description

EINVAL

Incorrect parameter or timer operation failure.