blob: da9b08dd80d823a5f181a92a0c61cfb9591a4c50 (
plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/*
sys/sys.cc
This file is part of the Osirion project and is distributed under
the terms of the GNU General Public License version 2
*/
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/types.h>
#endif
#include <stdlib.h>
#include <string>
#include "sys/sys.h"
namespace sys {
void mkdir(std::string const &path)
{
#ifdef _WIN32
/*
std::string p(path);
for (size_t i = 0; i < p.size(); i++)
if (p[i] == '/') p[i] = '\\';
mkdir(p.c_str());
*/
#else
::mkdir(path.c_str(), 0777);
#endif
}
void signal(int signum, signalfunc handler)
{
#ifndef _WIN32
struct sigaction sa;
sa.sa_sigaction = 0;
memset(&sa.sa_mask, 0 ,sizeof(sigset_t));
sa.sa_flags = 0;
sa.sa_handler = handler;
::sigaction(signum, &sa, 0);
#endif
}
unsigned long time()
{
#ifndef _WIN32
struct ::tm localtime;
time_t epochtime = ::time(0);
::localtime_r(&epochtime, &localtime);
return ((unsigned long) (localtime.tm_sec + localtime.tm_min*60 + localtime.tm_hour*3600));
#else
return 0;
#endif
}
void sleep(float seconds)
{
#ifndef _WIN32
::usleep((useconds_t) (seconds * 1000000.0f) );
#else
Sleep((DWORD) (seconds*1000.0f));
#endif
}
void quit(int status) {
::exit(status);
}
}
|