--- file_orig.c Thu Mar 2 19:55:14 2000 +++ file.c Thu Mar 2 21:02:36 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,89 @@ 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_next_index_long(return_value, stat_sb.st_dev); + add_next_index_long(return_value, stat_sb.st_ino); + add_next_index_long(return_value, stat_sb.st_mode); + add_next_index_long(return_value, stat_sb.st_nlink); + add_next_index_long(return_value, stat_sb.st_uid); + add_next_index_long(return_value, stat_sb.st_gid); +#ifdef HAVE_ST_BLKSIZE + add_next_index_long(return_value, stat_sb.st_rdev); +#else + add_next_index_long(return_value, -1); +#endif + add_next_index_long(return_value, stat_sb.st_size); + add_next_index_long(return_value, stat_sb.st_atime); + add_next_index_long(return_value, stat_sb.st_mtime); + add_next_index_long(return_value, stat_sb.st_ctime); +#ifdef HAVE_ST_BLKSIZE + add_next_index_long(return_value, stat_sb.st_blksize); +#else + add_next_index_long(return_value, -1); +#endif +#ifdef HAVE_ST_BLOCKS + add_next_index_long(return_value, stat_sb.st_blocks); +#else + add_next_index_long(return_value, -1); +#endif +} + + + /* }}} */ /* {{{ proto int copy(string source_file, string destination_file)