mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:17:36 +00:00
LibC: Add lutimes(2)
and futimes(2)
implementations
Needed for a port of nix
This commit is contained in:
parent
c6c0ce78f5
commit
b8c847a3cd
2 changed files with 30 additions and 4 deletions
|
@ -20,7 +20,9 @@ struct timezone {
|
|||
int adjtime(const struct timeval* delta, struct timeval* old_delta);
|
||||
int gettimeofday(struct timeval* __restrict__, void* __restrict__);
|
||||
int settimeofday(struct timeval* __restrict__, void* __restrict__);
|
||||
int utimes(char const* pathname, const struct timeval[2]);
|
||||
int utimes(char const* pathname, struct timeval const times[2]);
|
||||
int lutimes(char const* pathname, struct timeval const times[2]);
|
||||
int futimes(int fd, struct timeval const times[2]);
|
||||
|
||||
static inline void timeradd(const struct timeval* a, const struct timeval* b, struct timeval* out)
|
||||
{
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <assert.h>
|
||||
#include <bits/pthread_cancel.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
@ -77,16 +78,39 @@ int settimeofday(struct timeval* __restrict__ tv, void* __restrict__)
|
|||
return clock_settime(CLOCK_REALTIME, &ts);
|
||||
}
|
||||
|
||||
int utimes(char const* pathname, const struct timeval times[2])
|
||||
int utimes(char const* pathname, struct timeval const times[2])
|
||||
{
|
||||
if (!times) {
|
||||
if (!times)
|
||||
return utime(pathname, nullptr);
|
||||
}
|
||||
// FIXME: implement support for tv_usec in the utime (or a new) syscall
|
||||
utimbuf buf = { times[0].tv_sec, times[1].tv_sec };
|
||||
return utime(pathname, &buf);
|
||||
}
|
||||
|
||||
// Not in POSIX, originated in BSD but also supported on Linux.
|
||||
// https://man.netbsd.org/NetBSD-6.0/lutimes.2
|
||||
int lutimes(char const* pathname, struct timeval const times[2])
|
||||
{
|
||||
if (!times)
|
||||
return utimensat(AT_FDCWD, pathname, nullptr, AT_SYMLINK_NOFOLLOW);
|
||||
timespec ts[2];
|
||||
TIMEVAL_TO_TIMESPEC(×[0], &ts[0]);
|
||||
TIMEVAL_TO_TIMESPEC(×[1], &ts[1]);
|
||||
return utimensat(AT_FDCWD, pathname, ts, AT_SYMLINK_NOFOLLOW);
|
||||
}
|
||||
|
||||
// Not in POSIX, originated in BSD but also supported on Linux.
|
||||
// https://man.netbsd.org/NetBSD-6.0/futimes.2
|
||||
int futimes(int fd, struct timeval const times[2])
|
||||
{
|
||||
if (!times)
|
||||
return utimensat(fd, nullptr, nullptr, 0);
|
||||
timespec ts[2];
|
||||
TIMEVAL_TO_TIMESPEC(×[0], &ts[0]);
|
||||
TIMEVAL_TO_TIMESPEC(×[1], &ts[1]);
|
||||
return utimensat(fd, nullptr, ts, 0);
|
||||
}
|
||||
|
||||
char* ctime(time_t const* t)
|
||||
{
|
||||
return asctime(localtime(t));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue