cvs: /php4/ext/standard file.c file.h
| From: | Andrei Zmievski | Date: | Sat, 04 Mar 2000 17:23:33 +0000 |
| Subject: | cvs: /php4/ext/standard file.c file.h | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-11515@lists.php.net to get a copy of this message | ||
andrei Sat Mar 4 09:23:33 2000 EDT
Modified files:
/php4/ext/standard file.c file.h
Log:
@Added ftruncate() and fstat(), courtesy of Faisal Nasim <faisal@nasim.org>
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.67 php4/ext/standard/file.c:1.68
--- php4/ext/standard/file.c:1.67 Thu Feb 24 00:07:29 2000
+++ php4/ext/standard/file.c Sat Mar 4 09:23:03 2000
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: file.c,v 1.67 2000/02/24 08:07:29 eschmid Exp $ */
+/* $Id: file.c,v 1.68 2000/03/04 17:23:03 andrei Exp $ */
/* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
@@ -228,6 +228,8 @@
PHP_FE(fread, NULL)
PHP_FE(fopen, NULL)
PHP_FE(fpassthru, NULL)
+ PHP_FE(ftruncate, NULL)
+ PHP_FE(fstat, NULL)
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 */
@@ -1504,6 +1507,81 @@
}
/* }}} */
+/* {{{ proto int ftruncate (int fp, int size)
+ Truncate file to 'size' length */
+PHP_FUNCTION(ftruncate)
+{
+ zval **fp , **size;
+ short int ret;
+ int type;
+ void *what;
+
+ if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &fp, &size) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ what = zend_fetch_resource(fp,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket);
+ ZEND_VERIFY_RESOURCE(what);
+
+ if (type == le_socket)
+ {
+ php_error(E_WARNING, "can't truncate sockets!");
+ RETURN_FALSE;
+ }
+
+ convert_to_long_ex(size);
+
+ ret = ftruncate(fileno((FILE *)what), (*size)->value.lval);
+ RETURN_LONG(ret);
+}
+/* }}} */
+
+/* {{{ proto int fstat (int fp)
+ Stat() on a filehandle */
+PHP_FUNCTION(fstat)
+{
+ zval **fp;
+ int type;
+ void *what;
+ struct stat stat_sb;
+
+ if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &fp) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ what = zend_fetch_resource(fp,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket);
+ ZEND_VERIFY_RESOURCE(what);
+
+ if (fstat(fileno((FILE *) what ), &stat_sb)) {
+ RETURN_FALSE;
+ }
+
+ array_init(return_value);
+
+ 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)
Copy a file */
Index: php4/ext/standard/file.h
diff -u php4/ext/standard/file.h:1.17 php4/ext/standard/file.h:1.18
--- php4/ext/standard/file.h:1.17 Tue Feb 1 12:02:44 2000
+++ php4/ext/standard/file.h Sat Mar 4 09:23:03 2000
@@ -27,7 +27,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: file.h,v 1.17 2000/02/01 20:02:44 andrei Exp $ */
+/* $Id: file.h,v 1.18 2000/03/04 17:23:03 andrei Exp $ */
/* Synced with php 3.0 revision 1.30 1999-06-16 [ssb] */
@@ -74,6 +74,8 @@
PHP_FUNCTION(fd_isset);
PHP_FUNCTION(select);
PHP_FUNCTION(realpath);
+PHP_FUNCTION(ftruncate);
+PHP_FUNCTION(fstat);
PHPAPI int php_set_sock_blocking(int socketd, int block);
PHPAPI int php_file_le_fopen(void);