added cross-platform
This commit is contained in:
@@ -3,8 +3,14 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#if __cplusplus >= 201703L
|
||||
#include <filesystem>
|
||||
#endif
|
||||
|
||||
#include "String.h"
|
||||
|
||||
class Utils {
|
||||
@@ -16,31 +22,39 @@ public:
|
||||
return (a > b) ? b : a;
|
||||
}
|
||||
static void Mkdir(const String& path) {
|
||||
#if __cplusplus >= 201703L
|
||||
std::filesystem::create_directory(path.getCharArray());
|
||||
#else
|
||||
mkdir(path.getCharArray(), 0777);
|
||||
#endif
|
||||
}
|
||||
|
||||
//https://stackoverflow.com/questions/4568681/using-chmod-in-a-c-program
|
||||
static void Chmod(const String& path) {
|
||||
String command = "chmod 777 " + String::DQuotes(path);
|
||||
system(command.getCharArray());
|
||||
}
|
||||
|
||||
//https://stackoverflow.com/questions/230062/whats-the-best-way-to-check-if-a-file-exists-in-c
|
||||
static bool Exists(const String& path) {
|
||||
struct stat buffer;
|
||||
return (stat(path.getCharArray(), &buffer) == 0);
|
||||
}
|
||||
|
||||
//in seconds
|
||||
static void Sleep(int s) {
|
||||
usleep(s * 1000000);
|
||||
std::chrono::seconds timespan(s);
|
||||
std::this_thread::sleep_for(timespan);
|
||||
}
|
||||
static void Copy(const String& src, const String& dst) {
|
||||
String command = "cp " + String::DQuotes(src) + " " + String::DQuotes(dst);
|
||||
system(command.getCharArray());
|
||||
}
|
||||
static long getAbsoluteTime() {
|
||||
static time_t getAbsoluteTime() {
|
||||
return time(NULL);
|
||||
}
|
||||
static String getDate() {
|
||||
long int ttime;
|
||||
ttime = time(NULL);
|
||||
auto ttime = time(NULL);
|
||||
String res(ctime(&ttime));
|
||||
return res;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user