$v) { $attr = "st_" . $key; $obj->$attr = $v; } return $obj; } static public function fstatvfs($fd) { self::_unimplemented(); } static public function fsync($fd) { fsync($fd); } static public function ftruncate($fd, $length) { ftruncate($fd, $length); } static public function isatty($fd) { return posix_isatty( $fd ); } static public function lseek($fd, $pos, $how) { lseek($fd, $pos, $how); } static public 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 ); } static public function pipe() { self::_unimplemented(); } static public function read($fd, $n) { return fread( $fd, $n ); } static public function tcgetpgrp($fd) { self::_unimplemented(); } static public function tcsetpgrp($fd, $pg) { self::_unimplemented(); } static public function ttyname($fd) { return posix_ttyname($fd); } static public function write($fd, $str) { return fwrite( $fd, $str ); } static function access($path, $mode) { return posix_access($path, $mode); } static function chdir($path) { chdir( $path ); } static function fchdir($path) { fchdir( $path ); } static function getcwd() { return getcwd(); } static function getcwdu() { return getcwd(); } static function chflags($path, $flags) { self::_unimplemented(); } static function chroot($path) { chroot($path); } static function chmode($path, $mode) { self::_unimplemented(); } static function chown($path, $uid, $gid) { chown($path, $uid, $gid); } static function lchflags($path, $flags) { self::_unimplemented(); } static function lchmod($path, $mode) { self::_unimplemented(); } static function lchown($path, $uid, $gid) { self::_unimplemented(); } static function link($source, $link_name) { link($source, $link_name); } static function listdir($path) { self::_unimplemented(); } static function lstat($path) { self::_unimplemented(); } static function mkfifo($path, $mode=0666) { posix_mkfifo($path, $mode); } static function mknod($filename, $mode=0666, $device=0) { return posix_mknod( $filename, $mode ); } static function major($path, $flags) { self::_unimplemented(); } static function minor($path, $flags) { self::_unimplemented(); } static function makedev($major, $minor) { self::_unimplemented(); } static function mkdir($path, $mode=0777) { mkdir($path, $mode, $recursive=false); } static function makedirs($path, $mode=0777) { mkdir($path, $mode, $recursive=true); } static function pathconf($path, $name) { self::_unimplemented(); } static function readlink($path) { return readlink($path); } 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() ); } } static function removedirs($path) { self::_unimplemented(); } static function rename($src, $dst) { if( is_dir($dst)) { throw new OSError("Destination is a directory. $dst"); } rename($src, $dst); } static function renames($old, $new) { self::makedirs( dirname($new) ); self::rename($old, $new); } static function rmdir($path) { rmdir($pat); } 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; } static function stat_float_times($newvalue=null) { self::_unimplemented(); } static function statvfs() { self::_unimplemented(); } static function symlink($source, $link_name) { symlink($source, $link_name); } static function tempnam($dir=null, $prefix='') { if( !$dir ) { $dir = sys_get_temp_dir() ; } $name = tempnam($dir, $prefix); unlink($name); return $name; } static function tmpnam() { return self::tempnam(); } static function unlink($path) { unlink($path); } static function utime($path, $times) { self::_unimplemented(); } static function walk($top, $topdown=true, $onerror=null, $followlinks=false) { self::_unimplemented(); } /** * Begin Process Management */ static function abort() { self::_unimplemented(); } static function execl($path, $arg0, $arg1) { self::_unimplemented(); } static function execle($path, $arg0, $arg1, $env) { self::_unimplemented(); } static function execlp($file, $arg0, $arg1) { self::_unimplemented(); } static function execlpe($file, $arg0, $arg1, $env) { self::_unimplemented(); } static function execv($path, $args) { self::_unimplemented(); } static function execve($path, $args, $env) { self::_unimplemented(); } static function execvp($file, $args) { self::_unimplemented(); } static function execvpe($file, $args, $env) { self::_unimplemented(); } static function _exit($n) { exit($n); } static function fork() { return pcntl_fork(); } static function forkpty() { self::_unimplemented(); } static function kill($pid, $sig) { posix_kill($pid, $sig); } static function killpg($pgid, $sig) { self::_unimplemented(); } static function nice($increment) { proc_nice($increment); } static function plock($op) { self::_unimplemented(); } private static function _unimplemented() { throw new Exception( "Unimplemented. Please consider submitting a patch to py2php project on github."); } }