From 3b5ddd067f8360365beccf79646171dba657b184 Mon Sep 17 00:00:00 2001 From: "Victor M. Alvarez" Date: Wed, 20 Aug 2014 11:22:37 +0200 Subject: [PATCH] Replace WIN32 with _WIN32. The latest is defined by the compiler and doesn't need to be defined externally. --- libyara/compiler.c | 2 +- libyara/exefiles.c | 2 +- libyara/filemap.c | 4 ++-- libyara/hex_lexer.c | 8 ++++---- libyara/include/yara/types.h | 2 +- libyara/include/yara/utils.h | 2 +- libyara/lexer.c | 4 ++-- libyara/libyara.c | 12 ++++++------ libyara/mem.c | 2 +- libyara/modules/pe.c | 2 +- libyara/proc.c | 2 +- libyara/re.c | 16 ++++++++-------- libyara/re_lexer.c | 8 ++++---- libyara/rules.c | 8 ++++---- threading.c | 22 +++++++++++----------- threading.h | 4 ++-- windows/libyara/libyara.vcxproj | 8 ++++---- windows/yara/yara.vcxproj | 8 ++++---- windows/yarac/yarac.vcxproj | 8 ++++---- yara-python/setupwin32.py | 1 - yara-python/setupwin64.py | 1 - yara.c | 6 +++--- yarac.c | 2 +- 23 files changed, 66 insertions(+), 68 deletions(-) diff --git a/libyara/compiler.c b/libyara/compiler.c index de59c35526..7d3652ff87 100644 --- a/libyara/compiler.c +++ b/libyara/compiler.c @@ -536,7 +536,7 @@ int yr_compiler_get_rules( yara_rules->code_start = rules_file_header->code_start; yara_rules->tidx_mask = 0; - #if WIN32 + #if _WIN32 yara_rules->mutex = CreateMutex(NULL, FALSE, NULL); #else pthread_mutex_init(&yara_rules->mutex, NULL); diff --git a/libyara/exefiles.c b/libyara/exefiles.c index 7662659a91..7f4e9ba442 100644 --- a/libyara/exefiles.c +++ b/libyara/exefiles.c @@ -16,7 +16,7 @@ limitations under the License. #include -#ifdef WIN32 +#ifdef _WIN32 #include #else #include diff --git a/libyara/filemap.c b/libyara/filemap.c index 2cb198e870..5b6cbd7db6 100755 --- a/libyara/filemap.c +++ b/libyara/filemap.c @@ -16,7 +16,7 @@ limitations under the License. #include -#ifdef WIN32 +#ifdef _WIN32 #include #else #include @@ -28,7 +28,7 @@ limitations under the License. #include -#ifdef WIN32 +#ifdef _WIN32 // // Win32 implementation diff --git a/libyara/hex_lexer.c b/libyara/hex_lexer.c index 14e83b10a3..49545517a6 100644 --- a/libyara/hex_lexer.c +++ b/libyara/hex_lexer.c @@ -488,7 +488,7 @@ limitations under the License. #include "hex_grammar.h" -#ifdef WIN32 +#ifdef _WIN32 #define snprintf _snprintf #endif @@ -2083,7 +2083,7 @@ void hex_yyfree (void * ptr , yyscan_t yyscanner) -#ifdef WIN32 +#ifdef _WIN32 #include extern DWORD recovery_state_key; #else @@ -2098,7 +2098,7 @@ void yyfatal( { jmp_buf* recovery_state; - #ifdef WIN32 + #ifdef _WIN32 recovery_state = TlsGetValue(recovery_state_key) ; #else recovery_state = pthread_getspecific(recovery_state_key); @@ -2142,7 +2142,7 @@ int yr_parse_hex_string( lex_env.last_error_code = ERROR_SUCCESS; lex_env.inside_or = 0; - #ifdef WIN32 + #ifdef _WIN32 TlsSetValue(recovery_state_key, (LPVOID) &recovery_state); #else pthread_setspecific(recovery_state_key, (void*) &recovery_state); diff --git a/libyara/include/yara/types.h b/libyara/include/yara/types.h index 03502213c3..2a8052b820 100644 --- a/libyara/include/yara/types.h +++ b/libyara/include/yara/types.h @@ -23,7 +23,7 @@ limitations under the License. #include #include -#ifdef WIN32 +#ifdef _WIN32 #include typedef HANDLE mutex_t; #else diff --git a/libyara/include/yara/utils.h b/libyara/include/yara/utils.h index 07604d0f5b..52a0147caf 100644 --- a/libyara/include/yara/utils.h +++ b/libyara/include/yara/utils.h @@ -45,7 +45,7 @@ limitations under the License. #define PTR_TO_UINT64(x) ((uint64_t) (size_t) x) -#ifdef WIN32 +#ifdef _WIN32 #define snprintf _snprintf #define strcasecmp _stricmp #define strncasecmp _strnicmp diff --git a/libyara/lexer.c b/libyara/lexer.c index 406fcbf512..b27732b519 100644 --- a/libyara/lexer.c +++ b/libyara/lexer.c @@ -670,7 +670,7 @@ limitations under the License. } \ } -#ifdef WIN32 +#ifdef _WIN32 #define snprintf _snprintf #endif @@ -1288,7 +1288,7 @@ YY_RULE_SETUP // make included file path relative to current source file s = strrchr(buffer, '/'); - #ifdef WIN32 + #ifdef _WIN32 b = strrchr(buffer, '\\'); // in Windows both path delimiters are accepted #endif diff --git a/libyara/libyara.c b/libyara/libyara.c index 8958bf6c7e..f3be9e70f1 100644 --- a/libyara/libyara.c +++ b/libyara/libyara.c @@ -22,12 +22,12 @@ limitations under the License. #include -#ifdef WIN32 +#ifdef _WIN32 #define snprintf _snprintf #endif -#ifdef WIN32 +#ifdef _WIN32 #include DWORD tidx_key; DWORD recovery_state_key; @@ -66,7 +66,7 @@ void yr_initialize(void) yr_heap_alloc(); - #ifdef WIN32 + #ifdef _WIN32 tidx_key = TlsAlloc(); recovery_state_key = TlsAlloc(); #else @@ -102,7 +102,7 @@ void yr_finalize(void) { yr_re_finalize_thread(); - #ifdef WIN32 + #ifdef _WIN32 TlsFree(tidx_key); TlsFree(recovery_state_key); #else @@ -128,7 +128,7 @@ void yr_finalize(void) void yr_set_tidx(int tidx) { - #ifdef WIN32 + #ifdef _WIN32 TlsSetValue(tidx_key, (LPVOID) (tidx + 1)); #else pthread_setspecific(tidx_key, (void*) (size_t) (tidx + 1)); @@ -148,7 +148,7 @@ void yr_set_tidx(int tidx) int yr_get_tidx(void) { - #ifdef WIN32 + #ifdef _WIN32 return (int) TlsGetValue(tidx_key) - 1; #else return (int) (size_t) pthread_getspecific(tidx_key) - 1; diff --git a/libyara/mem.c b/libyara/mem.c index 8d72109e68..bf4f4d8327 100644 --- a/libyara/mem.c +++ b/libyara/mem.c @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -#ifdef WIN32 +#ifdef _WIN32 #include #include diff --git a/libyara/modules/pe.c b/libyara/modules/pe.c index 40916ab32e..45dec1db46 100644 --- a/libyara/modules/pe.c +++ b/libyara/modules/pe.c @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -#ifdef WIN32 +#ifdef _WIN32 #include #else #include diff --git a/libyara/proc.c b/libyara/proc.c index 96a4d38adf..4b169597d1 100644 --- a/libyara/proc.c +++ b/libyara/proc.c @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -#ifdef WIN32 +#ifdef _WIN32 #include diff --git a/libyara/re.c b/libyara/re.c index a51f04ac16..78614b95a4 100644 --- a/libyara/re.c +++ b/libyara/re.c @@ -30,7 +30,7 @@ order to avoid confusion with operating system threads. #include #include -#ifdef WIN32 +#ifdef _WIN32 #include #else #include @@ -86,7 +86,7 @@ typedef struct _RE_THREAD_STORAGE } RE_THREAD_STORAGE; -#ifdef WIN32 +#ifdef _WIN32 DWORD thread_storage_key; #else pthread_key_t thread_storage_key; @@ -101,7 +101,7 @@ pthread_key_t thread_storage_key; int yr_re_initialize(void) { - #ifdef WIN32 + #ifdef _WIN32 thread_storage_key = TlsAlloc(); #else pthread_key_create(&thread_storage_key, NULL); @@ -119,7 +119,7 @@ int yr_re_initialize(void) int yr_re_finalize(void) { - #ifdef WIN32 + #ifdef _WIN32 TlsFree(thread_storage_key); #else pthread_key_delete(thread_storage_key); @@ -141,7 +141,7 @@ int yr_re_finalize_thread(void) RE_FIBER* next_fiber; RE_THREAD_STORAGE* storage; - #ifdef WIN32 + #ifdef _WIN32 storage = TlsGetValue(thread_storage_key); #else storage = pthread_getspecific(thread_storage_key); @@ -161,7 +161,7 @@ int yr_re_finalize_thread(void) yr_free(storage); } - #ifdef WIN32 + #ifdef _WIN32 TlsSetValue(thread_storage_key, NULL); #else pthread_setspecific(thread_storage_key, NULL); @@ -1104,7 +1104,7 @@ int yr_re_emit_code( int _yr_re_alloc_storage( RE_THREAD_STORAGE** storage) { - #ifdef WIN32 + #ifdef _WIN32 *storage = TlsGetValue(thread_storage_key); #else *storage = pthread_getspecific(thread_storage_key); @@ -1120,7 +1120,7 @@ int _yr_re_alloc_storage( (*storage)->fiber_pool.head = NULL; (*storage)->fiber_pool.tail = NULL; - #ifdef WIN32 + #ifdef _WIN32 TlsSetValue(thread_storage_key, *storage); #else pthread_setspecific(thread_storage_key, *storage); diff --git a/libyara/re_lexer.c b/libyara/re_lexer.c index cb60598f78..32af944856 100644 --- a/libyara/re_lexer.c +++ b/libyara/re_lexer.c @@ -514,7 +514,7 @@ limitations under the License. #include -#ifdef WIN32 +#ifdef _WIN32 #define snprintf _snprintf #endif @@ -2443,7 +2443,7 @@ uint8_t read_escaped_char(yyscan_t yyscanner) -#ifdef WIN32 +#ifdef _WIN32 #include extern DWORD recovery_state_key; #else @@ -2457,7 +2457,7 @@ void yyfatal( { jmp_buf* recovery_state; - #ifdef WIN32 + #ifdef _WIN32 recovery_state = TlsGetValue(recovery_state_key) ; #else recovery_state = pthread_getspecific(recovery_state_key); @@ -2501,7 +2501,7 @@ int yr_parse_re_string( lex_env.last_error_code = ERROR_SUCCESS; - #ifdef WIN32 + #ifdef _WIN32 TlsSetValue(recovery_state_key, (LPVOID) &recovery_state); #else pthread_setspecific(recovery_state_key, (void*) &recovery_state); diff --git a/libyara/rules.c b/libyara/rules.c index c47c3c8395..c7d4a7eb66 100644 --- a/libyara/rules.c +++ b/libyara/rules.c @@ -41,7 +41,7 @@ limitations under the License. void _yr_rules_lock( YR_RULES* rules) { - #ifdef WIN32 + #ifdef _WIN32 WaitForSingleObject(rules->mutex, INFINITE); #else pthread_mutex_lock(&rules->mutex); @@ -52,7 +52,7 @@ void _yr_rules_lock( void _yr_rules_unlock( YR_RULES* rules) { - #ifdef WIN32 + #ifdef _WIN32 ReleaseMutex(rules->mutex); #else pthread_mutex_unlock(&rules->mutex); @@ -624,7 +624,7 @@ int yr_rules_load( new_rules->rules_list_head = header->rules_list_head; new_rules->tidx_mask = 0; - #if WIN32 + #if _WIN32 new_rules->mutex = CreateMutex(NULL, FALSE, NULL); if (new_rules->mutex == NULL) @@ -657,7 +657,7 @@ int yr_rules_destroy( external++; } - #if WIN32 + #if _WIN32 CloseHandle(rules->mutex); #else pthread_mutex_destroy(&rules->mutex); diff --git a/threading.c b/threading.c index dd8e1d3eaa..d1d84a499e 100644 --- a/threading.c +++ b/threading.c @@ -16,7 +16,7 @@ limitations under the License. #include -#ifndef WIN32 +#ifndef _WIN32 #include #endif @@ -26,7 +26,7 @@ limitations under the License. int mutex_init( MUTEX* mutex) { - #ifdef WIN32 + #ifdef _WIN32 *mutex = CreateMutex(NULL, FALSE, NULL); if (*mutex == NULL) return GetLastError(); @@ -40,7 +40,7 @@ int mutex_init( void mutex_destroy( MUTEX* mutex) { - #ifdef WIN32 + #ifdef _WIN32 CloseHandle(*mutex); #else pthread_mutex_destroy(mutex); @@ -51,7 +51,7 @@ void mutex_destroy( void mutex_lock( MUTEX* mutex) { - #ifdef WIN32 + #ifdef _WIN32 WaitForSingleObject(*mutex, INFINITE); #else pthread_mutex_lock(mutex); @@ -62,7 +62,7 @@ void mutex_lock( void mutex_unlock( MUTEX* mutex) { - #ifdef WIN32 + #ifdef _WIN32 ReleaseMutex(*mutex); #else pthread_mutex_unlock(mutex); @@ -74,7 +74,7 @@ int semaphore_init( SEMAPHORE* semaphore, int value) { - #ifdef WIN32 + #ifdef _WIN32 *semaphore = CreateSemaphore(NULL, value, 65535, NULL); if (*semaphore == NULL) return GetLastError(); @@ -100,7 +100,7 @@ int semaphore_init( void semaphore_destroy( SEMAPHORE* semaphore) { - #ifdef WIN32 + #ifdef _WIN32 CloseHandle(*semaphore); #else sem_close(*semaphore); @@ -111,7 +111,7 @@ void semaphore_destroy( void semaphore_wait( SEMAPHORE* semaphore) { - #ifdef WIN32 + #ifdef _WIN32 WaitForSingleObject(*semaphore, INFINITE); #else sem_wait(*semaphore); @@ -122,7 +122,7 @@ void semaphore_wait( void semaphore_release( SEMAPHORE* semaphore) { - #ifdef WIN32 + #ifdef _WIN32 ReleaseSemaphore(*semaphore, 1, NULL); #else sem_post(*semaphore); @@ -135,7 +135,7 @@ int create_thread( THREAD_START_ROUTINE start_routine, void* param) { - #ifdef WIN32 + #ifdef _WIN32 *thread = CreateThread(NULL, 0, start_routine, param, 0, NULL); if (*thread == NULL) return GetLastError(); @@ -150,7 +150,7 @@ int create_thread( void thread_join( THREAD* thread) { - #ifdef WIN32 + #ifdef _WIN32 WaitForSingleObject(*thread, INFINITE); #else pthread_join(*thread, NULL); diff --git a/threading.h b/threading.h index a2f5041d47..f599e4fff5 100644 --- a/threading.h +++ b/threading.h @@ -18,7 +18,7 @@ limitations under the License. #ifndef YR_THREADING_H #define YR_THREADING_H -#ifdef WIN32 +#ifdef _WIN32 #include #else #include @@ -26,7 +26,7 @@ limitations under the License. #include #endif -#ifdef WIN32 +#ifdef _WIN32 typedef HANDLE SEMAPHORE; typedef HANDLE MUTEX; diff --git a/windows/libyara/libyara.vcxproj b/windows/libyara/libyara.vcxproj index d3c7ea6444..d3a59e1148 100644 --- a/windows/libyara/libyara.vcxproj +++ b/windows/libyara/libyara.vcxproj @@ -73,7 +73,7 @@ - WIN32;_CRT_SECURE_NO_WARNINGS;CUCKOO + _CRT_SECURE_NO_WARNINGS;CUCKOO ..\..;..\..\libyara;..\..\libyara\include;..\..\windows\include;%(AdditionalIncludeDirectories) MultiThreadedDebugDLL 4005;4273;4090; @@ -90,7 +90,7 @@ - WIN32;CUCKOO + CUCKOO ..\..;..\..\libyara;..\..\libyara\include;..\..\windows\include;%(AdditionalIncludeDirectories) 4005;4273;4090; @@ -105,7 +105,7 @@ - WIN32;_CRT_SECURE_NO_WARNINGS;CUCKOO + _CRT_SECURE_NO_WARNINGS;CUCKOO ..\..;..\..\libyara;..\..\libyara\include;..\..\windows\include;%(AdditionalIncludeDirectories) MultiThreadedDLL 4005;4273;4090;%(DisableSpecificWarnings) @@ -118,7 +118,7 @@ - WIN32;CUCKOO + CUCKOO ..\..;..\..\libyara;..\..\libyara\include;..\..\windows\include;%(AdditionalIncludeDirectories) 4005;4273;4090;%(DisableSpecificWarnings) diff --git a/windows/yara/yara.vcxproj b/windows/yara/yara.vcxproj index e82fbd40ce..b22db5c973 100644 --- a/windows/yara/yara.vcxproj +++ b/windows/yara/yara.vcxproj @@ -97,7 +97,7 @@ NotUsing Level3 Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + _DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) ..\..\libyara\include;..\include;%(AdditionalIncludeDirectories) MultiThreadedDebugDLL false @@ -115,7 +115,7 @@ NotUsing Level3 Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + _DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) ..\..\libyara\include;..\include;%(AdditionalIncludeDirectories) @@ -133,7 +133,7 @@ MaxSpeed true true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) ..\..\libyara\include;..\include;%(AdditionalIncludeDirectories) MultiThreadedDLL @@ -157,7 +157,7 @@ MaxSpeed true true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) ..\..\libyara\include;..\include;%(AdditionalIncludeDirectories) diff --git a/windows/yarac/yarac.vcxproj b/windows/yarac/yarac.vcxproj index 85f5bb1e70..fbcfca55b0 100644 --- a/windows/yarac/yarac.vcxproj +++ b/windows/yarac/yarac.vcxproj @@ -72,7 +72,7 @@ Level3 Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + _DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) ..\..\libyara\include;..\include;%(AdditionalIncludeDirectories) @@ -90,7 +90,7 @@ MaxSpeed true true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) ..\..\libyara\include;..\include;%(AdditionalIncludeDirectories) @@ -105,7 +105,7 @@ ..\..\libyara\include;..\include;%(AdditionalIncludeDirectories) - WIN32;_CRT_SECURE_NO_WARNINGS + _CRT_SECURE_NO_WARNINGS libyara64.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -115,7 +115,7 @@ ..\..\libyara\include;..\include;%(AdditionalIncludeDirectories) - WIN32;_CRT_SECURE_NO_WARNINGS + _CRT_SECURE_NO_WARNINGS libyara64.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) diff --git a/yara-python/setupwin32.py b/yara-python/setupwin32.py index 0c47ad18da..5b7be3e688 100644 --- a/yara-python/setupwin32.py +++ b/yara-python/setupwin32.py @@ -24,7 +24,6 @@ name='yara', sources=['yara-python.c'], include_dirs=['../windows/include', '../libyara/include'], - define_macros=[('WIN32', None)], extra_objects=[ '../windows/libyara/Release/libyara32.lib'] )]) diff --git a/yara-python/setupwin64.py b/yara-python/setupwin64.py index 7a6961b26e..9152fd510c 100644 --- a/yara-python/setupwin64.py +++ b/yara-python/setupwin64.py @@ -24,7 +24,6 @@ name='yara', sources=['yara-python.c'], include_dirs=['../windows/include', '../libyara/include'], - define_macros=[('WIN32', None)], extra_objects=[ '../windows/libyara/Release/libyara64.lib'] )]) diff --git a/yara.c b/yara.c index 3c8f23abbb..9160be4c21 100644 --- a/yara.c +++ b/yara.c @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -#ifndef WIN32 +#ifndef _WIN32 #include #include @@ -244,7 +244,7 @@ char* file_queue_get() } -#ifdef WIN32 +#ifdef _WIN32 int is_directory( const char* path) @@ -610,7 +610,7 @@ int callback(int message, void* message_data, void* user_data) return CALLBACK_ERROR; } -#ifdef WIN32 +#ifdef _WIN32 DWORD WINAPI scanning_thread(LPVOID param) #else void* scanning_thread(void* param) diff --git a/yarac.c b/yarac.c index 5458c790e3..157e42a06a 100644 --- a/yarac.c +++ b/yarac.c @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -#ifndef WIN32 +#ifndef _WIN32 #include #include