Skip to content

Commit

Permalink
Switch to explicit ANSI variants of Win32 API functions (#543)
Browse files Browse the repository at this point in the history
Allow clean compilation with /DUNICODE defined.

Fixes #542
  • Loading branch information
mloskot authored Feb 28, 2020
1 parent aa9b558 commit 71b8d4b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/engine/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ static int get_module_filename( string * out )
DWORD result;
string_reserve( out, 256 + 1 );
string_truncate( out, 256 );
while( ( result = GetModuleFileName( NULL, out->value, out->size ) ) == out->size )
while( ( result = GetModuleFileNameA( NULL, out->value, out->size ) ) == out->size )
{
string_reserve( out, out->size * 2 + 1);
string_truncate( out, out->size * 2 );
Expand Down Expand Up @@ -1104,7 +1104,7 @@ static void debug_start_child( int argc, const char * * argv )
string command_line[ 1 ];
SECURITY_ATTRIBUTES sa = { sizeof( SECURITY_ATTRIBUTES ), NULL, TRUE };
PROCESS_INFORMATION pi = { NULL, NULL, 0, 0 };
STARTUPINFO si = { sizeof( STARTUPINFO ), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
STARTUPINFOA si = { sizeof( STARTUPINFOA ), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0 };
assert( debug_state == DEBUG_NO_CHILD );
if ( ! CreatePipe( &pipe1[ 0 ], &pipe1[ 1 ], &sa, 0 ) )
Expand Down Expand Up @@ -1149,7 +1149,7 @@ static void debug_start_child( int argc, const char * * argv )
}
SetHandleInformation( pipe1[ 1 ], HANDLE_FLAG_INHERIT, 0 );
SetHandleInformation( pipe2[ 0 ], HANDLE_FLAG_INHERIT, 0 );
if ( ! CreateProcess(
if ( ! CreateProcessA(
self->value,
command_line->value,
NULL,
Expand Down
12 changes: 11 additions & 1 deletion src/engine/execnt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ static void invoke_cmd( char const * const command, int const slot )
{
SECURITY_ATTRIBUTES sa = { sizeof( SECURITY_ATTRIBUTES ), 0, 0 };
SECURITY_DESCRIPTOR sd;
STARTUPINFO si = { sizeof( STARTUPINFO ), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
STARTUPINFOA si = { sizeof( STARTUPINFOA ), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0 };

/* Init the security data. */
Expand Down Expand Up @@ -1079,10 +1079,20 @@ static int is_parent_child( DWORD const parent, DWORD const child )
* id == 4. This check must be performed before comparing
* process creation times.
*/

#ifdef UNICODE // no PROCESSENTRY32A
if ( !wcsicmp( pinfo.szExeFile, L"csrss.exe" ) &&
#else
if ( !stricmp( pinfo.szExeFile, "csrss.exe" ) &&
#endif
is_parent_child( parent, pinfo.th32ParentProcessID ) == 2 )
return 1;

#ifdef UNICODE // no PROCESSENTRY32A
if ( !wcsicmp( pinfo.szExeFile, L"smss.exe" ) &&
#else
if ( !stricmp( pinfo.szExeFile, "smss.exe" ) &&
#endif
( pinfo.th32ParentProcessID == 4 ) )
return 2;

Expand Down
4 changes: 2 additions & 2 deletions src/engine/filent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ int file_collect_dir_content_( file_info_t * const d )
/* FIXME: Avoid duplicate FindXXX Windows API calls here and in the code
* determining a normalized path.
*/
WIN32_FIND_DATA finfo;
WIN32_FIND_DATAA finfo;
HANDLE const findHandle = FindFirstFileA( pathspec->value, &finfo );
if ( findHandle == INVALID_HANDLE_VALUE )
{
Expand Down Expand Up @@ -142,7 +142,7 @@ int file_collect_dir_content_( file_info_t * const d )
}
}
}
while ( FindNextFile( findHandle, &finfo ) );
while ( FindNextFileA( findHandle, &finfo ) );

FindClose( findHandle );
}
Expand Down
2 changes: 1 addition & 1 deletion src/engine/jam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ int main( int argc, char * * argv, char * * arg_environ )
char * executable_path( char const * argv0 )
{
char buf[ 1024 ];
DWORD const ret = GetModuleFileName( NULL, buf, sizeof( buf ) );
DWORD const ret = GetModuleFileNameA( NULL, buf, sizeof( buf ) );
return ( !ret || ret == sizeof( buf ) ) ? NULL : strdup( buf );
}
#elif defined(__APPLE__) /* Not tested */
Expand Down
2 changes: 1 addition & 1 deletion src/engine/pathnt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ static int canonicWindowsPath( char const * const path, int const path_length,
if ( !( n_length == 1 && n[ 0 ] == '.' )
&& !( n_length == 2 && n[ 0 ] == '.' && n[ 1 ] == '.' ) )
{
WIN32_FIND_DATA fd;
WIN32_FIND_DATAA fd;
HANDLE const hf = FindFirstFileA( out->value, &fd );
if ( hf != INVALID_HANDLE_VALUE )
{
Expand Down
14 changes: 7 additions & 7 deletions src/engine/w32_getreg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ LIST * builtin_system_registry( FRAME * frame, int flags )

if (
key != 0
&& ERROR_SUCCESS == RegOpenKeyEx(key, path, 0, KEY_QUERY_VALUE, &key)
&& ERROR_SUCCESS == RegOpenKeyExA(key, path, 0, KEY_QUERY_VALUE, &key)
)
{
DWORD type;
Expand All @@ -74,7 +74,7 @@ LIST * builtin_system_registry( FRAME * frame, int flags )
LIST * const field = lol_get(frame->args, 1);

if ( ERROR_SUCCESS ==
RegQueryValueEx(key, field ? object_str( list_front( field ) ) : 0, 0, &type, data, &len) )
RegQueryValueExA(key, field ? object_str( list_front( field ) ) : 0, 0, &type, data, &len) )
{
switch (type)
{
Expand All @@ -86,7 +86,7 @@ LIST * builtin_system_registry( FRAME * frame, int flags )
string_new(expanded);

while (
(len = ExpandEnvironmentStrings(
(len = ExpandEnvironmentStringsA(
(LPCSTR)data, expanded->value, expanded->capacity))
> expanded->capacity
)
Expand Down Expand Up @@ -132,7 +132,7 @@ static LIST* get_subkey_names(HKEY key, char const* path)
LIST* result = 0;

if ( ERROR_SUCCESS ==
RegOpenKeyEx(key, path, 0, KEY_ENUMERATE_SUB_KEYS, &key)
RegOpenKeyExA(key, path, 0, KEY_ENUMERATE_SUB_KEYS, &key)
)
{
char name[MAX_REGISTRY_KEYNAME_LENGTH];
Expand All @@ -141,7 +141,7 @@ static LIST* get_subkey_names(HKEY key, char const* path)
FILETIME last_write_time;

for ( index = 0;
ERROR_SUCCESS == RegEnumKeyEx(
ERROR_SUCCESS == RegEnumKeyExA(
key, index, name, &name_size, 0, 0, 0, &last_write_time);
++index,
name_size = sizeof(name)
Expand All @@ -161,14 +161,14 @@ static LIST* get_value_names(HKEY key, char const* path)
{
LIST* result = 0;

if ( ERROR_SUCCESS == RegOpenKeyEx(key, path, 0, KEY_QUERY_VALUE, &key) )
if ( ERROR_SUCCESS == RegOpenKeyExA(key, path, 0, KEY_QUERY_VALUE, &key) )
{
char name[MAX_REGISTRY_VALUENAME_LENGTH];
DWORD name_size = sizeof(name);
DWORD index;

for ( index = 0;
ERROR_SUCCESS == RegEnumValue(
ERROR_SUCCESS == RegEnumValueA(
key, index, name, &name_size, 0, 0, 0, 0);
++index,
name_size = sizeof(name)
Expand Down

0 comments on commit 71b8d4b

Please sign in to comment.