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