forked from dearlulu/hive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.cpp
67 lines (57 loc) · 1.24 KB
/
tools.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
** repository: https://github.com/trumanzhao/luna
** trumanzhao, 2016/10/19, [email protected]
*/
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <string.h>
#include <string>
#include <locale>
#include <cstdint>
#ifdef _MSC_VER
#include <windows.h>
#endif
#ifdef __linux
#include <unistd.h>
#include <dirent.h>
#endif
#ifdef __APPLE__
#include <unistd.h>
#include <mach/clock.h>
#include <mach/mach.h>
#endif
#include "tools.h"
time_t get_file_time(const char* file_name)
{
if (file_name == nullptr)
return 0;
struct stat file_info;
int ret = stat(file_name, &file_info);
if (ret != 0)
return 0;
#ifdef __APPLE__
return file_info.st_mtimespec.tv_sec;
#endif
#if defined(_MSC_VER) || defined(__linux)
return file_info.st_mtime;
#endif
}
char* get_error_string(char buffer[], int len, int no)
{
buffer[0] = '\0';
#ifdef _MSC_VER
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, no, 0, buffer, len, nullptr);
#endif
#if defined(__linux) || defined(__APPLE__)
strerror_r(no, buffer, len);
#endif
return buffer;
}
void get_error_string(std::string& err, int no)
{
char txt[MAX_ERROR_TXT];
get_error_string(txt, sizeof(txt), no);
err = txt;
}