diff options
| author | Karel Zak <kzak@redhat.com> | 2013-03-13 11:51:15 +0100 |
|---|---|---|
| committer | Karel Zak <kzak@redhat.com> | 2013-03-13 11:51:15 +0100 |
| commit | 477254da9325b6c12975063023bded77c96dc1c4 (patch) | |
| tree | 009579e4b0046b48c85edc353d8ddf6dbfbeaf53 /lib/strutils.c | |
| parent | f1e7f7d54e232ceba0c739633183a0608529fb90 (diff) | |
| download | util-linux-477254da9325b6c12975063023bded77c96dc1c4.tar.gz | |
lib/strutils: add strtotimeval_or_err()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib/strutils.c')
| -rw-r--r-- | lib/strutils.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/strutils.c b/lib/strutils.c index 53b589a41a..c263b86b27 100644 --- a/lib/strutils.c +++ b/lib/strutils.c @@ -333,6 +333,16 @@ uintmax_t strtosize_or_err(const char *str, const char *errmesg) errx(STRTOXX_EXIT_CODE, "%s: '%s'", errmesg, str); } + +void strtotimeval_or_err(const char *str, struct timeval *tv, const char *errmesg) +{ + double user_input; + + user_input = strtod_or_err(str, errmesg); + tv->tv_sec = (time_t) user_input; + tv->tv_usec = (long)((user_input - tv->tv_sec) * 1000000); +} + /* * Converts stat->st_mode to ls(1)-like mode string. The size of "str" must * be 10 bytes. |
