$v) { $attr = 'st_'.$key; $obj->$attr = $v; } return $obj; } public static function fstatvfs($fd) { self::_unimplemented(); } public static function fsync($fd) { fsync($fd); } public static function ftruncate($fd, $length) { ftruncate($fd, $length); } public static function isatty($fd) { return posix_isatty($fd); } public static function lseek($fd, $pos, $how) { lseek($fd, $pos, $how); } public static function open($file, $flags, $mode = 0777) { // todo: define and map flag constants. See list at: // https://docs.python.org/2/library/os.html#open-flag-constants $fl = ''; if ($flags & self::O_RDONLY) { $fl .= 'r'; } if ($flags & self::O_WRONLY) { $fl .= 'w'; } if ($flags & self::O_RDWR) { $fl .= 'rw'; } if ($flags & self::O_APPEND) { $fl .= 'a'; } if ($flags & self::O_CREAT) { $fl .= 'c'; } if ($flags & self::O_EXCL) { $fl .= 'x'; } if ($flags & self::O_TRUNC) { $fl .= 'w'; } return fopen($file, $fl, false); } public static function pipe() { self::_unimplemented(); } public static function read($fd, $n) { return fread($fd, $n); } public static function tcgetpgrp($fd) { self::_unimplemented(); } public static function tcsetpgrp($fd, $pg) { self::_unimplemented(); } public static function ttyname($fd) { return posix_ttyname($fd); } public static function write($fd, $str) { return fwrite($fd, $str); } public static function access($path, $mode) { return posix_access($path, $mode); } public static function chdir($path) { chdir($path); } public static function fchdir($path) { fchdir($path); } public static function getcwd() { return getcwd(); } public static function getcwdu() { return getcwd(); } public static function chflags($path, $flags) { self::_unimplemented(); } public static function chroot($path) { chroot($path); } public static function chmode($path, $mode) { self::_unimplemented(); } public static function chown($path, $uid, $gid) { chown($path, $uid, $gid); } public static function lchflags($path, $flags) { self::_unimplemented(); } public static function lchmod($path, $mode) { self::_unimplemented(); } public static function lchown($path, $uid, $gid) { self::_unimplemented(); } public static function link($source, $link_name) { link($source, $link_name); } public static function listdir($path) { self::_unimplemented(); } public static function lstat($path) { self::_unimplemented(); } public static function mkfifo($path, $mode = 0666) { posix_mkfifo($path, $mode); } public static function mknod($filename, $mode = 0666, $device = 0) { return posix_mknod($filename, $mode); } public static function major($path, $flags) { self::_unimplemented(); } public static function minor($path, $flags) { self::_unimplemented(); } public static function makedev($major, $minor) { self::_unimplemented(); } public static function mkdir($path, $mode = 0777) { mkdir($path, $mode, $recursive = false); } public static function makedirs($path, $mode = 0777) { mkdir($path, $mode, $recursive = true); } public static function pathconf($path, $name) { self::_unimplemented(); } public static function readlink($path) { return readlink($path); } public static function remove($path) { if (!is_file($path)) { throw new OSError("Path is not a file. $path"); } try { unlink($path); } catch (Exception $e) { throw new OSError($e->getMessage(), $e->getCode()); } } public static function removedirs($path) { self::_unimplemented(); } public static function rename($src, $dst) { if (is_dir($dst)) { throw new OSError("Destination is a directory. $dst"); } rename($src, $dst); } public static function renames($old, $new) { self::makedirs(dirname($new)); self::rename($old, $new); } public static function rmdir($path) { rmdir($pat); } public static function stat($path) { $arr = stat($path); if (!$arr) { throw new OSError("Path does not exist. $path"); } $obj = new stdClass(); foreach ($arr as $key => $v) { $attr = 'st_'.$key; $obj->$attr = $v; } return $obj; } public static function stat_float_times($newvalue = null) { self::_unimplemented(); } public static function statvfs() { self::_unimplemented(); } public static function symlink($source, $link_name) { symlink($source, $link_name); } public static function tempnam($dir = null, $prefix = '') { if (!$dir) { $dir = sys_get_temp_dir(); } $name = tempnam($dir, $prefix); unlink($name); return $name; } public static function tmpnam() { return self::tempnam(); } public static function unlink($path) { unlink($path); } public static function utime($path, $times) { self::_unimplemented(); } public static function walk($top, $topdown = true, $onerror = null, $followlinks = false) { self::_unimplemented(); } /** * Begin Process Management. */ public static function abort() { self::_unimplemented(); } public static function execl($path, $arg0, $arg1) { self::_unimplemented(); } public static function execle($path, $arg0, $arg1, $env) { self::_unimplemented(); } public static function execlp($file, $arg0, $arg1) { self::_unimplemented(); } public static function execlpe($file, $arg0, $arg1, $env) { self::_unimplemented(); } public static function execv($path, $args) { self::_unimplemented(); } public static function execve($path, $args, $env) { self::_unimplemented(); } public static function execvp($file, $args) { self::_unimplemented(); } public static function execvpe($file, $args, $env) { self::_unimplemented(); } public static function _exit($n) { exit($n); } public static function fork() { return pcntl_fork(); } public static function forkpty() { self::_unimplemented(); } public static function kill($pid, $sig) { posix_kill($pid, $sig); } public static function killpg($pgid, $sig) { self::_unimplemented(); } public static function nice($increment) { proc_nice($increment); } public static function plock($op) { self::_unimplemented(); } private static function _unimplemented() { throw new Exception('Unimplemented. Please consider submitting a patch to py2php project on github.'); } }