75 lines
1.2 KiB
C++
75 lines
1.2 KiB
C++
// 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
|