flatten 20260225
This commit is contained in:
74
tjp/core/file/times.cpp
Normal file
74
tjp/core/file/times.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
// TJP COPYRIGHT HEADER
|
||||
|
||||
|
||||
#ifdef TJP_CORE_HEADER_ONLY
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <tjp/core/header_only/compile.h>
|
||||
|
||||
#include "times.hpp"
|
||||
#include <tjp/core/exception/Exception.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
#include <sys/stat.h>
|
||||
#include <utime.h>
|
||||
|
||||
|
||||
namespace tjp::core::file {
|
||||
|
||||
TJP_CORE_HEADER_ONLY_INLINE
|
||||
time_t getFileLastModifiedTime(const String & fullFileName)
|
||||
{
|
||||
struct stat status;
|
||||
|
||||
int result = stat(fullFileName.c_str(), &status);
|
||||
|
||||
if (result != 0)
|
||||
return 0;
|
||||
|
||||
return status.st_mtime;
|
||||
}
|
||||
|
||||
TJP_CORE_HEADER_ONLY_INLINE
|
||||
bool setFileLastModifiedTime(const String & fullFileName, time_t time)
|
||||
{
|
||||
struct utimbuf timbuf;
|
||||
timbuf.actime = getFileAccessTime(fullFileName);
|
||||
timbuf.modtime = time;
|
||||
|
||||
int result = utime(fullFileName.c_str(), &timbuf);
|
||||
|
||||
if (result != 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
TJP_CORE_HEADER_ONLY_INLINE
|
||||
time_t getFileCreationTime (const String & fullFileName)
|
||||
{
|
||||
struct stat status;
|
||||
|
||||
int result = stat(fullFileName.c_str(), &status);
|
||||
|
||||
if (result != 0)
|
||||
return 0;
|
||||
|
||||
return status.st_ctime;
|
||||
}
|
||||
|
||||
TJP_CORE_HEADER_ONLY_INLINE
|
||||
time_t getFileAccessTime (const String & fullFileName)
|
||||
{
|
||||
struct stat status;
|
||||
|
||||
int result = stat(fullFileName.c_str(), &status);
|
||||
|
||||
if (result != 0)
|
||||
return 0;
|
||||
|
||||
return status.st_atime;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user