|
| 1 | +--TEST-- |
| 2 | +posix_access() flag (mode) validation |
| 3 | +--FILE-- |
| 4 | +<?php |
| 5 | + |
| 6 | +$dir = __DIR__; |
| 7 | +$testfile = "$dir/testfile.txt"; |
| 8 | + |
| 9 | +// Create a temporary file for valid access tests |
| 10 | +file_put_contents($testfile, "hello"); |
| 11 | + |
| 12 | +// Invalid: negative mode |
| 13 | +try { |
| 14 | + posix_access($testfile, -1); |
| 15 | +} catch (ValueError $e) { |
| 16 | + echo $e->getMessage(), "\n"; |
| 17 | +} |
| 18 | + |
| 19 | +// Invalid: mode with garbage bits |
| 20 | +try { |
| 21 | + posix_access($testfile, 01000); // S_ISVTX bit (sticky) |
| 22 | +} catch (ValueError $e) { |
| 23 | + echo $e->getMessage(), "\n"; |
| 24 | +} |
| 25 | + |
| 26 | +// Invalid: mode with unrelated high bits |
| 27 | +try { |
| 28 | + posix_access($testfile, 02000); // S_ISGID bit |
| 29 | +} catch (ValueError $e) { |
| 30 | + echo $e->getMessage(), "\n"; |
| 31 | +} |
| 32 | + |
| 33 | +// Valid: check read and write access |
| 34 | +if (posix_access($testfile, POSIX_R_OK | POSIX_W_OK)) { |
| 35 | + echo "Read/write access OK\n"; |
| 36 | +} |
| 37 | + |
| 38 | +// Valid: check file existence |
| 39 | +if (posix_access($testfile, POSIX_F_OK)) { |
| 40 | + echo "File exists OK\n"; |
| 41 | +} |
| 42 | + |
| 43 | +unlink($testfile); |
| 44 | +?> |
| 45 | +--EXPECTF-- |
| 46 | +posix_access(): Argument #2 ($flags) must be a combination of POSIX_F_OK, POSIX_R_OK, POSIX_W_OK, and POSIX_X_OK |
| 47 | +posix_access(): Argument #2 ($flags) must be a combination of POSIX_F_OK, POSIX_R_OK, POSIX_W_OK, and POSIX_X_OK |
| 48 | +posix_access(): Argument #2 ($flags) must be a combination of POSIX_F_OK, POSIX_R_OK, POSIX_W_OK, and POSIX_X_OK |
| 49 | +Read/write access OK |
| 50 | +File exists OK |
0 commit comments