Re: [PHP4BETA] File truncation
| From: | Faisal Nasim | Date: | Mon, 28 Feb 2000 15:26:45 +0000 |
| Subject: | Re: [PHP4BETA] File truncation | ||
| References: | 1 2 3 4 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-11132@lists.php.net to get a copy of this message | ||
Hi,
Unofficial, untested addon! ;-)
--- file_orig.h Wed Feb 02 01:02:44 2000
+++ file.h Mon Feb 28 20:12:10 2000
@@ -74,6 +74,7 @@
PHP_FUNCTION(fd_isset);
PHP_FUNCTION(select);
PHP_FUNCTION(realpath);
+PHP_FUNCTION(ftruncate);
PHPAPI int php_set_sock_blocking(int socketd, int block);
PHPAPI int php_file_le_fopen(void);
--- file_orig.c Sun Feb 20 04:41:20 2000
+++ file.c Mon Feb 28 20:25:08 2000
@@ -228,6 +228,7 @@
PHP_FE(fread, NULL)
PHP_FE(fopen, NULL)
PHP_FE(fpassthru, NULL)
+ PHP_FE(ftruncate, NULL)
PHP_FE(fseek, NULL)
PHP_FE(ftell, NULL)
PHP_FE(fwrite, NULL)
@@ -1468,6 +1469,35 @@
zend_list_delete((*arg1)->value.lval);
RETURN_LONG(size);
}
+
+/* }}} */
+/* {{{ proto int ftruncateall (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_socke
t);
+ ZEND_VERIFY_RESOURCE(what);
+
+ convert_to_long_ex(arg2);
+ size = (*arg2)->value.lval;
+
+ if (type == le_socket)
+ { WRONG_PARAM_COUNT; /* Change this to correct one */ }
+
+ ret = ftruncate ( fileno ( ( FILE *) what ) , size );
+ RETURN_LONG(ret);
+}
+
+
/* }}} */
/* {{{ proto int rename(string old_name, string new_name)
: : I wrote a class with a bunch of file functions, ftruncate being one of
: them, in
: : PHP, I am going to try to add it to PEAR once I figure out how to add
: stuff to
: : the repository and add a few more functions.
:
: Cool. But I think it will be MUCH faster if an internal function
ftruncate()
: would call ftruncate() (C function) on a valid file descriptor (handle in
: PHP).
:
: You could also create another function to accept the *file handle* instead
: of the physical file path for truncation, but this would require you to
: check if the handle passed is valid descriptor of an open file but I can't
: find any function which allows you to verify that.
:
: I don't know if it would be useful or not, but I don't find ungetc()
: either! (fgetc() is there!)
:
:
:
: Faisal
:
: P.S. oops, just checked, they call it 'file pointer' and neither 'file
: descriptor'
: nor 'file handle'.
:
: :
: : Sterling Hughes
: : sterling@designmultimedia.com
: :
: : (class attached)
: :
: : > Because you havent opened up the source and coded it in yet?
: : >
: : > Seriously, its probably because no-one has needed it before.
: : >
: : > Matt
: : >
: : > Faisal Nasim wrote:
: : > >
: : > > Hi,
: : > >
: : > > Why doesn't PHP support ftruncate()?
: : > >
: : > > Thanks.
: : > >
: : > > Faisal