Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libsnes/bsnes/nall/platform.hpp
2 views
1
#ifndef NALL_PLATFORM_HPP
2
#define NALL_PLATFORM_HPP
3
4
#if defined(_WIN32)
5
//minimum version needed for _wstat64, etc
6
#undef __MSVCRT_VERSION__
7
#define __MSVCRT_VERSION__ 0x0601
8
#include <nall/windows/utf8.hpp>
9
#endif
10
11
#ifdef _MSC_VER
12
#define _USE_MATH_DEFINES 1
13
#endif
14
15
//=========================
16
//standard platform headers
17
//=========================
18
19
#include <limits>
20
21
#include <assert.h>
22
#include <limits.h>
23
#include <math.h>
24
#include <stdarg.h>
25
#include <stdio.h>
26
#include <stdlib.h>
27
#include <string.h>
28
#include <time.h>
29
30
#include <sys/types.h>
31
#include <sys/stat.h>
32
33
#if defined(_WIN32)
34
#include <io.h>
35
#include <direct.h>
36
//#include <shlobj.h> //bizhawk chokes?
37
#include <wchar.h>
38
#undef interface
39
#define dllexport __declspec(dllexport)
40
//bad things happen without these here
41
#include <string>
42
#include <vector>
43
#else
44
#include <unistd.h>
45
#include <pwd.h>
46
#define dllexport
47
#endif
48
49
//==================
50
//warning supression
51
//==================
52
53
//Visual C++
54
#if defined(_MSC_VER)
55
//disable libc "deprecation" warnings
56
#pragma warning(disable:4996)
57
#endif
58
59
//================
60
//POSIX compliance
61
//================
62
63
#if defined(_MSC_VER)
64
#define PATH_MAX _MAX_PATH
65
#define va_copy(dest, src) ((dest) = (src))
66
#endif
67
68
#if defined(_WIN32)
69
#define getcwd _getcwd
70
#define ftruncate _chsize
71
#define mkdir(n, m) _wmkdir(nall::utf16_t(n))
72
#define putenv _putenv
73
#define rmdir _rmdir
74
#define vsnprintf _vsnprintf
75
inline void usleep(unsigned milliseconds) { Sleep(milliseconds / 1000); }
76
#endif
77
78
//================
79
//inline expansion
80
//================
81
82
#if defined(__GNUC__)
83
#define noinline __attribute__((noinline))
84
#define inline inline
85
#define alwaysinline inline __attribute__((always_inline))
86
#elif defined(_MSC_VER)
87
#define noinline __declspec(noinline)
88
#define inline inline
89
#define alwaysinline inline __forceinline
90
#else
91
#define noinline
92
#define inline inline
93
#define alwaysinline inline
94
#endif
95
96
//=========================
97
//file system functionality
98
//=========================
99
100
#if defined(_WIN32)
101
inline char* realpath(const char *filename, char *resolvedname) {
102
wchar_t fn[_MAX_PATH] = L"";
103
_wfullpath(fn, nall::utf16_t(filename), _MAX_PATH);
104
strcpy(resolvedname, nall::utf8_t(fn));
105
for(unsigned n = 0; resolvedname[n]; n++) if(resolvedname[n] == '\\') resolvedname[n] = '/';
106
return resolvedname;
107
}
108
109
inline char* userpath(char *path) {
110
//TODO BIZHAWK
111
return nullptr;
112
//wchar_t fp[_MAX_PATH] = L"";
113
//SHGetFolderPathW(0, CSIDL_APPDATA | CSIDL_FLAG_CREATE, 0, 0, fp);
114
//strcpy(path, nall::utf8_t(fp));
115
//for(unsigned n = 0; path[n]; n++) if(path[n] == '\\') path[n] = '/';
116
//unsigned length = strlen(path);
117
//if(path[length] != '/') strcpy(path + length, "/");
118
//return path;
119
}
120
121
inline char* getcwd(char *path) {
122
//TODO BIZHAWK
123
return nullptr;
124
//wchar_t fp[_MAX_PATH] = L"";
125
//_wgetcwd(fp, _MAX_PATH);
126
//strcpy(path, nall::utf8_t(fp));
127
//for(unsigned n = 0; path[n]; n++) if(path[n] == '\\') path[n] = '/';
128
//unsigned length = strlen(path);
129
//if(path[length] != '/') strcpy(path + length, "/");
130
//return path;
131
}
132
#else
133
//realpath() already exists
134
135
inline char* userpath(char *path) {
136
*path = 0;
137
struct passwd *userinfo = getpwuid(getuid());
138
if(userinfo) strcpy(path, userinfo->pw_dir);
139
unsigned length = strlen(path);
140
if(path[length] != '/') strcpy(path + length, "/");
141
return path;
142
}
143
144
inline char *getcwd(char *path) {
145
auto unused = getcwd(path, PATH_MAX);
146
unsigned length = strlen(path);
147
if(path[length] != '/') strcpy(path + length, "/");
148
return path;
149
}
150
#endif
151
152
#endif
153
154
155