timeradd

Section: C Library Functions (3)
Updated: 2026-02-08
Index JM Home Page
 

名前

timeradd, timersub, timercmp, timerclear, timerisset - timeval の操作  

ライブラリ

標準 C ライブラリ (libc, -lc)  

書式

#include <sys/time.h>

void timeradd(struct timeval *a, struct timeval *b,
              struct timeval *res);
void timersub(struct timeval *a, struct timeval *b,
              struct timeval *res);

void timerclear(struct timeval *tvp);
int timerisset(struct timeval *tvp);

int timercmp(struct timeval *a, struct timeval *b, CMP);

glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):

すべての関数は上記に記してあります:

    glibc 2.19 よりあと:
        _DEFAULT_SOURCE
    glibc 2.19 以前:
        _BSD_SOURCE
 

説明

timeval 構造体を操作するためのマクロが提供されています。 timeval 構造体は <sys/time.h> で以下のように定義されています。

struct timeval {
    time_t      tv_sec;     /* 秒 */
    suseconds_t tv_usec;    /* マイクロ秒 */ };

timeradd() は、 a と b の時刻値を加算し、その合計を res により参照される timeval 構造体に格納します。結果は、res->tv_usec の値が 0 から 999,999 の範囲に入るように正規化されます。

timersub() は、 a の時刻値から b の時刻値を減算し、その結果を res により参照される timeval 構造体に格納します。結果は、 res->tv_usec の値が 0 から 999,999 の範囲に入るように正規化されます。

timerclear() は tvp により参照される timeval 構造体を 0 で埋めます。 0 で埋められた timeval 構造体は、時刻紀元 (Epoch; 1970-01-01 00:00:00 +0000 (UTC)) を表します。

timerisset() は、 tvp により参照される timeval 構造体のいずれか一方のフィールドに 0 以外の値が入っていれば、 真 (0 以外) を返します。

timercmp() は a と b の時刻値を比較演算子 CMP を使って比較し、比較結果に基づき、真 (0 以外) か偽 (0) を返します。 (Linux/glibc はそうではないが) いくつかのシステムでは、 timercmp() の実装がおかしく、 CMP に >=, <=, == を指定すると正しく動作しません。移植性が必要なアプリケーションでは、 代わりに以下を使ってください。

!timercmp(..., <) !timercmp(..., >) !timercmp(..., !=)  

返り値

timerisset() と timercmp() は、真 (0 以外) か偽 (0) を返します。  

エラー

エラーは定義されていません。  

標準

なし。  

履歴

BSD.  

関連項目

gettimeofday(2), time(7)

関連キーワード

timeval   struct   構造体   timercmp   時刻   time   usec   timeradd   timersub   timerclear   timerisset   操作   マクロ   格納   範囲   正規化   ライブラリ   検査   要件   macros   上記   提供   suseconds   マイクロ   加算

Linux マニュアル 一覧

関連するコマンド・関数

timerclear.3   timercmp.3   timerisset.3   timersub.3   rtime.3   futimes.3
 

Index

名前
ライブラリ
書式
説明
返り値
エラー
標準
履歴
関連項目

This document was created by man2html, using the manual pages.
Time: 04:39:03 GMT, October 11, 2026