Skip to content

Commit

Permalink
Merge pull request #159 from g-maxime/datecreated
Browse files Browse the repository at this point in the history
Support for file creation date on Linux and macOS
  • Loading branch information
JeromeMartinez authored Sep 19, 2024
2 parents d14535b + 78d1df5 commit 73c60d9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
14 changes: 14 additions & 0 deletions Source/ZenLib/Conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@
#endif
#endif

//---------------------------------------------------------------------------
//Linux
#if defined(__LINUX__) || defined(__linux__)
#ifndef LINUX
#define LINUX
#endif
#ifndef _LINUX
#define _LINUX
#endif
#ifndef __LINUX__
#define __LINUX__ 1
#endif
#endif

//---------------------------------------------------------------------------
//MacOS Classic
#if defined(macintosh)
Expand Down
41 changes: 39 additions & 2 deletions Source/ZenLib/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
#include <sys/stat.h>
#if !defined(WINDOWS)
#include <unistd.h>
#if defined(LINUX)
#include <fcntl.h>
#include <sys/syscall.h>
#include <linux/stat.h>
#endif
#endif //!defined(WINDOWS)
#include <fstream>
using namespace std;
Expand Down Expand Up @@ -1080,7 +1085,23 @@ Ztring File::Created_Get()
return __T(""); //Not implemented
#else //ZENLIB_USEWX
#ifdef ZENLIB_STANDARD
return __T(""); //Not implemented
#if defined LINUX && defined STATX_BTIME
struct statx Stat;
int Result=statx(AT_FDCWD, File_Name.To_Local().c_str(), AT_STATX_SYNC_AS_STAT, STATX_BTIME, &Stat);
if (Result<0)
return __T(""); //Error
Ztring Time; Time.Date_From_Seconds_1970((int64s)Stat.stx_btime.tv_sec);
return Time;
#elif defined MACOS || defined MACOSX
struct stat Stat;
int Result=stat(File_Name.To_Local().c_str(), &Stat);
if (Result<0)
return __T(""); //Error
Ztring Time; Time.Date_From_Seconds_1970((int64s)Stat.st_birthtime);
return Time;
#else
return __T(""); //Not implemented
#endif //defined LINUX && defined STATX_BTIME
#elif defined WINDOWS
#ifdef WINDOWS_UWP
ComPtr<IStorageItem> Item;
Expand Down Expand Up @@ -1149,7 +1170,23 @@ Ztring File::Created_Local_Get()
return __T(""); //Not implemented
#else //ZENLIB_USEWX
#ifdef ZENLIB_STANDARD
return __T(""); //Not implemented
#if defined LINUX && defined STATX_BTIME
struct statx Stat;
int Result=statx(AT_FDCWD, File_Name.To_Local().c_str(), AT_STATX_SYNC_AS_STAT, STATX_BTIME, &Stat);
if (Result<0)
return __T(""); //Error
Ztring Time; Time.Date_From_Seconds_1970_Local(Stat.stx_btime.tv_sec);
return Time;
#elif defined MACOS || defined MACOSX
struct stat Stat;
int Result=stat(File_Name.To_Local().c_str(), &Stat);
if (Result<0)
return __T(""); //Error
Ztring Time; Time.Date_From_Seconds_1970_Local((int64s)Stat.st_birthtime);
return Time;
#else
return __T(""); //Not implemented
#endif //defined LINUX && defined STATX_BTIME
#elif defined WINDOWS
#ifdef WINDOWS_UWP
ComPtr<IStorageItem> Item;
Expand Down

0 comments on commit 73c60d9

Please sign in to comment.