libroot/posix: Add lutimes for better posix compatibility

* Didn't exist on BeOS, but exists most other places.
* Update times of a file, not following symbolic links.
This commit is contained in:
Alexander von Gluck IV 2017-11-16 00:38:16 -06:00
parent f69a80b4bb
commit be149e8ccf
2 changed files with 29 additions and 1 deletions

View File

@ -43,7 +43,8 @@ extern int getitimer(int which, struct itimerval *value);
extern int setitimer(int which, const struct itimerval *value, struct itimerval *oldValue);
extern int gettimeofday(struct timeval *tv, void *tz);
extern int utimes(const char *name, const struct timeval times[2]);
extern int utimes(const char *path, const struct timeval times[2]);
extern int lutimes(const char *path, const struct timeval times[2]);
/* legacy */
#ifdef __cplusplus

View File

@ -34,6 +34,7 @@ utimes(const char* path, const struct timeval times[2])
stat.st_atim.tv_nsec = stat.st_mtim.tv_nsec = (now % 1000000) * 1000;
}
// traverseLeafLink == true
status = _kern_write_stat(-1, path, true, &stat, sizeof(struct stat),
B_STAT_MODIFICATION_TIME | B_STAT_ACCESS_TIME);
@ -41,6 +42,32 @@ utimes(const char* path, const struct timeval times[2])
}
int
lutimes(const char* path, const struct timeval times[2])
{
struct stat stat;
status_t status;
if (times != NULL) {
stat.st_atim.tv_sec = times[0].tv_sec;
stat.st_atim.tv_nsec = times[0].tv_usec * 1000;
stat.st_mtim.tv_sec = times[1].tv_sec;
stat.st_mtim.tv_nsec = times[1].tv_usec * 1000;
} else {
bigtime_t now = real_time_clock_usecs();
stat.st_atim.tv_sec = stat.st_mtim.tv_sec = now / 1000000;
stat.st_atim.tv_nsec = stat.st_mtim.tv_nsec = (now % 1000000) * 1000;
}
// traverseLeafLink == false
status = _kern_write_stat(-1, path, false, &stat, sizeof(struct stat),
B_STAT_MODIFICATION_TIME | B_STAT_ACCESS_TIME);
RETURN_AND_SET_ERRNO(status);
}
int
utimensat(int fd, const char *path, const struct timespec times[2], int flag)
{