Skip to content

Commit

Permalink
Use stdbool.h instead of defining custom bool types.
Browse files Browse the repository at this point in the history
  • Loading branch information
tritao committed Sep 25, 2024
1 parent 5174a98 commit 31a7ee2
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/host/os_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int os_compile(lua_State* L)
return 2;
}

lua_dump(P, writer, outputFile, FALSE);
lua_dump(P, writer, outputFile, false);
fclose(outputFile);

lua_close(P);
Expand Down
2 changes: 1 addition & 1 deletion src/host/os_copyfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int os_copyfile(lua_State* L)
return lua_error(L);
}

z = CopyFileW(wide_src, wide_dst, FALSE);
z = CopyFileW(wide_src, wide_dst, false);
#else
lua_pushfstring(L, "cp \"%s\" \"%s\"", src, dst);
z = (system(lua_tostring(L, -1)) == 0);
Expand Down
14 changes: 7 additions & 7 deletions src/host/os_getversion.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ int getKernelVersion(struct OsVersionInfo* info)
info->majorversion = HIWORD(fileInfo->dwProductVersionMS);
info->minorversion = LOWORD(fileInfo->dwProductVersionMS);
info->revision = HIWORD(fileInfo->dwProductVersionLS);
return TRUE;
return true;
}
}
}
return FALSE;
return false;
}

int getversion(struct OsVersionInfo* info)
Expand Down Expand Up @@ -119,7 +119,7 @@ int getversion(struct OsVersionInfo* info)
int getversion(struct OsVersionInfo* info)
{
const char * propertyListFilePath = "/System/Library/CoreServices/SystemVersion.plist";
Boolean fallback = TRUE;
Boolean fallback = true;

info->description = "Mac OS";
info->majorversion = 10;
Expand All @@ -133,7 +133,7 @@ int getversion(struct OsVersionInfo* info)
CFReadStreamRef streamRef = NULL;
CFPropertyListRef propertyListRef = NULL;
CFTypeID typeId = 0;
Boolean result = FALSE;
Boolean result = false;

stringRef = CFStringCreateWithCStringNoCopy(
kCFAllocatorDefault,
Expand Down Expand Up @@ -165,7 +165,7 @@ int getversion(struct OsVersionInfo* info)

result = CFReadStreamOpen (streamRef);

if (result == FALSE)
if (result == false)
{
goto getversion_macosx_cleanup;
}
Expand Down Expand Up @@ -196,7 +196,7 @@ int getversion(struct OsVersionInfo* info)
CFStringGetCString(stringValueRef, &versionString[0], (CFIndex)sizeof (versionString), kCFStringEncodingASCII);
sscanf (versionString, "%d.%d.%d", &info->majorversion, &info->minorversion, &info->revision);

fallback = FALSE;
fallback = false;
}
}

Expand All @@ -208,7 +208,7 @@ int getversion(struct OsVersionInfo* info)
if (stringRef) CFRelease (stringRef);
}

if (fallback == TRUE)
if (fallback == true)
{
int mib[] = { CTL_KERN, KERN_OSRELEASE };
size_t len;
Expand Down
2 changes: 1 addition & 1 deletion src/host/os_is64bit.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ int os_is64bit(lua_State* L)
WowFuncSig func = (WowFuncSig)GetProcAddress(GetModuleHandle(TEXT("kernel32")), "IsWow64Process");
if (func)
{
BOOL isWow = FALSE;
BOOL isWow = false;
if (func(GetCurrentProcess(), &isWow))
{
lua_pushboolean(L, isWow);
Expand Down
17 changes: 5 additions & 12 deletions src/host/os_touchfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,14 @@
#include <sys/types.h>
#endif

#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif

static int truncate_file(const char* fn)
{
FILE* file = fopen(fn, "rb");
size_t size;
file = fopen(fn, "ab");
if (file == NULL)
{
return FALSE;
return false;
}
fseek(file, 0, SEEK_END);
size = ftell(file);
Expand All @@ -41,23 +34,23 @@ static int truncate_file(const char* fn)
if (fwrite(" ", 1, 1, file) != 1)
{
fclose(file);
return FALSE;
return false;
}
#if PLATFORM_WINDOWS
if (_chsize(_fileno(file), (long)size) != 0)
{
fclose(file);
return FALSE;
return false;
}
#endif
fclose(file);
#if !PLATFORM_WINDOWS
if (truncate(fn, (off_t)size) != 0)
{
return FALSE;
return false;
}
#endif
return TRUE;
return true;
}

int os_touchfile(lua_State* L)
Expand Down
14 changes: 7 additions & 7 deletions src/host/os_writefile_ifnotequal.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static int compare_file(const char* content, size_t length, const char* dst)
#if PLATFORM_WINDOWS
wchar_t wide_path[PATH_MAX];
if (MultiByteToWideChar(CP_UTF8, 0, dst, -1, wide_path, PATH_MAX) == 0)
return FALSE;
return false;

file = _wfopen(wide_path, L"rb");
#else
Expand All @@ -30,7 +30,7 @@ static int compare_file(const char* content, size_t length, const char* dst)

if (file == NULL)
{
return FALSE;
return false;
}

// check sizes.
Expand All @@ -41,7 +41,7 @@ static int compare_file(const char* content, size_t length, const char* dst)
if (length != size)
{
fclose(file);
return FALSE;
return false;
}

while (size > 0)
Expand All @@ -52,21 +52,21 @@ static int compare_file(const char* content, size_t length, const char* dst)
if (read != num)
{
fclose (file);
return FALSE;
return false;
}

if (memcmp(content, buffer, num) != 0)
{
fclose(file);
return FALSE;
return false;
}

size -= num;
content += num;
}

fclose(file);
return TRUE;
return true;
}


Expand All @@ -87,7 +87,7 @@ int os_writefile_ifnotequal(lua_State* L)
#if PLATFORM_WINDOWS
wchar_t wide_path[PATH_MAX];
if (MultiByteToWideChar(CP_UTF8, 0, dst, -1, wide_path, PATH_MAX) == 0)
return FALSE;
return false;

file = _wfopen(wide_path, L"wb");
#else
Expand Down
9 changes: 1 addition & 8 deletions src/host/premake.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,7 @@
#include <unistd.h>
#endif
#include <stdint.h>

/* not all platforms define this */
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#include <stdbool.h>

/* Fill in any missing bits */
#ifndef PATH_MAX
Expand Down

0 comments on commit 31a7ee2

Please sign in to comment.