Fixed various issues with compiling with VS2012

This commit is contained in:
Sam Surtees 2017-04-25 01:37:46 +10:00
parent 74b2f4680e
commit 8ac4955b22
6 changed files with 17 additions and 12 deletions

View File

@ -16,7 +16,7 @@ void buffer_init(Buffer* b)
b->data = NULL; b->data = NULL;
} }
void buffer_destroy(Buffer* b) void buffer_destroy(Buffer* b)
{ {
free(b->data); free(b->data);
b->capacity = 0; b->capacity = 0;
@ -53,12 +53,13 @@ void buffer_puts(Buffer* b, const void* ptr, size_t len)
b->length += len; b->length += len;
} }
void buffer_printf(Buffer* b, const char *fmt, ...) void buffer_printf(Buffer* b, const char *fmt, ...)
{ {
char text[2048]; char text[2048];
int len;
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
int len = vsnprintf(text, sizeof(text) - 1, fmt, args); len = vsnprintf(text, sizeof(text) - 1, fmt, args);
va_end(args); va_end(args);
buffer_puts(b, text, len); buffer_puts(b, text, len);
} }

View File

@ -11,8 +11,6 @@ int do_chdir(lua_State* L, const char* path)
{ {
int z; int z;
(void)(L); /* warning: unused parameter */
#if PLATFORM_WINDOWS #if PLATFORM_WINDOWS
wchar_t wide_buffer[PATH_MAX]; wchar_t wide_buffer[PATH_MAX];
if (MultiByteToWideChar(CP_UTF8, 0, path, -1, wide_buffer, PATH_MAX) == 0) if (MultiByteToWideChar(CP_UTF8, 0, path, -1, wide_buffer, PATH_MAX) == 0)
@ -23,6 +21,8 @@ int do_chdir(lua_State* L, const char* path)
z = SetCurrentDirectoryW(wide_buffer); z = SetCurrentDirectoryW(wide_buffer);
#else #else
(void)(L); /* warning: unused parameter */
z = !chdir(path); z = !chdir(path);
#endif #endif

View File

@ -67,7 +67,7 @@ int getKernelVersion(struct OsVersionInfo* info)
{ {
void* fixedInfoPtr; void* fixedInfoPtr;
UINT fixedInfoSize; UINT fixedInfoSize;
if (VerQueryValueA(data, "\\", &fixedInfoPtr, &fixedInfoSize)) if (VerQueryValueA(data, "\\", &fixedInfoPtr, &fixedInfoSize))
{ {
VS_FIXEDFILEINFO* fileInfo = (VS_FIXEDFILEINFO*)fixedInfoPtr; VS_FIXEDFILEINFO* fileInfo = (VS_FIXEDFILEINFO*)fixedInfoPtr;
info->majorversion = HIWORD(fileInfo->dwProductVersionMS); info->majorversion = HIWORD(fileInfo->dwProductVersionMS);
@ -82,10 +82,10 @@ int getKernelVersion(struct OsVersionInfo* info)
int getversion(struct OsVersionInfo* info) int getversion(struct OsVersionInfo* info)
{ {
HKEY key;
info->description = "Windows"; info->description = "Windows";
// First get a friendly product name from the registry. // First get a friendly product name from the registry.
HKEY key;
if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &key) == ERROR_SUCCESS) if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &key) == ERROR_SUCCESS)
{ {
char value[512]; char value[512];

View File

@ -18,10 +18,9 @@ int os_isfile(lua_State* L)
int do_isfile(lua_State* L, const char* filename) int do_isfile(lua_State* L, const char* filename)
{ {
(void)(L); /* warning: unused parameter */
#if PLATFORM_WINDOWS #if PLATFORM_WINDOWS
wchar_t wide_path[PATH_MAX]; wchar_t wide_path[PATH_MAX];
DWORD attrib;
if (MultiByteToWideChar(CP_UTF8, 0, filename, -1, wide_path, PATH_MAX) == 0) if (MultiByteToWideChar(CP_UTF8, 0, filename, -1, wide_path, PATH_MAX) == 0)
{ {
@ -29,13 +28,16 @@ int do_isfile(lua_State* L, const char* filename)
return lua_error(L); return lua_error(L);
} }
DWORD attrib = GetFileAttributesW(wide_path); attrib = GetFileAttributesW(wide_path);
if (attrib != INVALID_FILE_ATTRIBUTES) if (attrib != INVALID_FILE_ATTRIBUTES)
{ {
return (attrib & FILE_ATTRIBUTE_DIRECTORY) == 0; return (attrib & FILE_ATTRIBUTE_DIRECTORY) == 0;
} }
#else #else
struct stat buf; struct stat buf;
(void)(L); /* warning: unused parameter */
if (stat(filename, &buf) == 0) if (stat(filename, &buf) == 0)
{ {
return ((buf.st_mode & S_IFDIR) == 0); return ((buf.st_mode & S_IFDIR) == 0);

View File

@ -15,13 +15,14 @@ int os_islink(lua_State* L)
#if PLATFORM_WINDOWS #if PLATFORM_WINDOWS
{ {
wchar_t wide_path[PATH_MAX]; wchar_t wide_path[PATH_MAX];
DWORD attr;
if (MultiByteToWideChar(CP_UTF8, 0, path, -1, wide_path, PATH_MAX) == 0) if (MultiByteToWideChar(CP_UTF8, 0, path, -1, wide_path, PATH_MAX) == 0)
{ {
lua_pushstring(L, "unable to encode path"); lua_pushstring(L, "unable to encode path");
return lua_error(L); return lua_error(L);
} }
DWORD attr = GetFileAttributesW(wide_path); attr = GetFileAttributesW(wide_path);
if (attr != INVALID_FILE_ATTRIBUTES) { if (attr != INVALID_FILE_ATTRIBUTES) {
lua_pushboolean(L, (attr & FILE_ATTRIBUTE_REPARSE_POINT) != 0); lua_pushboolean(L, (attr & FILE_ATTRIBUTE_REPARSE_POINT) != 0);
return 1; return 1;

View File

@ -21,6 +21,7 @@ typedef struct struct_MatchInfo
int os_matchstart(lua_State* L) int os_matchstart(lua_State* L)
{ {
const char* mask = luaL_checkstring(L, 1); const char* mask = luaL_checkstring(L, 1);
MatchInfo* m;
wchar_t wide_mask[PATH_MAX]; wchar_t wide_mask[PATH_MAX];
if (MultiByteToWideChar(CP_UTF8, 0, mask, -1, wide_mask, PATH_MAX) == 0) if (MultiByteToWideChar(CP_UTF8, 0, mask, -1, wide_mask, PATH_MAX) == 0)
@ -29,7 +30,7 @@ int os_matchstart(lua_State* L)
return lua_error(L); return lua_error(L);
} }
MatchInfo* m = (MatchInfo*)malloc(sizeof(MatchInfo)); m = (MatchInfo*)malloc(sizeof(MatchInfo));
m->handle = FindFirstFileW(wide_mask, &m->entry); m->handle = FindFirstFileW(wide_mask, &m->entry);
m->is_first = 1; m->is_first = 1;