[klibc] [PATCH] Fix implementation of utimes

Ben Hutchings ben at decadent.org.uk
Sun Dec 26 15:01:19 PST 2021


On Thu, 2021-12-09 at 16:42 -0800, Benjamin Gwin wrote:
> This was not correctly initializing the timespec array before passing it
> on to utimensat.
> 
> Tested: Built cpio and extracted an image with `cpio -im` to preserve
> mtime. The calls to utime now pass through the correct timestamps.
> 

Applied, thanks.

Ben.

> Signed-off-by: Benjamin Gwin <bgwin at google.com>
> ---
>  usr/klibc/utimes.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/usr/klibc/utimes.c b/usr/klibc/utimes.c
> index fd378a63..ce6d2f81 100644
> --- a/usr/klibc/utimes.c
> +++ b/usr/klibc/utimes.c
> @@ -10,8 +10,10 @@ int utimes(const char *file, const struct timeval tvp[2])
>  	struct timespec ts[2];
>  
>  	if (tvp) {
> -		ts->tv_sec = tvp->tv_sec;
> -		ts->tv_nsec = tvp->tv_usec * 1000;
> +		ts[0].tv_sec = tvp[0].tv_sec;
> +		ts[0].tv_nsec = tvp[0].tv_usec * 1000;
> +		ts[1].tv_sec = tvp[1].tv_sec;
> +		ts[1].tv_nsec = tvp[1].tv_usec * 1000;
>  	}
>  
>  	return utimensat(AT_FDCWD, file, &ts[0], 0);

-- 
Ben Hutchings
It is easier to write an incorrect program
than to understand a correct one.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <https://lists.zytor.com/archives/klibc/attachments/20211227/93df50d0/attachment.sig>


More information about the klibc mailing list