libbsd: Move lutimes to bsd compat
* Rework be149e8ccf since lutimes isn't posix
This commit is contained in:
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016-2017 Haiku, Inc. All Rights Reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef _BSD_SYS_TIME_H_
|
||||||
|
#define _BSD_SYS_TIME_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include_next <sys/time.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef _BSD_SOURCE
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int lutimes(const char *path, const struct timeval times[2]);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* _BSD_SYS_TIME_H_ */
|
||||||
@@ -44,7 +44,6 @@ extern int setitimer(int which, const struct itimerval *value, struct itimerval
|
|||||||
extern int gettimeofday(struct timeval *tv, void *tz);
|
extern int gettimeofday(struct timeval *tv, void *tz);
|
||||||
|
|
||||||
extern int utimes(const char *path, 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 */
|
/* legacy */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
|||||||
fgetln.c
|
fgetln.c
|
||||||
getpass.c
|
getpass.c
|
||||||
issetugid.c
|
issetugid.c
|
||||||
|
lutimes.c
|
||||||
progname.c
|
progname.c
|
||||||
pty.cpp
|
pty.cpp
|
||||||
signal.c
|
signal.c
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright, 2016-2017 Haiku, Inc. All rights reserved.
|
||||||
|
* Released under the terms of the MIT license.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Alexander von Gluck IV, [email protected]
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
#include <OS.h>
|
||||||
|
|
||||||
|
|
||||||
|
extern int _utimes(const char* path, const struct timeval times[2],
|
||||||
|
bool traverseLink);
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
lutimes(const char* path, const struct timeval times[2])
|
||||||
|
{
|
||||||
|
return _utimes(path, times, false);
|
||||||
|
}
|
||||||
@@ -17,7 +17,10 @@
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
utimes(const char* path, const struct timeval times[2])
|
_utimes(const char* path, const struct timeval times[2], bool traverseLink);
|
||||||
|
|
||||||
|
extern int
|
||||||
|
_utimes(const char* path, const struct timeval times[2], bool traverseLink)
|
||||||
{
|
{
|
||||||
struct stat stat;
|
struct stat stat;
|
||||||
status_t status;
|
status_t status;
|
||||||
@@ -35,36 +38,17 @@ utimes(const char* path, const struct timeval times[2])
|
|||||||
}
|
}
|
||||||
|
|
||||||
// traverseLeafLink == true
|
// traverseLeafLink == true
|
||||||
status = _kern_write_stat(-1, path, true, &stat, sizeof(struct stat),
|
status = _kern_write_stat(-1, path, traverseLink, &stat,
|
||||||
B_STAT_MODIFICATION_TIME | B_STAT_ACCESS_TIME);
|
sizeof(struct stat), B_STAT_MODIFICATION_TIME | B_STAT_ACCESS_TIME);
|
||||||
|
|
||||||
RETURN_AND_SET_ERRNO(status);
|
RETURN_AND_SET_ERRNO(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
lutimes(const char* path, const struct timeval times[2])
|
utimes(const char* path, const struct timeval times[2])
|
||||||
{
|
{
|
||||||
struct stat stat;
|
return _utimes(path, times, true);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user