Fix compile error on some platform

This commit is contained in:
Tindy X committed 2020-02-19 22:52:50 +08:00
1 parent 19742630f5
commit 452c9299f1
3 files changed
+33 -15

No files matched your search

+25 -11
View File
@@ -8,8 +8,11 @@
#include <yaml-cpp/yaml.h> #include <yaml-cpp/yaml.h>
#ifdef _WIN32 #ifdef _WIN32
#include <unistd.h>
#define PATH_SLASH "\\" #define PATH_SLASH "\\"
#else #else
#include <sys/types.h>
#include <sys/stat.h>
#define PATH_SLASH "//" #define PATH_SLASH "//"
#endif // _WIN32 #endif // _WIN32
@@ -18,9 +21,9 @@ typedef std::vector<std::string> string_array;
typedef const std::string &refCnstStr; typedef const std::string &refCnstStr;
static const std::string base64_chars = static const std::string base64_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz" "abcdefghijklmnopqrstuvwxyz"
"0123456789+/"; "0123456789+/";
std::string UrlEncode(const std::string& str); std::string UrlEncode(const std::string& str);
std::string UrlDecode(const std::string& str); std::string UrlDecode(const std::string& str);
@@ -70,11 +73,13 @@ static inline bool strFind(const std::string &str, const std::string &target)
return str.find(target) != str.npos; return str.find(target) != str.npos;
} }
static inline bool startsWith(const std::string &hay, const std::string &needle) { static inline bool startsWith(const std::string &hay, const std::string &needle)
{
return hay.substr(0, needle.length()) == needle; return hay.substr(0, needle.length()) == needle;
} }
static inline bool endsWith(const std::string &hay, const std::string &needle) { static inline bool endsWith(const std::string &hay, const std::string &needle)
{
std::string::size_type hl = hay.length(), nl = needle.length(); std::string::size_type hl = hay.length(), nl = needle.length();
return hl >= nl && hay.substr(hl - nl, nl) == needle; return hl >= nl && hay.substr(hl - nl, nl) == needle;
} }
@@ -108,15 +113,24 @@ int to_int(const std::string &str, int def_value = 0);
#ifndef HAVE_TO_STRING #ifndef HAVE_TO_STRING
namespace std namespace std
{ {
template <typename T> std::string to_string(const T& n) template <typename T> std::string to_string(const T& n)
{ {
std::ostringstream ss; std::ostringstream ss;
ss << n; ss << n;
return ss.str(); return ss.str();
} }
} }
#endif // HAVE_TO_STRING #endif // HAVE_TO_STRING
static inline int md(const char *path)
{
#ifdef _WIN32
return mkdir(path);
#else
return mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
#endif // _WIN32
}
#ifdef _WIN32 #ifdef _WIN32
void StringToWstring(std::wstring& szDst, const std::string &str); void StringToWstring(std::wstring& szDst, const std::string &str);
#endif // _WIN32 #endif // _WIN32
+1 -1
View File
@@ -1796,7 +1796,7 @@ std::string netchToSSD(std::vector<nodeInfo> &nodes, std::string &group, std::st
const time_t rawtime = to_int(expiry); const time_t rawtime = to_int(expiry);
char buffer[30]; char buffer[30];
struct tm *dt = localtime(&rawtime); struct tm *dt = localtime(&rawtime);
strftime(buffer, sizeof(buffer), "%F %R", dt); strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M", dt);
writer.Key("expiry"); writer.Key("expiry");
writer.String(buffer); writer.String(buffer);
} }
+7 -3
View File
@@ -9,6 +9,10 @@
#include "misc.h" #include "misc.h"
#include "logger.h" #include "logger.h"
#ifdef _WIN32
#define _stat stat
#endif // _WIN32
extern bool print_debug_info; extern bool print_debug_info;
//std::string user_agent_str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"; //std::string user_agent_str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36";
@@ -89,11 +93,11 @@ std::string webGet(std::string url, std::string proxy, std::string &response_hea
// cache system // cache system
if(cache_ttl > 0) if(cache_ttl > 0)
{ {
mkdir("cache"); md("cache");
std::string url_md5 = getMD5(url); std::string url_md5 = getMD5(url);
std::string path = "cache/" + url_md5; std::string path = "cache/" + url_md5;
struct _stat result; struct stat result;
if(_stat(path.data(), &result) == 0) if(stat(path.data(), &result) == 0)
{ {
time_t mtime = result.st_mtime, now = time(NULL); time_t mtime = result.st_mtime, now = time(NULL);
if(difftime(now, mtime) <= cache_ttl) if(difftime(now, mtime) <= cache_ttl)