--- file_orig.c Thu Mar 2 19:55:14 2000 +++ file.c Fri Mar 3 11:36:35 2000 @@ -228,6 +228,8 @@ PHP_FE(fread, NULL) PHP_FE(fopen, NULL) PHP_FE(fpassthru, NULL) + PHP_FE(ftruncate, NULL) // faisal + PHP_FE(fstat, NULL) // faisal PHP_FE(fseek, NULL) PHP_FE(ftell, NULL) PHP_FE(fwrite, NULL) @@ -585,6 +587,7 @@ } } + /* }}} */ /* {{{ proto string tempnam(string dir, string prefix) Create a unique filename in a directory */ @@ -1502,6 +1505,84 @@ RETVAL_TRUE; } + +/* }}} */ +/* {{{ proto int ftruncate (int fp, int size) + Truncate file to 'size' length */ +PHP_FUNCTION(ftruncate) +{ + pval **arg1 , **arg2; + short int ret; + long size; + int type; + void *what; + + if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) + { WRONG_PARAM_COUNT; } + + what = zend_fetch_resource(arg1,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket); + ZEND_VERIFY_RESOURCE(what); + + convert_to_long_ex(arg2); + size = (*arg2)->value.lval; + + if (type == le_socket) + { + php_error(E_WARNING, "can't truncate sockets!"); + RETURN_FALSE; + } + + ret = ftruncate ( fileno ( ( FILE *) what ) , size ); + RETURN_LONG(ret); +} + + +/* }}} */ +/* {{{ proto int fstat (int fp) + Stat() on a filehandle */ +PHP_FUNCTION(fstat) +{ + pval **arg1; + int type; + void *what; + struct stat stat_sb; + + if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) + { WRONG_PARAM_COUNT; } + + what = zend_fetch_resource(arg1,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket); + ZEND_VERIFY_RESOURCE(what); + + fstat ( fileno ( what ) , &stat_sb ); + + if (array_init(return_value) == FAILURE) { + RETURN_FALSE; + } + + add_assoc_long ( return_value , "dev" , stat_sb.st_dev ); + add_assoc_long ( return_value , "ino" , stat_sb.st_ino ); + add_assoc_long ( return_value , "mode" , stat_sb.st_mode ); + add_assoc_long ( return_value , "nlink" , stat_sb.st_nlink ); + add_assoc_long ( return_value , "uid" , stat_sb.st_uid ); + add_assoc_long ( return_value , "gid" , stat_sb.st_gid ); + +#ifdef HAVE_ST_BLKSIZE + add_assoc_long ( return_value, "rdev" , stat_sb.st_rdev ); + add_assoc_long ( return_value , "blksize" , stat_sb.st_blksize ); +#endif + + add_assoc_long ( return_value , "size" , stat_sb.st_size ); + add_assoc_long ( return_value , "atime" , stat_sb.st_atime ); + add_assoc_long ( return_value , "mtime" , stat_sb.st_mtime ); + add_assoc_long ( return_value , "ctime" , stat_sb.st_ctime ); + +#ifdef HAVE_ST_BLOCKS + add_assoc_long ( return_value , "blocks" , stat_sb.st_blocks ); +#endif +} + + + /* }}} */ /* {{{ proto int copy(string source_file, string destination_file)