From patchwork Sun Mar 12 16:59:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Thomas X-Patchwork-Id: 1755920 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=uclibc-ng.org (client-ip=2a00:1828:2000:679::23; helo=helium.openadk.org; envelope-from=devel-bounces@uclibc-ng.org; receiver=) X-Greylist: delayed 420 seconds by postgrey-1.36 at legolas; Mon, 13 Mar 2023 04:07:44 AEDT Received: from helium.openadk.org (helium.openadk.org [IPv6:2a00:1828:2000:679::23]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PZR7447MQz1yWn for ; Mon, 13 Mar 2023 04:07:44 +1100 (AEDT) Received: from helium.openadk.org (localhost [IPv6:::1]) by helium.openadk.org (Postfix) with ESMTP id DE9C53520921; Sun, 12 Mar 2023 18:00:29 +0100 (CET) Received: from blackhole.midnightspark.net (unknown [62.3.122.141]) by helium.openadk.org (Postfix) with ESMTPS id 34A623520760 for ; Sun, 12 Mar 2023 17:59:22 +0100 (CET) Received: from blackhole.midnightspark.net (localhost [127.0.0.1]) by blackhole.midnightspark.net (OpenSMTPD) with ESMTP id 1377b7e8 for ; Sun, 12 Mar 2023 16:59:21 +0000 (UTC) Received: from [192.168.0.20] ([80.235.239.210]) by blackhole.midnightspark.net with ESMTPSA id EhJMGOkEDmRpgwQAPKhDDg (envelope-from ) for ; Sun, 12 Mar 2023 16:59:21 +0000 Date: Sun, 12 Mar 2023 16:59:15 +0000 From: Elliot Thomas To: devel@uclibc-ng.org Message-Id: X-Mailer: geary/43.0 MIME-Version: 1.0 Message-ID-Hash: RQX26ZXGGSIFI4HEPZIQNQCKQMK6RQA5 X-Message-ID-Hash: RQX26ZXGGSIFI4HEPZIQNQCKQMK6RQA5 X-MailFrom: elliot@midnightspark.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list Subject: [uclibc-ng-devel] Implement 'futimesat' function for architectures where Linux does not provide a futimesat syscall. List-Id: uClibc-ng Development Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Recently I tried compiling QEMU user emulation with uClibc on Aarch64, and found the 'futimesat' symbol was missing (but still defined in headers). This emulation is similar to the 'lutimesat' emulation. Regards, Elliot. From 60d600b56627cceace22da19ea3803aa7ab6bcf2 Mon Sep 17 00:00:00 2001 From: Elliot Thomas Date: Mon, 6 Mar 2023 01:21:05 +0000 Subject: [PATCH] Emulate 'futimesat' when __NR_futimesat is not available. --- libc/sysdeps/linux/common/futimesat.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/libc/sysdeps/linux/common/futimesat.c b/libc/sysdeps/linux/common/futimesat.c index bd73eae7e..fd19fea7c 100644 --- a/libc/sysdeps/linux/common/futimesat.c +++ b/libc/sysdeps/linux/common/futimesat.c @@ -11,6 +11,28 @@ #ifdef __NR_futimesat _syscall3(int, futimesat, int, fd, const char *, file, const struct timeval *, tvp) -#else -/* should add emulation with futimes() and /proc/self/fd/ ... */ +#elif defined __NR_utimensat +#include +#define __need_NULL +#include + +int futimesat(int dirfd, const char *file, const struct timeval tvp[2]) +{ + struct timespec ts[2]; + + if (tvp != NULL) + { + if (tvp[0].tv_usec < 0 || tvp[0].tv_usec >= 1000000 + || tvp[1].tv_usec < 0 || tvp[1].tv_usec >= 1000000) + { + __set_errno(EINVAL); + return -1; + } + + TIMEVAL_TO_TIMESPEC(&tvp[0], &ts[0]); + TIMEVAL_TO_TIMESPEC(&tvp[1], &ts[1]); + } + + return utimensat(dirfd, file, tvp ? ts : NULL, 0); +} #endif -- 2.39.2