- Tumbleweed 20260815-1.1
- Leap-16.0
- Leap-15.6
| timeradd(3) | Library Functions Manual | timeradd(3) |
名前¶
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 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.
関連項目¶
| 2026-02-08 | Linux man-pages (未リリース) |