From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 6953513881E for ; Mon, 28 Sep 2015 20:17:11 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 6737A21C014; Mon, 28 Sep 2015 20:17:09 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 0CF6D21C014 for ; Mon, 28 Sep 2015 20:17:07 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id E39D534089F for ; Mon, 28 Sep 2015 20:17:06 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 6BCFA21C for ; Mon, 28 Sep 2015 20:17:04 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1443470417.6b0db7d9abfded8bdf8c7d061b261f053eec886d.vapier@gentoo> Subject: [gentoo-commits] proj/sandbox:master commit in: tests/ X-VCS-Repository: proj/sandbox X-VCS-Files: tests/test-skel-0.c tests/tests.h tests/utimensat-0.c X-VCS-Directories: tests/ X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: 6b0db7d9abfded8bdf8c7d061b261f053eec886d X-VCS-Branch: master Date: Mon, 28 Sep 2015 20:17:04 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 3c451811-88e7-4f09-9194-0711f5b2667f X-Archives-Hash: dcb13f2629f37231a76c0097b7f6e592 commit: 6b0db7d9abfded8bdf8c7d061b261f053eec886d Author: Mike Frysinger gentoo org> AuthorDate: Mon Sep 28 20:00:17 2015 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Mon Sep 28 20:00:17 2015 +0000 URL: https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=6b0db7d9 tests: add basic parsing of timespec fields Signed-off-by: Mike Frysinger gentoo.org> tests/test-skel-0.c | 23 ++++++++++++++++++++++- tests/tests.h | 3 +++ tests/utimensat-0.c | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/tests/test-skel-0.c b/tests/test-skel-0.c index dbe60db..96e42ae 100644 --- a/tests/test-skel-0.c +++ b/tests/test-skel-0.c @@ -9,7 +9,6 @@ const char *color_red = "\033[31;01m"; # define CONFIG 1 #endif -#define V_TIMESPEC "NULL" #define V_STRMODE "[+bcemx] (see `man 3 fopen`)" static bool _strtoul(const char *sul, unsigned long *ul) @@ -132,6 +131,28 @@ int at_get_fd(const char *str_dirfd) return open(str_path, f_get_flags(str_flags), sscanf_mode_t(str_mode)); } +#define V_TIMESPEC "NULL | NOW | #[,#]" +struct timespec *parse_timespec(const char *s) +{ + struct timespec *times; + + if (!strcmp(s, "NULL")) + return NULL; + + times = xzalloc(sizeof(*times)); + + if (!strcmp(s, "NOW")) { + times->tv_sec = time(0); + } else { + long sec = 0, nsec = 0; + sscanf(s, "%li,%li", &sec, &nsec); + times->tv_sec = sec; + times->tv_nsec = nsec; + } + + return times; +} + #define V_ACCESS_MODE "r | w | x | f" int access_mode(const char *s) { diff --git a/tests/tests.h b/tests/tests.h index 51dc68a..22733ca 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -10,6 +10,9 @@ #define err(fmt, args...) ({ _stderr_msg(fmt, ##args); exit(1); }) #define errp(fmt, args...) ({ _stderr_pmsg(fmt, ##args); exit(1); }) +#define xmalloc(size) ({ void *ret = malloc(size); assert(ret); ret; }) +#define xzalloc(size) ({ void *ret = xmalloc(size); memset(ret, 0, size); ret; }) + typedef struct { const char *name; int val; diff --git a/tests/utimensat-0.c b/tests/utimensat-0.c index 431d179..99c3fa4 100644 --- a/tests/utimensat-0.c +++ b/tests/utimensat-0.c @@ -14,7 +14,7 @@ const char *file = f_get_file(s); \ \ s = argv[i++]; \ - const struct timespec *times = NULL; \ + const struct timespec *times = parse_timespec(s); \ \ s = argv[i++]; \ int flags = at_get_flags(s);