summaryrefslogtreecommitdiff
path: root/lib/win32/emu.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/win32/emu.h')
-rw-r--r--lib/win32/emu.h97
1 files changed, 47 insertions, 50 deletions
diff --git a/lib/win32/emu.h b/lib/win32/emu.h
index bf408050..91793004 100644
--- a/lib/win32/emu.h
+++ b/lib/win32/emu.h
@@ -18,7 +18,14 @@
#define EMU_INCLUDE
// Need feature detection macros below
-#include "../common/BoxConfig.h"
+#if defined BOX_CMAKE
+# include "../common/BoxConfig.cmake.h"
+#elif defined _MSC_VER
+# include "../common/BoxConfig-MSVC.h"
+# define NEED_BOX_VERSION_H
+#else
+# include "../common/BoxConfig.h"
+#endif
// Shut up stupid new warnings. Thanks MinGW! Ever heard of "compatibility"?
#ifdef __MINGW32__
@@ -27,31 +34,21 @@
// basic types, may be required by other headers since we
// don't include sys/types.h
-
-#ifdef __MINGW32__
- #include <stdint.h>
-#else // MSVC
- typedef unsigned __int64 u_int64_t;
- typedef unsigned __int64 uint64_t;
- typedef __int64 int64_t;
- typedef unsigned __int32 uint32_t;
- typedef unsigned __int32 u_int32_t;
- typedef __int32 int32_t;
- typedef unsigned __int16 uint16_t;
- typedef __int16 int16_t;
- typedef unsigned __int8 uint8_t;
- typedef __int8 int8_t;
-#endif
+#include <stdint.h>
// emulated types, present on MinGW but not MSVC or vice versa
-#ifdef __MINGW32__
- typedef uint32_t u_int32_t;
-#else
+#ifndef __MINGW32__
typedef unsigned int mode_t;
typedef unsigned int pid_t;
+ typedef unsigned int uid_t;
+ typedef unsigned int gid_t;
#endif
+// Disable Windows' non-standard implementation of min() and max():
+// http://stackoverflow.com/a/5004874/648162
+#define NOMINMAX
+
// Windows headers
#include <winsock2.h>
@@ -76,17 +73,6 @@
#define ITIMER_REAL 0
-#ifdef _MSC_VER
-// Microsoft decided to deprecate the standard POSIX functions. Great!
-#define open(file,flags,mode) _open(file,flags,mode)
-#define close(fd) _close(fd)
-#define dup(fd) _dup(fd)
-#define read(fd,buf,count) _read(fd,buf,count)
-#define write(fd,buf,count) _write(fd,buf,count)
-#define lseek(fd,off,whence) _lseek(fd,off,whence)
-#define fileno(struct_file) _fileno(struct_file)
-#endif
-
struct passwd {
char *pw_name;
char *pw_passwd;
@@ -110,26 +96,34 @@ inline struct passwd * getpwnam(const char * name)
return &gTempPasswd;
}
-#define S_IRWXG 1
-#define S_IRWXO 2
-#define S_ISUID 4
-#define S_ISGID 8
-#define S_ISVTX 16
-
-#ifndef __MINGW32__
+#ifndef S_IRGRP
+ // these constants are only defined in MinGW64, not the original MinGW headers,
+ // nor MSVC, so use poor man's feature detection to define them only if needed.
//not sure if these are correct
//S_IWRITE - writing permitted
//_S_IREAD - reading permitted
//_S_IREAD | _S_IWRITE -
- #define S_IRUSR S_IWRITE
- #define S_IWUSR S_IREAD
- #define S_IRWXU (S_IREAD|S_IWRITE|S_IEXEC)
+# define S_IRUSR S_IWRITE
+# define S_IWUSR S_IREAD
+# define S_IRGRP S_IWRITE
+# define S_IWGRP S_IREAD
+# define S_IROTH S_IWRITE | S_IREAD
+# define S_IWOTH S_IREAD | S_IREAD
+# define S_IRWXU (S_IREAD|S_IWRITE|S_IEXEC)
+# define S_IRWXG 1
+# define S_IRWXO 2
+#endif
+#define S_ISUID 4
+#define S_ISGID 8
+#define S_ISVTX 16
+
+#ifndef __MINGW32__
#define S_ISREG(x) (S_IFREG & x)
#define S_ISDIR(x) (S_IFDIR & x)
#endif
-inline int chown(const char * Filename, u_int32_t uid, u_int32_t gid)
+inline int chown(const char * Filename, uint32_t uid, uint32_t gid)
{
//important - this needs implementing
//If a large restore is required then
@@ -183,7 +177,7 @@ inline int geteuid(void)
// MinGW provides a getopt implementation
#ifndef __MINGW32__
-#include "getopt.h"
+#include "box_getopt.h"
#endif // !__MINGW32__
#define timespec timeval
@@ -195,11 +189,6 @@ inline int geteuid(void)
typedef int socklen_t;
#endif
-#define S_IRGRP S_IWRITE
-#define S_IWGRP S_IREAD
-#define S_IROTH S_IWRITE | S_IREAD
-#define S_IWOTH S_IREAD | S_IREAD
-
//again need to verify these
#define S_IFLNK 1
#define S_IFSOCK 0
@@ -209,9 +198,14 @@ inline int geteuid(void)
#define vsnprintf _vsnprintf
#ifndef __MINGW32__
+#define snprintf _snprintf
inline int strcasecmp(const char *s1, const char *s2)
{
- return _stricmp(s1,s2);
+ return _stricmp(s1, s2);
+}
+inline int strncasecmp(const char *s1, const char *s2, size_t count)
+{
+ return _strnicmp(s1, s2, count);
}
#endif
@@ -238,7 +232,7 @@ struct dirent *readdir(DIR *dp);
int closedir(DIR *dp);
// local constant to open file exclusively without shared access
-#define O_LOCK 0x10000
+#define BOX_OPEN_LOCK 0x10000
extern DWORD winerrno; /* used to report errors from openfile() */
HANDLE openfile(const char *filename, int flags, int mode);
@@ -279,7 +273,7 @@ void syslog (int loglevel, const char *fmt, ...);
#define strtoll _strtoi64
#endif
-inline unsigned int sleep(unsigned int secs)
+extern "C" inline unsigned int sleep(unsigned int secs)
{
Sleep(secs*1000);
return(ERROR_SUCCESS);
@@ -347,6 +341,7 @@ bool ConvertTime_tToFileTime(const time_t from, FILETIME *pTo);
int emu_chdir (const char* pDirName);
int emu_mkdir (const char* pPathName);
+int emu_link (const char* pOldPath, const char* pNewPath);
int emu_unlink (const char* pFileName);
int emu_fstat (HANDLE file, struct emu_stat* st);
int emu_stat (const char* pName, struct emu_stat* st);
@@ -357,6 +352,7 @@ int emu_rename (const char* pOldName, const char* pNewName);
#define chdir(directory) emu_chdir (directory)
#define mkdir(path, mode) emu_mkdir (path)
+#define link(oldpath, newpath) emu_link (oldpath, newpath)
#define unlink(file) emu_unlink (file)
#define utimes(buffer, times) emu_utimes (buffer, times)
#define chmod(file, mode) emu_chmod (file, mode)
@@ -403,6 +399,7 @@ bool ConvertConsoleToUtf8(const std::string& rSource, std::string& rDest);
char* ConvertFromWideString(const WCHAR* pString, unsigned int codepage);
bool ConvertFromWideString(const std::wstring& rInput,
std::string* pOutput, unsigned int codepage);
+WCHAR* ConvertUtf8ToWideString(const char* pString);
std::string ConvertPathToAbsoluteUnicode(const char *pFileName);
// Utility function which returns a default config file name,