File: tempnam_variation9.phpt

package info (click to toggle)
php8.4 8.4.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 208,108 kB
  • sloc: ansic: 1,060,628; php: 35,345; sh: 11,866; cpp: 7,201; pascal: 4,913; javascript: 3,091; asm: 2,810; yacc: 2,411; makefile: 689; xml: 446; python: 301; awk: 148
file content (73 lines) | stat: -rw-r--r-- 1,922 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
--TEST--
Test tempnam() function: usage variations - test prefix maximum size
--SKIPIF--
<?php
if (PHP_OS_FAMILY === 'Windows') {
    die("skip Do not run on Windows");
}
?>
--FILE--
<?php
/* Testing the maximum prefix size */

echo "*** Testing tempnam() maximum prefix size ***\n";
$file_path = __DIR__."/tempnamVar9";
mkdir($file_path);

$pre_prefix = "begin_";
$post_prefix = "_end";
$fixed_length = strlen($pre_prefix) + strlen($post_prefix);
/* An array of prefixes */
$names_arr = [
  $pre_prefix . str_repeat("x", 7) . $post_prefix,
  $pre_prefix . str_repeat("x", 63 - $fixed_length) . $post_prefix,
  $pre_prefix . str_repeat("x", 64 - $fixed_length) . $post_prefix,
  $pre_prefix . str_repeat("x", 65 - $fixed_length) . $post_prefix,
  $pre_prefix . str_repeat("x", 300) . $post_prefix,
];

foreach($names_arr as $i=>$prefix) {
    echo "-- Iteration $i --\n";
    try {
        $file_name = tempnam("$file_path", $prefix);
    } catch (Error $e) {
        echo $e->getMessage(), "\n";
        continue;
    }

    $base_name = basename($file_name);
    echo "File name is => ", $base_name, "\n";
    echo "File name length is => ", strlen($base_name), "\n";

    if (file_exists($file_name)) {
        unlink($file_name);
    }
}
rmdir($file_path);

?>
--CLEAN--
<?php
$file_path = __DIR__."/tempnamVar9";
if (file_exists($file_path)) {
    array_map('unlink', glob($file_path . "/*"));
    rmdir($file_path);
}
?>
--EXPECTF--
*** Testing tempnam() maximum prefix size ***
-- Iteration 0 --
File name is => begin_%rx{7}%r_end%r.{19}%r
File name length is => 36
-- Iteration 1 --
File name is => begin_%rx{53}%r_end%r.{19}%r
File name length is => 82
-- Iteration 2 --
File name is => begin_%rx{54}%r_en%r.{19}%r
File name length is => 82
-- Iteration 3 --
File name is => begin_%rx{55}%r_e%r.{19}%r
File name length is => 82
-- Iteration 4 --
File name is => begin_%rx{57}%r%r.{19}%r
File name length is => 82