Commit 4ca4be5dfea for php.net

commit 4ca4be5dfea819638f1e399893768c6a1d3d1be1
Author: Gina Peter Banyard <girgias@php.net>
Date:   Fri Dec 12 18:07:45 2025 +0000

    ext/standard: use sapi_windows_cp_*() functions directly

diff --git a/ext/standard/tests/file/windows_mb_path/bug64699.phpt b/ext/standard/tests/file/windows_mb_path/bug64699.phpt
index 8dc9b31114a..0bde1ea1bfa 100644
--- a/ext/standard/tests/file/windows_mb_path/bug64699.phpt
+++ b/ext/standard/tests/file/windows_mb_path/bug64699.phpt
@@ -12,8 +12,9 @@

 include __DIR__ . DIRECTORY_SEPARATOR . "util.inc";

-$old_cp = get_active_cp();
-set_active_cp(65001);
+$old_cp = sapi_windows_cp_get();
+sapi_windows_cp_set(65001);
+echo "Active code page: ", sapi_windows_cp_get(), "\n";

 $prefix = __DIR__ . DIRECTORY_SEPARATOR . "testBug64699" . DIRECTORY_SEPARATOR;

@@ -41,10 +42,10 @@
 }
 rmdir($prefix);

-set_active_cp($old_cp);
+sapi_windows_cp_set($old_cp);

 ?>
---EXPECTF--
+--EXPECT--
 Active code page: 65001
 filetype()[dir ] == is_dir()[dir ] -> OK: .
 filetype()[dir ] == is_dir()[dir ] -> OK: ..
@@ -54,4 +55,3 @@
 filetype()[dir ] == is_dir()[dir ] -> OK: ゾ
 filetype()[dir ] == is_dir()[dir ] -> OK: 多国語
 filetype()[dir ] == is_dir()[dir ] -> OK: 表
-Active code page: %d
diff --git a/ext/standard/tests/file/windows_mb_path/test_cwd_mb_names.phpt b/ext/standard/tests/file/windows_mb_path/test_cwd_mb_names.phpt
index 622c38272e8..9f9d1f24e6c 100644
--- a/ext/standard/tests/file/windows_mb_path/test_cwd_mb_names.phpt
+++ b/ext/standard/tests/file/windows_mb_path/test_cwd_mb_names.phpt
@@ -17,8 +17,9 @@
 $dirw = $prefix . DIRECTORY_SEPARATOR . "テストマルチバイト・パス42";
 touch($dirw . DIRECTORY_SEPARATOR . "dummy.txt");

-$old_cp = get_active_cp();
-set_active_cp(65001);
+$old_cp = sapi_windows_cp_get();
+sapi_windows_cp_set(65001);
+echo "Active code page: ", sapi_windows_cp_get(), "\n";

 $oldcwd = getcwd();
 var_dump(chdir($dirw));
@@ -26,7 +27,7 @@

 var_dump(file_exists("dummy.txt"));

-set_active_cp($old_cp);
+sapi_windows_cp_set($old_cp);

 chdir($oldcwd);
 remove_data("dir_mb");
@@ -37,4 +38,3 @@
 bool(true)
 string(%d) "%s\テストマルチバイト・パス42"
 bool(true)
-Active code page: %d
diff --git a/ext/standard/tests/file/windows_mb_path/test_readdir_mb_names.phpt b/ext/standard/tests/file/windows_mb_path/test_readdir_mb_names.phpt
index c04bdbdcb46..65a0dada9f4 100644
--- a/ext/standard/tests/file/windows_mb_path/test_readdir_mb_names.phpt
+++ b/ext/standard/tests/file/windows_mb_path/test_readdir_mb_names.phpt
@@ -34,8 +34,9 @@

 $dirw = $prefix . DIRECTORY_SEPARATOR;

-$old_cp = get_active_cp();
-set_active_cp(65001);
+$old_cp = sapi_windows_cp_get();
+sapi_windows_cp_set(65001);
+echo "Active code page: ", sapi_windows_cp_get(), "\n";

 if (is_dir($dirw)) {
     if ($dh = opendir($dirw)) {
@@ -47,12 +48,12 @@
 } else {
     echo "is_dir failed\n";
 }
-set_active_cp($old_cp);
+sapi_windows_cp_set($old_cp);

 remove_data("mb_names");

 ?>
---EXPECTF--
+--EXPECT--
 Active code page: 65001
 filename: . : filetype: dir
 filename: .. : filetype: dir
@@ -72,4 +73,3 @@
 filename: テストマルチバイト・パス42 : filetype: dir
 filename: 測試多字節路徑 : filetype: file
 filename: 測試多字節路徑5 : filetype: dir
-Active code page: %d
diff --git a/ext/standard/tests/file/windows_mb_path/test_rename_mb_names.phpt b/ext/standard/tests/file/windows_mb_path/test_rename_mb_names.phpt
index a04aa72fb45..ce040d1eda5 100644
--- a/ext/standard/tests/file/windows_mb_path/test_rename_mb_names.phpt
+++ b/ext/standard/tests/file/windows_mb_path/test_rename_mb_names.phpt
@@ -10,47 +10,34 @@
 --FILE--
 <?php

-
 include __DIR__ . DIRECTORY_SEPARATOR . "util.inc";

-
 $prefix = create_data("file2_mb");

 $fw_orig = $prefix . DIRECTORY_SEPARATOR . "Ελλάδα.txt";
-
-
-
 $fw_copied = $prefix . DIRECTORY_SEPARATOR . "Ελλάδα_copy.txt";
-
-
 $fw_renamed = $prefix . DIRECTORY_SEPARATOR . "測試多字節路徑17.txt";

-
-
-$old_cp = get_active_cp();
-
-set_active_cp(65001);
-
-
-
-
+$old_cp = sapi_windows_cp_get();
+sapi_windows_cp_set(65001);
+echo "Active code page: ", sapi_windows_cp_get(), "\n";

 var_dump(copy($fw_orig, $fw_copied));
-var_dump(get_basename_with_cp($fw_copied, get_active_cp(), false));
+var_dump(get_basename($fw_copied, false));
 var_dump(file_exists($fw_copied));

 var_dump(rename($fw_copied, $fw_renamed));
-var_dump(get_basename_with_cp($fw_renamed, get_active_cp(), false));
+var_dump(get_basename($fw_renamed, false));
 var_dump(file_exists($fw_renamed));

 var_dump(unlink($fw_renamed));

-set_active_cp($old_cp);
+sapi_windows_cp_set($old_cp);

 remove_data("file2_mb");

 ?>
---EXPECTF--
+--EXPECT--
 Active code page: 65001
 bool(true)
 string(21) "Ελλάδα_copy.txt"
@@ -59,4 +46,3 @@
 string(27) "測試多字節路徑17.txt"
 bool(true)
 bool(true)
-Active code page: %d
diff --git a/ext/standard/tests/file/windows_mb_path/util.inc b/ext/standard/tests/file/windows_mb_path/util.inc
index 65a2b78404a..cec79aba56c 100644
--- a/ext/standard/tests/file/windows_mb_path/util.inc
+++ b/ext/standard/tests/file/windows_mb_path/util.inc
@@ -1,52 +1,35 @@
 <?php

-function get_active_cp($kind = "")
+function get_basename($path, $echo = true)
 {
-    if (version_compare(PHP_VERSION, '7.1', '<')) {
-        $s = exec("chcp");
-        preg_match(",.*: (\d+),", $s, $m);
+    if ($echo) echo "getting basename of $path\n";

-        return $m[1];
-    } else {
-        return sapi_windows_cp_get($kind);
-    }
-}
+    $cmd = "powershell -command \"Get-Item -Path '$path' | Format-Table -HideTableHeaders Name\"";
+    $out = trim(shell_exec($cmd));

-function set_active_cp($cp, $echo = true)
-{
-    if (version_compare(PHP_VERSION, '7.1', '<')) {
-        $ret = exec("chcp $cp");
-    } else {
-        if (!sapi_windows_cp_set($cp)) {
-            echo "Failed to set cp $cp\n";
-            return;
-        }
+    if ($echo) var_dump($out, $out == basename($path));
+    if ($echo) var_dump(realpath($path));

-        if ($echo) echo "Active code page: ", get_active_cp(), "\n";
-    }
+    return $out;
 }

 function get_basename_with_cp($path, $cp, $echo = true)
 {
-    $old_cp = get_active_cp();
-    set_active_cp($cp, $echo);
-
-    if ($echo) echo "getting basename of $path\n";
+    $old_cp = sapi_windows_cp_get();
+    sapi_windows_cp_set($cp);
+    if ($echo) echo "Active code page: ", sapi_windows_cp_get(), "\n";

-    $cmd = "powershell -command \"Get-Item -Path '$path' | Format-Table -HideTableHeaders Name\"";
-    $out = trim(shell_exec($cmd));
-
-    if ($echo) var_dump($out, $out == basename($path));
-    if ($echo) var_dump(realpath($path));
+    $out = get_basename($path, $echo);

-    set_active_cp($old_cp, $echo);
+    sapi_windows_cp_set($old_cp);
+    if ($echo) echo "Active code page: ", sapi_windows_cp_get(), "\n";

     return $out;
 }

 function skip_if_wrong_cp($cp, $kind = "")
 {
-    if (get_active_cp($kind) != $cp) {
+    if (sapi_windows_cp_get($kind) != $cp) {
         die("skip this test expect codepage $cp");
     }
 }
@@ -121,9 +104,9 @@ function create_data($id, $item = "", $cp = 65001, $utf8 = true)
             mkdir($prefix);
         }

-        if (0 === strpos($id, "dir")) {
+        if (str_starts_with($id, "dir")) {
             create_verify_dir($prefix, $item, $cp);
-        } else if (0 === strpos($id, "file")) {
+        } else if (str_starts_with($id, "file")) {
             /* a bit unhandy, but content can be put from outside, if needed */
             create_verify_file($prefix, $item, "dummy content", $cp);
         } else {