mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
fix: add macos build patch for fs_get_creation_time
Signed-off-by: Rui Chen <rui@chenrui.dev>
This commit is contained in:
parent
8ead9337d1
commit
c37cc145d7
1 changed files with 16 additions and 7 deletions
23
src/fs.c
23
src/fs.c
|
|
@ -181,19 +181,27 @@ char* fs_search_directory(const char *dir_path, const char *dirname)
|
||||||
// Function to return creation time of file
|
// Function to return creation time of file
|
||||||
double fs_get_creation_time(const char *path)
|
double fs_get_creation_time(const char *path)
|
||||||
{
|
{
|
||||||
struct statx stx;
|
|
||||||
|
|
||||||
int fd = open(path, O_RDONLY);
|
#if defined(__APPLE__) || defined(__MACH__)
|
||||||
if (fd == -1)
|
// Use stat on macOS to access creation time
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
|
if (stat(path, &st) != 0)
|
||||||
{
|
{
|
||||||
// Error
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret = statx(fd, "", AT_EMPTY_PATH, STATX_ALL, &stx);
|
return st.st_birthtimespec.tv_sec + st.st_birthtimespec.tv_nsec / 1e9;
|
||||||
if (ret == -1)
|
#else
|
||||||
|
struct statx stx;
|
||||||
|
int fd = open(path, O_RDONLY);
|
||||||
|
if (fd == -1)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (statx(fd, "", AT_EMPTY_PATH, STATX_ALL, &stx) != 0)
|
||||||
{
|
{
|
||||||
// Error
|
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -202,4 +210,5 @@ double fs_get_creation_time(const char *path)
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
return stx.stx_btime.tv_sec + stx.stx_btime.tv_nsec / 1e9;
|
return stx.stx_btime.tv_sec + stx.stx_btime.tv_nsec / 1e9;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue