From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 1181 invoked from network); 26 May 2023 09:36:26 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 26 May 2023 09:36:26 -0000 Received: (qmail 32391 invoked by uid 550); 26 May 2023 09:36:23 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 32359 invoked from network); 26 May 2023 09:36:22 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=0W+367goxlV3bHVdV2KAftFGbpC4VOk9mtX42QoyXdE=; b=i+mIhKbmfQ+pMG30u+bnBSe8clGKQPbKmV6ipcNS/CuhMJaGkR+00AE2 r33TFXnO59kpWCtG1PBYh2XVRTj8FXWVZAqC5J3t10k+KsBOFiumdmGlx v3qgolrY76knQZjo2d5D0yq/5PrVY/At0SOQT7zRj7nbKaMtaReoNGF0/ A=; Authentication-Results: mail3-relais-sop.national.inria.fr; dkim=none (message not signed) header.i=none; spf=SoftFail smtp.mailfrom=Jens.Gustedt@inria.fr; dmarc=fail (p=none dis=none) d=inria.fr X-IronPort-AV: E=Sophos;i="6.00,193,1681164000"; d="scan'208";a="57085555" From: Jens Gustedt To: musl@lists.openwall.com Date: Fri, 26 May 2023 11:35:51 +0200 Message-Id: <59f95d06c1294c74217358bda83757b61740bda4.1684932978.git.Jens.Gustedt@inria.fr> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [musl] [C23 time 1/1] C23: add timespec_getres and deprecate asctime and ctime The identifier timespec_getres was not reserved before so we have to protect it against includes by older C versions and make the symbol weak, so it doesn't conflict with potential user code. The implementation just uses clock_getres underneath, which forces that function also to be weak such that we don't link with that symbol accidentally in pure C mode. Deprecate asctime and ctime. These are also deprecated by POSIX, so there should not be a conflict between the two standards. Also, use the __STDC_VERSION_TIME_H__ macro, this still have to be adapted to the final value that will be decided by WG14 for __STDC_VERSION__. --- include/time.h | 9 +++++---- src/time/clock_getres.c | 4 +++- src/time/timespec_getres.c | 12 ++++++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 src/time/timespec_getres.c diff --git a/include/time.h b/include/time.h index e94b3a01..074a64e1 100644 --- a/include/time.h +++ b/include/time.h @@ -1,5 +1,5 @@ -#ifndef _TIME_H -#define _TIME_H +#ifndef __STDC_VERSION_TIME_H__ +#define __STDC_VERSION_TIME_H__ 202300L #ifdef __cplusplus extern "C" { @@ -58,8 +58,8 @@ time_t mktime (struct tm *); size_t strftime (char *__restrict, size_t, const char *__restrict, const struct tm *__restrict); struct tm *gmtime (const time_t *); struct tm *localtime (const time_t *); -char *asctime (const struct tm *); -char *ctime (const time_t *); +__deprecated char *asctime(const struct tm *); +__deprecated char *ctime(const time_t *); int timespec_get(struct timespec *, int); #define CLOCKS_PER_SEC 1000000L @@ -69,6 +69,7 @@ int timespec_get(struct timespec *, int); struct tm *gmtime_r (const time_t *__restrict, struct tm *__restrict); struct tm *localtime_r (const time_t *__restrict, struct tm *__restrict); time_t timegm(struct tm *); +int timespec_getres(struct timespec *, int); #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ diff --git a/src/time/clock_getres.c b/src/time/clock_getres.c index 81c67037..248e6d18 100644 --- a/src/time/clock_getres.c +++ b/src/time/clock_getres.c @@ -1,7 +1,7 @@ #include #include "syscall.h" -int clock_getres(clockid_t clk, struct timespec *ts) +int __clock_getres(clockid_t clk, struct timespec *ts) { #ifdef SYS_clock_getres_time64 /* On a 32-bit arch, use the old syscall if it exists. */ @@ -19,3 +19,5 @@ int clock_getres(clockid_t clk, struct timespec *ts) * 32-bit arch and we can get result directly into timespec. */ return syscall(SYS_clock_getres, clk, ts); } + +weak_alias(__clock_getres, clock_getres); diff --git a/src/time/timespec_getres.c b/src/time/timespec_getres.c new file mode 100644 index 00000000..6ecbbdc4 --- /dev/null +++ b/src/time/timespec_getres.c @@ -0,0 +1,12 @@ +#include + +extern int __clock_getres(clockid_t clk, struct timespec *ts); + +/* There is no other implemented value than TIME_UTC; all other values + * are considered erroneous. */ +int timespec_getres(struct timespec * ts, int base) +{ + if (base != TIME_UTC) return 0; + int ret = __clock_getres(CLOCK_REALTIME, ts); + return ret < 0 ? 0 : base; +} -- 2.34.1