15
15
+----------------------------------------------------------------------+
16
16
*/
17
17
18
- #include "php.h"
19
18
#include "winutil.h"
20
19
#include "codepage.h"
21
20
#include <bcrypt.h>
@@ -54,31 +53,31 @@ PHP_WINUTIL_API void php_win32_error_msg_free(char *msg)
54
53
}
55
54
}/*}}}*/
56
55
57
- int php_win32_check_trailing_space (const char * path , const size_t path_len )
56
+ bool php_win32_check_trailing_space (const char * path , const size_t path_len )
58
57
{/*{{{*/
59
58
if (path_len > MAXPATHLEN - 1 ) {
60
- return 1 ;
59
+ return true ;
61
60
}
62
61
if (path ) {
63
62
if (path [0 ] == ' ' || path [path_len - 1 ] == ' ' ) {
64
- return 0 ;
63
+ return false ;
65
64
} else {
66
- return 1 ;
65
+ return true ;
67
66
}
68
67
} else {
69
- return 0 ;
68
+ return false ;
70
69
}
71
70
}/*}}}*/
72
71
73
72
static BCRYPT_ALG_HANDLE bcrypt_algo ;
74
- static BOOL has_bcrypt_algo = 0 ;
73
+ static bool has_bcrypt_algo = false ;
75
74
76
75
#define NT_SUCCESS (Status ) (((NTSTATUS)(Status)) >= 0)
77
76
78
77
#ifdef PHP_EXPORTS
79
- BOOL php_win32_shutdown_random_bytes (void )
78
+ bool php_win32_shutdown_random_bytes (void )
80
79
{/*{{{*/
81
- BOOL ret = TRUE ;
80
+ bool ret = true ;
82
81
83
82
if (has_bcrypt_algo ) {
84
83
ret = NT_SUCCESS (BCryptCloseAlgorithmProvider (bcrypt_algo , 0 ));
@@ -88,10 +87,10 @@ BOOL php_win32_shutdown_random_bytes(void)
88
87
return ret ;
89
88
}/*}}}*/
90
89
91
- BOOL php_win32_init_random_bytes (void )
90
+ bool php_win32_init_random_bytes (void )
92
91
{/*{{{*/
93
92
if (has_bcrypt_algo ) {
94
- return TRUE ;
93
+ return true ;
95
94
}
96
95
97
96
has_bcrypt_algo = NT_SUCCESS (BCryptOpenAlgorithmProvider (& bcrypt_algo , BCRYPT_RNG_ALGORITHM , NULL , 0 ));
@@ -100,24 +99,22 @@ BOOL php_win32_init_random_bytes(void)
100
99
}/*}}}*/
101
100
#endif
102
101
103
- PHP_WINUTIL_API int php_win32_get_random_bytes (unsigned char * buf , size_t size )
102
+ PHP_WINUTIL_API bool php_win32_get_random_bytes (unsigned char * buf , size_t size )
104
103
{ /* {{{ */
105
104
106
- BOOL ret ;
107
-
108
105
#if 0
109
106
/* Currently we fail on startup, with CNG API it shows no regressions so far and is secure.
110
107
Should switch on and try to reinit, if it fails too often on startup. This means also
111
108
bringing locks back. */
112
- if (has_bcrypt_algo == 0 ) {
113
- return FAILURE ;
109
+ if (! has_bcrypt_algo ) {
110
+ return false ;
114
111
}
115
112
#endif
116
113
117
114
/* No sense to loop here, the limit is huge enough. */
118
- ret = NT_SUCCESS (BCryptGenRandom (bcrypt_algo , buf , (ULONG )size , 0 ));
115
+ bool ret = NT_SUCCESS (BCryptGenRandom (bcrypt_algo , buf , (ULONG )size , 0 ));
119
116
120
- return ret ? SUCCESS : FAILURE ;
117
+ return ret ;
121
118
}
122
119
/* }}} */
123
120
@@ -439,7 +436,7 @@ PHP_WINUTIL_API char *php_win32_get_username(void)
439
436
return uname ;
440
437
}/*}}}*/
441
438
442
- static zend_always_inline BOOL is_compatible (HMODULE handle , BOOL is_smaller , char * format , char * * err )
439
+ static __forceinline bool is_compatible (HMODULE handle , bool is_smaller , char * format , char * * err )
443
440
{/*{{{*/
444
441
PIMAGE_DOS_HEADER dosHeader = (PIMAGE_DOS_HEADER ) handle ;
445
442
PIMAGE_NT_HEADERS pNTHeader = (PIMAGE_NT_HEADERS )((char * ) dosHeader + dosHeader -> e_lfanew );
@@ -470,19 +467,19 @@ static zend_always_inline BOOL is_compatible(HMODULE handle, BOOL is_smaller, ch
470
467
} else {
471
468
spprintf (err , 0 , "Can't retrieve the module name (error %u)" , GetLastError ());
472
469
}
473
- return FALSE ;
470
+ return false ;
474
471
}
475
472
476
- return TRUE ;
473
+ return true ;
477
474
}/*}}}*/
478
475
479
- PHP_WINUTIL_API BOOL php_win32_image_compatible (HMODULE handle , char * * err )
476
+ PHP_WINUTIL_API bool php_win32_image_compatible (HMODULE handle , char * * err )
480
477
{/*{{{*/
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 );
478
+ 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 );
482
479
}/*}}}*/
483
480
484
481
/* Expect a CRT module handle */
485
- PHP_WINUTIL_API BOOL php_win32_crt_compatible (char * * err )
482
+ PHP_WINUTIL_API bool php_win32_crt_compatible (char * * err )
486
483
{/*{{{*/
487
484
#if PHP_LINKER_MAJOR == 14
488
485
/* Extend for other CRT if needed. */
@@ -494,9 +491,9 @@ PHP_WINUTIL_API BOOL php_win32_crt_compatible(char **err)
494
491
HMODULE handle = GetModuleHandle (crt_name );
495
492
if (handle == NULL ) {
496
493
spprintf (err , 0 , "Can't get handle of module %s (error %u)" , crt_name , GetLastError ());
497
- return FALSE ;
494
+ return false ;
498
495
}
499
- return is_compatible (handle , FALSE , "'%s' %u.%u is not compatible with this PHP build linked with %d.%d" , err );
496
+ return is_compatible (handle , false , "'%s' %u.%u is not compatible with this PHP build linked with %d.%d" , err );
500
497
#endif
501
- return TRUE ;
498
+ return true ;
502
499
}/*}}}*/
0 commit comments