|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2020-02-05 12:05 UTC] imbolk at gmail dot com
Description:
------------
Run test code.
Test script:
---------------
<?php
/**
* @method object mkdtemp(string $template)
* @method object strerror(int $errnum)
* @property-read int $errno
*/
$ffi = FFI::cdef('
char *mkdtemp(char *template);
char *strerror(int errnum);
int errno;
');
$mkdtemp = function (string $template) use ($ffi): string {
$result = $ffi->mkdtemp($template);
if ($result === null) {
$errno = $ffi->errno;
$errstr = $ffi->strerror($errno);
throw new RuntimeException(FFI::string($errstr), $errno);
}
return FFI::string($result);
};
$template = implode(DIRECTORY_SEPARATOR, [sys_get_temp_dir(), 'ffiphp.XXXXXX']);
try {
$tmppath = $mkdtemp($template);
rmdir($tmppath);
echo "YES\n";
} catch (RuntimeException $e) {
echo $e->getMessage(), "\n";
}
try {
$tmppath = $mkdtemp($template);
rmdir($tmppath);
echo "YES\n";
} catch (RuntimeException $e) {
echo $e->getMessage(), "\n";
}
Expected result:
----------------
YES
YES
Actual result:
--------------
YES
Invalid argument
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 13:00:01 2025 UTC |
But it's completely counterintuitive. BTW this code changes the value of the constant too: define("TEMPLATE", implode(DIRECTORY_SEPARATOR, [sys_get_temp_dir(), 'ffiphp.XXXXXX'])); $mkdtemp(TEMPLATE); var_dump(TEMPLATE);Another funny example: $ffi = FFI::cdef(' char *mkdtemp(char *template); char *strerror(int errnum); int errno; '); $mkdtemp = function () use ($ffi): string { $t = '/tmp/tXXXXXX'; $result = $ffi->mkdtemp($t); if ($result === null) { $errno = $ffi->errno; $errstr = $ffi->strerror($errno); throw new RuntimeException(FFI::string($errstr), $errno); } return FFI::string($result); }; //$template = implode(DIRECTORY_SEPARATOR, [sys_get_temp_dir(), 'ffiphp.XXXXXX']); $template = '/tmp/tXXXXXX'; try { $tmppath = $mkdtemp($template); rmdir($tmppath); var_dump($template); } catch (RuntimeException $e) { echo $e->getMessage(), "\n"; } Expected: string(12) "/tmp/tXXXXXX" Actual: string(12) "/tmp/ttlGhuM"