diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 086c5cc0347bd..d9399e110541a 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -42,197 +42,6 @@ env: CC: ccache gcc CXX: ccache g++ jobs: - LINUX_X64: - if: github.repository == 'php/php-src' || github.event_name == 'pull_request' - services: - mysql: - image: mysql:8.3 - ports: - - 3306:3306 - env: - MYSQL_DATABASE: test - MYSQL_ROOT_PASSWORD: root - postgres: - image: postgres - ports: - - 5432:5432 - env: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: test - firebird: - image: jacobalberty/firebird - ports: - - 3050:3050 - env: - ISC_PASSWORD: test - FIREBIRD_DATABASE: test.fdb - FIREBIRD_USER: test - FIREBIRD_PASSWORD: test - strategy: - fail-fast: false - matrix: - include: - - debug: false - zts: false - asan: false - - debug: true - zts: true - asan: true - name: "LINUX_X64_${{ matrix.debug && 'DEBUG' || 'RELEASE' }}_${{ matrix.zts && 'ZTS' || 'NTS' }}${{ matrix.asan && '_ASAN' || '' }}" - runs-on: ubuntu-${{ !matrix.asan && '22' || '20' }}.04 - container: - image: ${{ matrix.asan && 'ubuntu:23.04' || null }} - steps: - - name: git checkout - uses: actions/checkout@v4 - - name: apt - uses: ./.github/actions/apt-x64 - - name: LLVM 16 (ASAN-only) - if: ${{ matrix.asan }} - run: | - DEBIAN_FRONTEND=noninteractive sudo apt-get install -y lsb-release wget software-properties-common gnupg - wget https://apt.llvm.org/llvm.sh - chmod u+x llvm.sh - sudo ./llvm.sh 16 - - name: System info - run: | - echo "::group::Show host CPU info" - lscpu - echo "::endgroup::" - echo "::group::Show installed package versions" - dpkg -l - echo "::endgroup::" - - name: Create MSSQL container - if: ${{ !matrix.asan }} - uses: ./.github/actions/setup-mssql - - name: Setup Caddy server - uses: ./.github/actions/setup-caddy - - name: ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - # This duplicates the "job.name" expression above because - # GitHub has no way to query the job name (github.job is the - # job id, not the job name) - key: "LINUX_X64_${{ matrix.debug && 'DEBUG' || 'RELEASE' }}_${{ matrix.zts && 'ZTS' || 'NTS' }}${{ matrix.asan && '_ASAN' || '' }}-${{hashFiles('main/php_version.h')}}" - append-timestamp: false - save: ${{ github.event_name != 'pull_request' }} - - name: ./configure - uses: ./.github/actions/configure-x64 - with: - configurationParameters: >- - --${{ matrix.debug && 'enable' || 'disable' }}-debug - --${{ matrix.zts && 'enable' || 'disable' }}-zts - ${{ matrix.asan && 'CFLAGS="-fsanitize=undefined,address -DZEND_TRACK_ARENA_ALLOC" LDFLAGS="-fsanitize=undefined,address" CC=clang-16 CXX=clang++-16' || '' }} - skipSlow: ${{ matrix.asan }} - - name: make - run: make -j$(/usr/bin/nproc) >/dev/null - - name: make install - uses: ./.github/actions/install-linux - - name: Setup - if: ${{ !matrix.asan }} - uses: ./.github/actions/setup-x64 - - name: Test - if: matrix.asan == false - uses: ./.github/actions/test-linux - - name: Test Tracing JIT - uses: ./.github/actions/test-linux - with: - jitType: tracing - runTestsParameters: >- - -d zend_extension=opcache.so - -d opcache.enable_cli=1 - ${{ matrix.asan && '--asan -x' || '' }} - - name: Verify generated files are up to date - if: ${{ !matrix.asan }} - uses: ./.github/actions/verify-generated-files - LINUX_X32: - if: github.repository == 'php/php-src' || github.event_name == 'pull_request' - name: LINUX_X32_DEBUG_ZTS - runs-on: ubuntu-latest - container: - image: ubuntu:20.04 - env: - MYSQL_TEST_HOST: mysql - PDO_MYSQL_TEST_DSN: mysql:host=mysql;dbname=test - PDO_MYSQL_TEST_HOST: mysql - services: - mysql: - image: mysql:8.3 - ports: - - 3306:3306 - env: - MYSQL_DATABASE: test - MYSQL_ROOT_PASSWORD: root - steps: - - name: git checkout - uses: actions/checkout@v4 - - name: apt - uses: ./.github/actions/apt-x32 - - name: ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: "${{github.job}}-${{hashFiles('main/php_version.h')}}" - append-timestamp: false - - name: ./configure - uses: ./.github/actions/configure-x32 - with: - configurationParameters: >- - --enable-debug - --enable-zts - - name: make - run: make -j$(/usr/bin/nproc) >/dev/null - - name: make install - uses: ./.github/actions/install-linux-x32 - - name: Test Tracing JIT - uses: ./.github/actions/test-linux - with: - jitType: tracing - runTestsParameters: >- - -d zend_extension=opcache.so - -d opcache.enable_cli=1 - MACOS_DEBUG_NTS: - if: github.repository == 'php/php-src' || github.event_name == 'pull_request' - strategy: - fail-fast: false - matrix: - include: - - os: 13 - arch: X64 - - os: 14 - arch: ARM64 - name: MACOS_${{ matrix.arch }}_DEBUG_NTS - runs-on: macos-${{ matrix.os }} - steps: - - name: git checkout - uses: actions/checkout@v4 - - name: brew - uses: ./.github/actions/brew - - name: ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: "${{github.job}}-${{matrix.os}}-${{hashFiles('main/php_version.h')}}" - append-timestamp: false - save: ${{ github.event_name != 'pull_request' }} - - name: ./configure - uses: ./.github/actions/configure-macos - with: - configurationParameters: --enable-debug --disable-zts - - name: make - run: |- - export PATH="$(brew --prefix)/opt/bison/bin:$PATH" - make -j$(sysctl -n hw.logicalcpu) >/dev/null - - name: make install - run: sudo make install - - name: Test Tracing JIT - uses: ./.github/actions/test-macos - with: - jitType: tracing - runTestsParameters: >- - -d zend_extension=opcache.so - -d opcache.enable_cli=1 - - name: Verify generated files are up to date - uses: ./.github/actions/verify-generated-files WINDOWS: if: github.repository == 'php/php-src' || github.event_name == 'pull_request' name: WINDOWS_X64_ZTS @@ -259,109 +68,3 @@ jobs: run: .github/scripts/windows/build.bat - name: Test run: .github/scripts/windows/test.bat - BENCHMARKING: - name: BENCHMARKING - if: github.repository == 'php/php-src' || github.event_name == 'pull_request' - runs-on: ubuntu-22.04 - steps: - - name: git checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - # ASLR can cause a lot of noise due to missed sse opportunities for memcpy - # and other operations, so we disable it during benchmarking. - - name: Disable ASLR - run: echo 0 | sudo tee /proc/sys/kernel/randomize_va_space - - name: apt - run: | - set -x - sudo apt-get update - sudo apt-get install \ - bison \ - libgmp-dev \ - libonig-dev \ - libsqlite3-dev \ - openssl \ - re2c \ - valgrind - - name: ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: "${{github.job}}-${{hashFiles('main/php_version.h')}}" - append-timestamp: false - save: ${{ github.event_name != 'pull_request' }} - - name: ./configure - run: | - set -x - ./buildconf --force - ./configure \ - --disable-debug \ - --enable-mbstring \ - --enable-opcache \ - --enable-option-checking=fatal \ - --enable-sockets \ - --enable-werror \ - --prefix=/usr \ - --with-config-file-scan-dir=/etc/php.d \ - --with-gmp \ - --with-mysqli=mysqlnd \ - --with-openssl \ - --with-pdo-sqlite \ - --with-valgrind - - name: make - run: make -j$(/usr/bin/nproc) >/dev/null - - name: make install - run: | - set -x - sudo make install - sudo mkdir -p /etc/php.d - sudo chmod 777 /etc/php.d - echo mysqli.default_socket=/var/run/mysqld/mysqld.sock > /etc/php.d/mysqli.ini - echo zend_extension=opcache.so >> /etc/php.d/opcache.ini - echo opcache.enable=1 >> /etc/php.d/opcache.ini - echo opcache.enable_cli=1 >> /etc/php.d/opcache.ini - - name: Setup - run: | - git config --global user.name "Benchmark" - git config --global user.email "benchmark@php.net" - sudo service mysql start - mysql -uroot -proot -e "CREATE DATABASE IF NOT EXISTS wordpress" - mysql -uroot -proot -e "CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'wordpress'; FLUSH PRIVILEGES;" - mysql -uroot -proot -e "GRANT ALL PRIVILEGES ON *.* TO 'wordpress'@'localhost' WITH GRANT OPTION;" - - name: git checkout benchmarking-data - uses: actions/checkout@v4 - with: - repository: php/benchmarking-data - ssh-key: ${{ secrets.BENCHMARKING_DATA_DEPLOY_KEY }} - path: benchmark/repos/data - - name: Benchmark - run: php benchmark/benchmark.php true - - name: Store result - if: github.event_name == 'push' - run: | - set -x - cd benchmark/repos/data - git pull --autostash - if [ -e ".git/MERGE_HEAD" ]; then - echo "Merging, can't proceed" - exit 1 - fi - git add . - if git diff --cached --quiet; then - exit 0 - fi - git commit -m "Add result for ${{ github.repository }}@${{ github.sha }}" - git push - - name: Show diff - if: github.event_name == 'pull_request' - run: |- - set -x - php benchmark/generate_diff.php \ - ${{ github.sha }} \ - $(git merge-base ${{ github.event.pull_request.base.sha }} ${{ github.sha }}) \ - > $GITHUB_STEP_SUMMARY - - uses: actions/upload-artifact@v4 - with: - name: profiles - path: ${{ github.workspace }}/benchmark/profiles - retention-days: 30 diff --git a/TSRM/tsrm_win32.c b/TSRM/tsrm_win32.c index 52fbc95bbd457..3be0ccb5ecd5d 100644 --- a/TSRM/tsrm_win32.c +++ b/TSRM/tsrm_win32.c @@ -617,7 +617,7 @@ TSRM_API int pclose(FILE *stream) /* Returns a number between 0x2000_0000 and 0x3fff_ffff. On Windows, key_t is int. */ static key_t tsrm_choose_random_shm_key(key_t prev_key) { unsigned char buf[4]; - if (php_win32_get_random_bytes(buf, 4) != SUCCESS) { + if (!php_win32_get_random_bytes(buf, 4)) { return prev_key + 2; } uint32_t n = diff --git a/ext/random/csprng.c b/ext/random/csprng.c index 8b38985c6ac67..857a45b2b7969 100644 --- a/ext/random/csprng.c +++ b/ext/random/csprng.c @@ -70,7 +70,7 @@ ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_random_bytes_ex(void *bytes, size_ { #ifdef PHP_WIN32 /* Defer to CryptGenRandom on Windows */ - if (php_win32_get_random_bytes(bytes, size) == FAILURE) { + if (!php_win32_get_random_bytes(bytes, size)) { snprintf(errstr, errstr_size, "Failed to retrieve randomness from the operating system (BCryptGenRandom)"); return FAILURE; } diff --git a/win32/codepage.c b/win32/codepage.c index 69b6a44aa9c8a..06b5916683726 100644 --- a/win32/codepage.c +++ b/win32/codepage.c @@ -420,7 +420,7 @@ PW32CP const struct php_win32_cp *php_win32_cp_set_by_id(DWORD id) return cur_cp; }/*}}}*/ -PW32CP BOOL php_win32_cp_use_unicode(void) +PW32CP bool php_win32_cp_use_unicode(void) {/*{{{*/ return 65001 == cur_cp->id; }/*}}}*/ diff --git a/win32/codepage.h b/win32/codepage.h index e69bf7cdc9d5c..7f1a5ae996e4e 100644 --- a/win32/codepage.h +++ b/win32/codepage.h @@ -27,6 +27,11 @@ extern "C" { # define PW32CP __declspec(dllimport) #endif +#include +#include +#include +#include + #define PHP_WIN32_CP_IGNORE_LEN (0) #define PHP_WIN32_CP_IGNORE_LEN_P ((size_t *)-1) @@ -40,7 +45,7 @@ struct php_win32_cp { char *desc; }; -PW32CP BOOL php_win32_cp_use_unicode(void); +PW32CP bool php_win32_cp_use_unicode(void); PW32CP const struct php_win32_cp *php_win32_cp_do_setup(const char *); #define php_win32_cp_setup() php_win32_cp_do_setup(NULL) PW32CP const struct php_win32_cp *php_win32_cp_do_update(const char *); diff --git a/win32/glob.c b/win32/glob.c index 5dd0f4661acbe..663b308bbb78a 100644 --- a/win32/glob.c +++ b/win32/glob.c @@ -41,16 +41,11 @@ * * Optional extra services, controlled by flags not defined by POSIX: * - * GLOB_QUOTE: - * Escaping convention: \ inhibits any special meaning the following - * character might have (except \ at end of string is retained). * GLOB_MAGCHAR: * Set in gl_flags if pattern contained a globbing character. * GLOB_NOMAGIC: * Same as GLOB_NOCHECK, but it will only append pattern if it did * not contain any magic characters. [Used in csh style globbing] - * GLOB_ALTDIRFUNC: - * Use alternately specified directory access functions. * GLOB_TILDE: * expand ~user/foo to the /home/dir/of/user/foo * GLOB_BRACE: @@ -58,33 +53,19 @@ * gl_matchc: * Number of matches in the current invocation of glob. */ -#ifdef PHP_WIN32 -#if _MSC_VER < 1800 -# define _POSIX_ -# include -# undef _POSIX_ -#else + /* Visual Studio 2013 removed all the _POSIX_ defines, but we depend on some */ -# ifndef ARG_MAX -# define ARG_MAX 14500 -# endif -#endif +#ifndef ARG_MAX +# define ARG_MAX 14500 #endif -#include "php.h" -#include +#include "glob.h" +#include +#include +#include "ioutil.h" +#include "readdir.h" -#include -#ifndef PHP_WIN32 -#include -#include -#include -#include -#endif #include -#include "glob.h" -#include -#include #include #define DOLLAR '$' @@ -96,7 +77,8 @@ #define QUOTE '\\' #define RANGE '-' #define RBRACKET ']' -#define SEP DEFAULT_SLASH +/* As this is Windows we use a backslash for the separator */ +#define SEP '\\' #define STAR '*' #define TILDE '~' #define UNDERSCORE '_' @@ -137,11 +119,11 @@ typedef char Char; #define ismeta(c) (((c)&M_QUOTE) != 0) static int compare(const void *, const void *); -static int g_Ctoc(const Char *, char *, u_int); -static int g_lstat(Char *, zend_stat_t *, glob_t *); +static bool g_Ctoc(const Char *, char *, u_int); +static int g_lstat(Char *, php_win32_ioutil_stat_t *, glob_t *); static DIR *g_opendir(Char *, glob_t *); static Char *g_strchr(Char *, int); -static int g_stat(Char *, zend_stat_t *, glob_t *); +static int g_stat(Char *, php_win32_ioutil_stat_t *, glob_t *); static int glob0(const Char *, glob_t *); static int glob1(Char *, Char *, glob_t *, size_t *); static int glob2(Char *, Char *, Char *, Char *, Char *, Char *, @@ -152,23 +134,21 @@ static int globextend(const Char *, glob_t *, size_t *); static const Char *globtilde(const Char *, Char *, size_t, glob_t *); static int globexp1(const Char *, glob_t *); static int globexp2(const Char *, const Char *, glob_t *, int *); -static int match(Char *, Char *, Char *); +static bool match(Char *, Char *, Char *); #ifdef DEBUG static void qprintf(const char *, Char *); #endif -PHPAPI int glob(const char *pattern, int flags, int (*errfunc)(const char *, int), glob_t *pglob) +PHP_WIN_GLOB int glob(const char *pattern, int flags, int (*errfunc)(const char *, int), glob_t *pglob) { const uint8_t *patnext; int c; Char *bufnext, *bufend, patbuf[MAXPATHLEN]; -#ifdef PHP_WIN32 /* Force skipping escape sequences on windows * due to the ambiguity with path backslashes */ flags |= GLOB_NOESCAPE; -#endif patnext = (uint8_t *) pattern; if (!(flags & GLOB_APPEND)) { @@ -341,9 +321,6 @@ static int globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv */ static const Char *globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob) { -#ifndef PHP_WIN32 - struct passwd *pwd; -#endif char *h; const Char *p; Char *b, *eb; @@ -359,38 +336,19 @@ static const Char *globtilde(const Char *pattern, Char *patbuf, size_t patbuf_le *h = EOS; -#if 0 - if (h == (char *)eb) - return what; -#endif - if (((char *) patbuf)[0] == EOS) { /* * handle a plain ~ or ~/ by expanding $HOME * first and then trying the password file */ if ((h = getenv("HOME")) == NULL) { -#ifndef PHP_WIN32 - if ((pwd = getpwuid(getuid())) == NULL) - return pattern; - else - h = pwd->pw_dir; -#else return pattern; -#endif } } else { /* * Expand a ~user */ -#ifndef PHP_WIN32 - if ((pwd = getpwnam((char*) patbuf)) == NULL) - return pattern; - else - h = pwd->pw_dir; -#else return pattern; -#endif } /* Copy the home directory */ @@ -504,11 +462,7 @@ static int compare(const void *p, const void *q) return(strcmp(*(char **)p, *(char **)q)); } -static int -glob1(pattern, pattern_last, pglob, limitp) - Char *pattern, *pattern_last; - glob_t *pglob; - size_t *limitp; +static int glob1(Char *pattern, Char *pattern_last, glob_t *pglob, size_t *limitp) { Char pathbuf[MAXPATHLEN]; @@ -520,6 +474,11 @@ glob1(pattern, pattern_last, pglob, limitp) pattern, pattern_last, pglob, limitp)); } +static inline bool glob_is_slash(Char c) +{ + return c == '/' || c == '\\'; +} + /* * The functions glob2 and glob3 are mutually recursive; there is one level * of recursion for each segment in the pattern that contains one or more @@ -528,7 +487,7 @@ glob1(pattern, pattern_last, pglob, limitp) static int glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, Char *pattern, Char *pattern_last, glob_t *pglob, size_t *limitp) { - zend_stat_t sb = {0}; + php_win32_ioutil_stat_t sb = {0}; Char *p, *q; int anymeta; @@ -543,7 +502,7 @@ static int glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend return(0); if (((pglob->gl_flags & GLOB_MARK) && - !IS_SLASH(pathend[-1])) && (S_ISDIR(sb.st_mode) || + !glob_is_slash(pathend[-1])) && (S_ISDIR(sb.st_mode) || (S_ISLNK(sb.st_mode) && (g_stat(pathbuf, &sb, pglob) == 0) && S_ISDIR(sb.st_mode)))) { @@ -559,7 +518,7 @@ static int glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend /* Find end of next segment, copy tentatively to pathend. */ q = pathend; p = pattern; - while (*p != EOS && !IS_SLASH(*p)) { + while (*p != EOS && !glob_is_slash(*p)) { if (ismeta(*p)) anymeta = 1; if (q+1 > pathend_last) @@ -570,7 +529,7 @@ static int glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend if (!anymeta) { /* No expansion, do next segment. */ pathend = q; pattern = p; - while (IS_SLASH(*pattern)) { + while (glob_is_slash(*pattern)) { if (pathend+1 > pathend_last) return (1); *pathend++ = *pattern++; @@ -591,14 +550,6 @@ static int glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend DIR *dirp; int err; - /* - * The readdirfunc declaration can't be prototyped, because it is - * assigned, below, to two functions which are prototyped in glob.h - * and dirent.h as taking pointers to differently typed opaque - * structures. - */ - struct dirent *(*readdirfunc)(); - if (pathend > pathend_last) return (1); *pathend = EOS; @@ -620,11 +571,7 @@ static int glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend err = 0; /* Search directory for matching names. */ - if (pglob->gl_flags & GLOB_ALTDIRFUNC) - readdirfunc = pglob->gl_readdir; - else - readdirfunc = readdir; - while ((dp = (*readdirfunc)(dirp))) { + while ((dp = readdir(dirp))) { register uint8_t *sc; register Char *dc; @@ -651,10 +598,7 @@ static int glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend break; } - if (pglob->gl_flags & GLOB_ALTDIRFUNC) - (*pglob->gl_closedir)(dirp); - else - closedir(dirp); + closedir(dirp); return(err); } @@ -727,54 +671,62 @@ static int globextend(const Char *path, glob_t *pglob, size_t *limitp) * pattern matching function for filenames. Each occurrence of the * * pattern causes a recursion level. */ -static int match(Char *name, Char *pat, Char *patend) +static bool match(Char *name, Char *pat, Char *patend) { - int ok, negate_range; + bool ok, negate_range; Char c, k; while (pat < patend) { c = *pat++; switch (c & M_MASK) { case M_ALL: - if (pat == patend) - return(1); - do - if (match(name, pat, patend)) - return(1); - while (*name++ != EOS) - ; - return(0); + if (pat == patend) { + return true; + } + do { + if (match(name, pat, patend)) { + return true; + } + } while (*name++ != EOS); + return false; case M_ONE: - if (*name++ == EOS) - return(0); + if (*name++ == EOS) { + return false; + } break; case M_SET: - ok = 0; - if ((k = *name++) == EOS) - return(0); - if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS) + ok = false; + if ((k = *name++) == EOS) { + return false; + } + if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS) { ++pat; + } while (((c = *pat++) & M_MASK) != M_END) if ((*pat & M_MASK) == M_RNG) { - if (c <= k && k <= pat[1]) - ok = 1; + if (c <= k && k <= pat[1]) { + ok = true; + } pat += 2; - } else if (c == k) - ok = 1; - if (ok == negate_range) - return(0); + } else if (c == k) { + ok = true; + } + if (ok == negate_range) { + return false; + } break; default: - if (*name++ != c) - return(0); + if (*name++ != c) { + return false; + } break; } } - return(*name == EOS); + return *name == EOS; } /* Free allocated data belonging to a glob_t structure. */ -PHPAPI void globfree(glob_t *pglob) +PHP_WIN_GLOB void globfree(glob_t *pglob) { register int i; register char **pp; @@ -794,38 +746,31 @@ static DIR * g_opendir(Char *str, glob_t *pglob) char buf[MAXPATHLEN]; if (!*str) - strlcpy(buf, ".", sizeof(buf)); + memcpy(buf, ".", strlen(".")); else { if (g_Ctoc(str, buf, sizeof(buf))) return(NULL); } - if (pglob->gl_flags & GLOB_ALTDIRFUNC) - return((*pglob->gl_opendir)(buf)); - return(opendir(buf)); } -static int g_lstat(Char *fn, zend_stat_t *sb, glob_t *pglob) +static int g_lstat(Char *fn, php_win32_ioutil_stat_t *sb, glob_t *pglob) { char buf[MAXPATHLEN]; if (g_Ctoc(fn, buf, sizeof(buf))) return(-1); - if (pglob->gl_flags & GLOB_ALTDIRFUNC) - return((*pglob->gl_lstat)(buf, sb)); - return(php_sys_lstat(buf, sb)); + return(php_win32_ioutil_lstat(buf, sb)); } -static int g_stat(Char *fn, zend_stat_t *sb, glob_t *pglob) +static int g_stat(Char *fn, php_win32_ioutil_stat_t *sb, glob_t *pglob) { char buf[MAXPATHLEN]; if (g_Ctoc(fn, buf, sizeof(buf))) return(-1); - if (pglob->gl_flags & GLOB_ALTDIRFUNC) - return((*pglob->gl_stat)(buf, sb)); - return(php_sys_stat(buf, sb)); + return(php_win32_ioutil_stat(buf, sb)); } static Char *g_strchr(Char *str, int ch) @@ -837,14 +782,14 @@ static Char *g_strchr(Char *str, int ch) return (NULL); } -static int g_Ctoc(const Char *str, char *buf, u_int len) +static bool g_Ctoc(const Char *str, char *buf, u_int len) { while (len--) { if ((*buf++ = (char) *str++) == EOS) - return (0); + return false; } - return (1); + return true; } #ifdef DEBUG diff --git a/win32/glob.h b/win32/glob.h index 42cf2f9d71dda..fd677f6d1d80f 100644 --- a/win32/glob.h +++ b/win32/glob.h @@ -42,61 +42,54 @@ #ifndef _GLOB_H_ #define _GLOB_H_ -#ifndef PHP_WIN32 -# include +#ifdef __cplusplus +extern "C" { #endif -#include "Zend/zend_stream.h" +#ifdef PHP_EXPORTS +# define PHP_WIN_GLOB __declspec(dllexport) +#else +# define PHP_WIN_GLOB __declspec(dllimport) +#endif + +#include typedef struct { - int gl_pathc; /* Count of total paths so far. */ - int gl_matchc; /* Count of paths matching pattern. */ - int gl_offs; /* Reserved at beginning of gl_pathv. */ + size_t gl_pathc; /* Count of total paths so far. */ + unsigned int gl_matchc; /* Count of paths matching pattern. */ + size_t gl_offs; /* Reserved at beginning of gl_pathv. */ int gl_flags; /* Copy of flags parameter to glob. */ char **gl_pathv; /* List of paths matching pattern. */ /* Copy of errfunc parameter to glob. */ int (*gl_errfunc)(const char *, int); - - /* - * Alternate filesystem access methods for glob; replacement - * versions of closedir(3), readdir(3), opendir(3), stat(2) - * and lstat(2). - */ - void (*gl_closedir)(void *); - struct dirent *(*gl_readdir)(void *); - void *(*gl_opendir)(const char *); - int (*gl_lstat)(const char *, zend_stat_t *); - int (*gl_stat)(const char *, zend_stat_t *); } glob_t; -/* Flags */ +/* Standard POSIX Flags */ #define GLOB_APPEND 0x0001 /* Append to output from previous call. */ #define GLOB_DOOFFS 0x0002 /* Use gl_offs. */ #define GLOB_ERR 0x0004 /* Return on error. */ #define GLOB_MARK 0x0008 /* Append / to matching directories. */ #define GLOB_NOCHECK 0x0010 /* Return pattern itself if nothing matches. */ +#define GLOB_NOESCAPE 0x1000 /* Disable backslash escaping. */ #define GLOB_NOSORT 0x0020 /* Don't sort. */ - -#ifndef _POSIX_SOURCE -#define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */ #define GLOB_BRACE 0x0080 /* Expand braces ala csh. */ + +/* Implementation defined flags */ #define GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */ #define GLOB_NOMAGIC 0x0200 /* GLOB_NOCHECK without magic chars (csh). */ -#define GLOB_QUOTE 0x0400 /* Quote special chars with \. */ #define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */ -#define GLOB_NOESCAPE 0x1000 /* Disable backslash escaping. */ #define GLOB_LIMIT 0x2000 /* Limit pattern match output to ARG_MAX */ -#endif /* Error values returned by glob(3) */ #define GLOB_NOSPACE (-1) /* Malloc call failed. */ #define GLOB_ABORTED (-2) /* Unignored error. */ #define GLOB_NOMATCH (-3) /* No match and GLOB_NOCHECK not set. */ -#define GLOB_NOSYS (-4) /* Function not supported. */ -#define GLOB_ABEND GLOB_ABORTED -BEGIN_EXTERN_C() -PHPAPI int glob(const char *, int, int (*)(const char *, int), glob_t *); -PHPAPI void globfree(glob_t *); -END_EXTERN_C() +PHP_WIN_GLOB int glob(const char *, int, int (*)(const char *, int), glob_t *); +PHP_WIN_GLOB void globfree(glob_t *); + +#ifdef __cplusplus +} +#endif + #endif /* !_GLOB_H_ */ diff --git a/win32/winutil.c b/win32/winutil.c index e09944d131b9b..c20f74b427acd 100644 --- a/win32/winutil.c +++ b/win32/winutil.c @@ -15,8 +15,8 @@ +----------------------------------------------------------------------+ */ -#include "php.h" #include "winutil.h" +#include "ioutil.h" #include "codepage.h" #include #include @@ -54,31 +54,31 @@ PHP_WINUTIL_API void php_win32_error_msg_free(char *msg) } }/*}}}*/ -int php_win32_check_trailing_space(const char * path, const size_t path_len) +bool php_win32_check_trailing_space(const char * path, const size_t path_len) {/*{{{*/ if (path_len > MAXPATHLEN - 1) { - return 1; + return true; } if (path) { if (path[0] == ' ' || path[path_len - 1] == ' ') { - return 0; + return false; } else { - return 1; + return true; } } else { - return 0; + return false; } }/*}}}*/ static BCRYPT_ALG_HANDLE bcrypt_algo; -static BOOL has_bcrypt_algo = 0; +static bool has_bcrypt_algo = false; #define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0) #ifdef PHP_EXPORTS -BOOL php_win32_shutdown_random_bytes(void) +bool php_win32_shutdown_random_bytes(void) {/*{{{*/ - BOOL ret = TRUE; + bool ret = true; if (has_bcrypt_algo) { ret = NT_SUCCESS(BCryptCloseAlgorithmProvider(bcrypt_algo, 0)); @@ -88,10 +88,10 @@ BOOL php_win32_shutdown_random_bytes(void) return ret; }/*}}}*/ -BOOL php_win32_init_random_bytes(void) +bool php_win32_init_random_bytes(void) {/*{{{*/ if (has_bcrypt_algo) { - return TRUE; + return true; } has_bcrypt_algo = NT_SUCCESS(BCryptOpenAlgorithmProvider(&bcrypt_algo, BCRYPT_RNG_ALGORITHM, NULL, 0)); @@ -100,24 +100,22 @@ BOOL php_win32_init_random_bytes(void) }/*}}}*/ #endif -PHP_WINUTIL_API int php_win32_get_random_bytes(unsigned char *buf, size_t size) +PHP_WINUTIL_API bool php_win32_get_random_bytes(unsigned char *buf, size_t size) { /* {{{ */ - BOOL ret; - #if 0 /* Currently we fail on startup, with CNG API it shows no regressions so far and is secure. Should switch on and try to reinit, if it fails too often on startup. This means also bringing locks back. */ - if (has_bcrypt_algo == 0) { - return FAILURE; + if (!has_bcrypt_algo) { + return false; } #endif /* No sense to loop here, the limit is huge enough. */ - ret = NT_SUCCESS(BCryptGenRandom(bcrypt_algo, buf, (ULONG)size, 0)); + bool ret = NT_SUCCESS(BCryptGenRandom(bcrypt_algo, buf, (ULONG)size, 0)); - return ret ? SUCCESS : FAILURE; + return ret; } /* }}} */ @@ -439,7 +437,7 @@ PHP_WINUTIL_API char *php_win32_get_username(void) return uname; }/*}}}*/ -static zend_always_inline BOOL is_compatible(HMODULE handle, BOOL is_smaller, char *format, char **err) +static __forceinline bool is_compatible(HMODULE handle, bool is_smaller, char *format, char **err) {/*{{{*/ PIMAGE_DOS_HEADER dosHeader = (PIMAGE_DOS_HEADER) handle; 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 } else { spprintf(err, 0, "Can't retrieve the module name (error %u)", GetLastError()); } - return FALSE; + return false; } - return TRUE; + return true; }/*}}}*/ -PHP_WINUTIL_API BOOL php_win32_image_compatible(HMODULE handle, char **err) +PHP_WINUTIL_API bool php_win32_image_compatible(HMODULE handle, char **err) {/*{{{*/ - 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); + 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); }/*}}}*/ /* Expect a CRT module handle */ -PHP_WINUTIL_API BOOL php_win32_crt_compatible(char **err) +PHP_WINUTIL_API bool php_win32_crt_compatible(char **err) {/*{{{*/ #if PHP_LINKER_MAJOR == 14 /* Extend for other CRT if needed. */ @@ -494,9 +492,9 @@ PHP_WINUTIL_API BOOL php_win32_crt_compatible(char **err) HMODULE handle = GetModuleHandle(crt_name); if (handle == NULL) { spprintf(err, 0, "Can't get handle of module %s (error %u)", crt_name, GetLastError()); - return FALSE; + return false; } - return is_compatible(handle, FALSE, "'%s' %u.%u is not compatible with this PHP build linked with %d.%d", err); + return is_compatible(handle, false, "'%s' %u.%u is not compatible with this PHP build linked with %d.%d", err); #endif - return TRUE; + return true; }/*}}}*/ diff --git a/win32/winutil.h b/win32/winutil.h index 043195067529c..f868448bddb15 100644 --- a/win32/winutil.h +++ b/win32/winutil.h @@ -23,16 +23,21 @@ # define PHP_WINUTIL_API __declspec(dllimport) #endif +#include +#include +#include +#include + PHP_WINUTIL_API char *php_win32_error_to_msg(HRESULT error); PHP_WINUTIL_API void php_win32_error_msg_free(char *msg); #define php_win_err() php_win32_error_to_msg(GetLastError()) #define php_win_err_free(err) php_win32_error_msg_free(err) -int php_win32_check_trailing_space(const char * path, const size_t path_len); -PHP_WINUTIL_API int php_win32_get_random_bytes(unsigned char *buf, size_t size); +bool php_win32_check_trailing_space(const char * path, const size_t path_len); +PHP_WINUTIL_API bool php_win32_get_random_bytes(unsigned char *buf, size_t size); #ifdef PHP_EXPORTS -BOOL php_win32_init_random_bytes(void); -BOOL php_win32_shutdown_random_bytes(void); +bool php_win32_init_random_bytes(void); +bool php_win32_shutdown_random_bytes(void); #endif #if !defined(ECURDIR) @@ -53,7 +58,7 @@ PHP_WINUTIL_API int php_win32_code_to_errno(unsigned long w32Err); PHP_WINUTIL_API char *php_win32_get_username(void); -PHP_WINUTIL_API BOOL php_win32_image_compatible(HMODULE handle, char **err); -PHP_WINUTIL_API BOOL php_win32_crt_compatible(char **err); +PHP_WINUTIL_API bool php_win32_image_compatible(HMODULE handle, char **err); +PHP_WINUTIL_API bool php_win32_crt_compatible(char **err); #endif