1515 +----------------------------------------------------------------------+
1616 */
1717
18- #include "php.h"
1918#include "winutil.h"
19+ #include "ioutil.h"
2020#include "codepage.h"
2121#include <bcrypt.h>
2222#include <lmcons.h>
@@ -54,31 +54,31 @@ PHP_WINUTIL_API void php_win32_error_msg_free(char *msg)
5454 }
5555}/*}}}*/
5656
57- int php_win32_check_trailing_space (const char * path , const size_t path_len )
57+ bool php_win32_check_trailing_space (const char * path , const size_t path_len )
5858{/*{{{*/
5959 if (path_len > MAXPATHLEN - 1 ) {
60- return 1 ;
60+ return true ;
6161 }
6262 if (path ) {
6363 if (path [0 ] == ' ' || path [path_len - 1 ] == ' ' ) {
64- return 0 ;
64+ return false ;
6565 } else {
66- return 1 ;
66+ return true ;
6767 }
6868 } else {
69- return 0 ;
69+ return false ;
7070 }
7171}/*}}}*/
7272
7373static BCRYPT_ALG_HANDLE bcrypt_algo ;
74- static BOOL has_bcrypt_algo = 0 ;
74+ static bool has_bcrypt_algo = false ;
7575
7676#define NT_SUCCESS (Status ) (((NTSTATUS)(Status)) >= 0)
7777
7878#ifdef PHP_EXPORTS
79- BOOL php_win32_shutdown_random_bytes (void )
79+ bool php_win32_shutdown_random_bytes (void )
8080{/*{{{*/
81- BOOL ret = TRUE ;
81+ bool ret = true ;
8282
8383 if (has_bcrypt_algo ) {
8484 ret = NT_SUCCESS (BCryptCloseAlgorithmProvider (bcrypt_algo , 0 ));
@@ -88,10 +88,10 @@ BOOL php_win32_shutdown_random_bytes(void)
8888 return ret ;
8989}/*}}}*/
9090
91- BOOL php_win32_init_random_bytes (void )
91+ bool php_win32_init_random_bytes (void )
9292{/*{{{*/
9393 if (has_bcrypt_algo ) {
94- return TRUE ;
94+ return true ;
9595 }
9696
9797 has_bcrypt_algo = NT_SUCCESS (BCryptOpenAlgorithmProvider (& bcrypt_algo , BCRYPT_RNG_ALGORITHM , NULL , 0 ));
@@ -100,24 +100,22 @@ BOOL php_win32_init_random_bytes(void)
100100}/*}}}*/
101101#endif
102102
103- PHP_WINUTIL_API int php_win32_get_random_bytes (unsigned char * buf , size_t size )
103+ PHP_WINUTIL_API bool php_win32_get_random_bytes (unsigned char * buf , size_t size )
104104{ /* {{{ */
105105
106- BOOL ret ;
107-
108106#if 0
109107 /* Currently we fail on startup, with CNG API it shows no regressions so far and is secure.
110108 Should switch on and try to reinit, if it fails too often on startup. This means also
111109 bringing locks back. */
112- if (has_bcrypt_algo == 0 ) {
113- return FAILURE ;
110+ if (! has_bcrypt_algo ) {
111+ return false ;
114112 }
115113#endif
116114
117115 /* No sense to loop here, the limit is huge enough. */
118- ret = NT_SUCCESS (BCryptGenRandom (bcrypt_algo , buf , (ULONG )size , 0 ));
116+ bool ret = NT_SUCCESS (BCryptGenRandom (bcrypt_algo , buf , (ULONG )size , 0 ));
119117
120- return ret ? SUCCESS : FAILURE ;
118+ return ret ;
121119}
122120/* }}} */
123121
@@ -439,7 +437,7 @@ PHP_WINUTIL_API char *php_win32_get_username(void)
439437 return uname ;
440438}/*}}}*/
441439
442- static zend_always_inline BOOL is_compatible (HMODULE handle , BOOL is_smaller , char * format , char * * err )
440+ static __forceinline bool is_compatible (HMODULE handle , bool is_smaller , char * format , char * * err )
443441{/*{{{*/
444442 PIMAGE_DOS_HEADER dosHeader = (PIMAGE_DOS_HEADER ) handle ;
445443 PIMAGE_NT_HEADERS pNTHeader = (PIMAGE_NT_HEADERS )((char * ) dosHeader + dosHeader -> e_lfanew );
@@ -470,19 +468,19 @@ static zend_always_inline BOOL is_compatible(HMODULE handle, BOOL is_smaller, ch
470468 } else {
471469 spprintf (err , 0 , "Can't retrieve the module name (error %u)" , GetLastError ());
472470 }
473- return FALSE ;
471+ return false ;
474472 }
475473
476- return TRUE ;
474+ return true ;
477475}/*}}}*/
478476
479- PHP_WINUTIL_API BOOL php_win32_image_compatible (HMODULE handle , char * * err )
477+ PHP_WINUTIL_API bool php_win32_image_compatible (HMODULE handle , char * * err )
480478{/*{{{*/
481- return is_compatible (handle , TRUE , "Can't load module '%s' as it's linked with %u.%u, but the core is linked with %d.%d" , err );
479+ return is_compatible (handle , true , "Can't load module '%s' as it's linked with %u.%u, but the core is linked with %d.%d" , err );
482480}/*}}}*/
483481
484482/* Expect a CRT module handle */
485- PHP_WINUTIL_API BOOL php_win32_crt_compatible (char * * err )
483+ PHP_WINUTIL_API bool php_win32_crt_compatible (char * * err )
486484{/*{{{*/
487485#if PHP_LINKER_MAJOR == 14
488486 /* Extend for other CRT if needed. */
@@ -494,9 +492,9 @@ PHP_WINUTIL_API BOOL php_win32_crt_compatible(char **err)
494492 HMODULE handle = GetModuleHandle (crt_name );
495493 if (handle == NULL ) {
496494 spprintf (err , 0 , "Can't get handle of module %s (error %u)" , crt_name , GetLastError ());
497- return FALSE ;
495+ return false ;
498496 }
499- return is_compatible (handle , FALSE , "'%s' %u.%u is not compatible with this PHP build linked with %d.%d" , err );
497+ return is_compatible (handle , false , "'%s' %u.%u is not compatible with this PHP build linked with %d.%d" , err );
500498#endif
501- return TRUE ;
499+ return true ;
502500}/*}}}*/
0 commit comments