[PHP-CVS] cvs: php4 /ext/standard basic_functions.c file.c file.h
sterlingWed Mar 12 01:47:35 2003 EDT Modified files: /php4/ext/standard basic_functions.c file.c file.h Log: @ Add the file_set_contents() function, as a complement to the file_get_contents() @ function. (Sterling) Index: php4/ext/standard/basic_functions.c diff -u php4/ext/standard/basic_functions.c:1.595 php4/ext/standard/basic_functions.c:1.596 --- php4/ext/standard/basic_functions.c:1.595 Sun Mar 9 18:12:31 2003 +++ php4/ext/standard/basic_functions.c Wed Mar 12 01:47:34 2003 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: basic_functions.c,v 1.595 2003/03/09 23:12:31 pollita Exp $ */ +/* $Id: basic_functions.c,v 1.596 2003/03/12 06:47:34 sterling Exp $ */ #include php.h #include php_streams.h @@ -672,6 +672,7 @@ PHP_STATIC_FE(tmpfile,php_if_tmpfile, NULL) PHP_FE(file, NULL) PHP_FE(file_get_contents, NULL) + PHP_FE(file_set_contents, NULL) PHP_FE(stream_select, first_through_third_args_force_ref) PHP_FE(stream_context_create, NULL) PHP_FE(stream_context_set_params, NULL) Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.324 php4/ext/standard/file.c:1.325 --- php4/ext/standard/file.c:1.324 Fri Mar 7 00:15:23 2003 +++ php4/ext/standard/file.cWed Mar 12 01:47:34 2003 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: file.c,v 1.324 2003/03/07 05:15:23 sniper Exp $ */ +/* $Id: file.c,v 1.325 2003/03/12 06:47:34 sterling Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -458,6 +458,34 @@ } /* }}} */ + +/* {{{ proto string file_set_contents(string file, string data) + Write/Create a file with contents data */ +PHP_FUNCTION(file_set_contents) +{ + php_stream *stream; + char *filename, *data; + size_t filename_len, data_len; + int numbytes; + zend_bool use_include_path = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, ss|b, filename, filename_len, + data, data_len, use_include_path) == FAILURE) { + return; + } + + stream = php_stream_open_wrapper(filename, wb, + (use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL); + if (data_len) { + numbytes = php_stream_write(stream, data, data_len); + if (numbytes 0) { + RETURN_FALSE; + } + } + php_stream_close(stream); + + RETURN_TRUE; +} /* {{{ proto array file(string filename [, int flags]) Read entire file into an array */ Index: php4/ext/standard/file.h diff -u php4/ext/standard/file.h:1.79 php4/ext/standard/file.h:1.80 --- php4/ext/standard/file.h:1.79 Fri Feb 28 14:53:20 2003 +++ php4/ext/standard/file.hWed Mar 12 01:47:34 2003 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: file.h,v 1.79 2003/02/28 19:53:20 wez Exp $ */ +/* $Id: file.h,v 1.80 2003/03/12 06:47:34 sterling Exp $ */ /* Synced with php 3.0 revision 1.30 1999-06-16 [ssb] */ @@ -54,6 +54,7 @@ PHP_FUNCTION(copy); PHP_FUNCTION(file); PHP_FUNCTION(file_get_contents); +PHP_FUNCTION(file_set_contents); PHP_FUNCTION(get_meta_tags); PHP_FUNCTION(flock); PHP_FUNCTION(fd_set); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard basic_functions.c file.c file.h html.c
iliaa Sat Feb 22 15:33:11 2003 EDT Modified files: /php4/ext/standard basic_functions.c file.c file.h html.c Log: int/long change. Index: php4/ext/standard/basic_functions.c diff -u php4/ext/standard/basic_functions.c:1.584 php4/ext/standard/basic_functions.c:1.585 --- php4/ext/standard/basic_functions.c:1.584 Fri Feb 21 03:45:57 2003 +++ php4/ext/standard/basic_functions.c Sat Feb 22 15:33:11 2003 -17,7 +17,7 +--+ */ -/* $Id: basic_functions.c,v 1.584 2003/02/21 08:45:57 sniper Exp $ */ +/* $Id: basic_functions.c,v 1.585 2003/02/22 20:33:11 iliaa Exp $ */ #include php.h #include php_streams.h -670,6 +670,7 PHP_STATIC_FE(tmpfile,php_if_tmpfile, NULL) PHP_FE(file, NULL) PHP_FE(file_get_contents, NULL) + PHP_FE(file_write_content, NULL) PHP_FE(stream_select, first_through_third_args_force_ref) PHP_FE(stream_context_create, NULL) PHP_FE(stream_context_set_params, NULL) Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.307 php4/ext/standard/file.c:1.308 --- php4/ext/standard/file.c:1.307 Tue Feb 18 10:15:22 2003 +++ php4/ext/standard/file.cSat Feb 22 15:33:11 2003 -21,7 +21,7 +--+ */ -/* $Id: file.c,v 1.307 2003/02/18 15:15:22 moriyoshi Exp $ */ +/* $Id: file.c,v 1.308 2003/02/22 20:33:11 iliaa Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ -406,6 +406,67 php_stream_close(md.stream); } +/* }}} */ + +/* {{{ proto int file_write_content(string filename, mixed content [, char mode [, bool use_include_path]]) + Write a string to a file. */ +PHP_FUNCTION(file_write_content) +{ + zval *content; + char *filename, *mode; + int filename_len, mode_len = 0; + zend_bool use_include_path = 0; + size_t written; + php_stream *stream; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, sz|sb, filename, filename_len, content, mode, mode_len, use_include_path) == FAILURE) { + RETURN_FALSE; + } + + if (!(stream = php_stream_open_wrapper(filename, (mode_len ? mode : wb), (use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL))) { + RETURN_FALSE; + } + + /* try to set an exclusive lock on the file to prevent access to the file while the write operation +* is happening. +*/ + php_stream_set_option(stream, PHP_STREAM_OPTION_LOCKING, F_SETLKW, (void *) F_WRLCK TSRMLS_CC); + + if (Z_TYPE_P(content) == IS_ARRAY) { + HashPosition pos; + zval **tmp; + size_t cur_write; + + written = 0; + zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(content), pos); + + while (zend_hash_get_current_data_ex(Z_ARRVAL_P(content), (void **) tmp, pos) == SUCCESS) { + SEPARATE_ZVAL(tmp); + convert_to_string(*tmp); + + if ((cur_write = php_stream_write(stream, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp))) 0) { + RETVAL_FALSE; + goto done; + } + written += cur_write; + + zend_hash_move_forward_ex(Z_ARRVAL_P(content), pos); + } + RETVAL_LONG(written); + } else { + SEPARATE_ZVAL(content); + convert_to_string(content); + if ((written = php_stream_write(stream, Z_STRVAL_P(content), Z_STRLEN_P(content))) 0) { + RETVAL_FALSE; + } else { + RETVAL_LONG(written); + } + zval_ptr_dtor(content); + } + +done: + php_stream_close(stream); +} /* }}} */ /* {{{ proto string file_get_contents(string filename [, bool use_include_path]) Index: php4/ext/standard/file.h diff -u php4/ext/standard/file.h:1.75 php4/ext/standard/file.h:1.76 --- php4/ext/standard/file.h:1.75 Mon Feb 10 17:26:53 2003 +++ php4/ext/standard/file.hSat Feb 22 15:33:11 2003 -16,7 +16,7
[PHP-CVS] cvs: php4 /ext/standard basic_functions.c file.c file.h
iliaa Sat Feb 22 15:35:22 2003 EDT Modified files: /php4/ext/standard basic_functions.c file.c file.h Log: Revent previous patch, adding of file_write_content() was premature. Index: php4/ext/standard/basic_functions.c diff -u php4/ext/standard/basic_functions.c:1.585 php4/ext/standard/basic_functions.c:1.586 --- php4/ext/standard/basic_functions.c:1.585 Sat Feb 22 15:33:11 2003 +++ php4/ext/standard/basic_functions.c Sat Feb 22 15:35:22 2003 -17,7 +17,7 +--+ */ -/* $Id: basic_functions.c,v 1.585 2003/02/22 20:33:11 iliaa Exp $ */ +/* $Id: basic_functions.c,v 1.586 2003/02/22 20:35:22 iliaa Exp $ */ #include php.h #include php_streams.h -670,7 +670,6 PHP_STATIC_FE(tmpfile,php_if_tmpfile, NULL) PHP_FE(file, NULL) PHP_FE(file_get_contents, NULL) - PHP_FE(file_write_content, NULL) PHP_FE(stream_select, first_through_third_args_force_ref) PHP_FE(stream_context_create, NULL) PHP_FE(stream_context_set_params, NULL) Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.308 php4/ext/standard/file.c:1.309 --- php4/ext/standard/file.c:1.308 Sat Feb 22 15:33:11 2003 +++ php4/ext/standard/file.cSat Feb 22 15:35:22 2003 -21,7 +21,7 +--+ */ -/* $Id: file.c,v 1.308 2003/02/22 20:33:11 iliaa Exp $ */ +/* $Id: file.c,v 1.309 2003/02/22 20:35:22 iliaa Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ -406,67 +406,6 php_stream_close(md.stream); } -/* }}} */ - -/* {{{ proto int file_write_content(string filename, mixed content [, char mode [, bool use_include_path]]) - Write a string to a file. */ -PHP_FUNCTION(file_write_content) -{ - zval *content; - char *filename, *mode; - int filename_len, mode_len = 0; - zend_bool use_include_path = 0; - size_t written; - php_stream *stream; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, sz|sb, filename, filename_len, content, mode, mode_len, use_include_path) == FAILURE) { - RETURN_FALSE; - } - - if (!(stream = php_stream_open_wrapper(filename, (mode_len ? mode : wb), (use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL))) { - RETURN_FALSE; - } - - /* try to set an exclusive lock on the file to prevent access to the file while the write operation -* is happening. -*/ - php_stream_set_option(stream, PHP_STREAM_OPTION_LOCKING, F_SETLKW, (void *) F_WRLCK TSRMLS_CC); - - if (Z_TYPE_P(content) == IS_ARRAY) { - HashPosition pos; - zval **tmp; - size_t cur_write; - - written = 0; - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(content), pos); - - while (zend_hash_get_current_data_ex(Z_ARRVAL_P(content), (void **) tmp, pos) == SUCCESS) { - SEPARATE_ZVAL(tmp); - convert_to_string(*tmp); - - if ((cur_write = php_stream_write(stream, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp))) 0) { - RETVAL_FALSE; - goto done; - } - written += cur_write; - - zend_hash_move_forward_ex(Z_ARRVAL_P(content), pos); - } - RETVAL_LONG(written); - } else { - SEPARATE_ZVAL(content); - convert_to_string(content); - if ((written = php_stream_write(stream, Z_STRVAL_P(content), Z_STRLEN_P(content))) 0) { - RETVAL_FALSE; - } else { - RETVAL_LONG(written); - } - zval_ptr_dtor(content); - } - -done: - php_stream_close(stream); -} /* }}} */ /* {{{ proto string file_get_contents(string filename [, bool use_include_path]) Index: php4/ext/standard/file.h diff -u php4/ext/standard/file.h:1.76 php4/ext/standard/file.h:1.77 --- php4/ext/standard/file.h:1.76 Sat Feb 22 15:33:11 2003 +++ php4/ext/standard/file.hSat Feb 22 15:35:22 2003 -16,7 +16,7
[PHP-CVS] cvs: php4 /ext/standard basic_functions.c file.c file.h /main php_streams.h streams.c
iliaa Sun Feb 9 15:43:06 2003 EDT Modified files: /php4/main streams.c php_streams.h /php4/ext/standard file.c file.h basic_functions.c Log: Added feature request #9173 (added stream_get_line(), this function will read either the specified number of bytes or until the ending string is found). Index: php4/main/streams.c diff -u php4/main/streams.c:1.144 php4/main/streams.c:1.145 --- php4/main/streams.c:1.144 Fri Feb 7 16:33:35 2003 +++ php4/main/streams.c Sun Feb 9 15:43:05 2003 @@ -20,7 +20,7 @@ +--+ */ -/* $Id: streams.c,v 1.144 2003/02/07 21:33:35 iliaa Exp $ */ +/* $Id: streams.c,v 1.145 2003/02/09 20:43:05 iliaa Exp $ */ #define _GNU_SOURCE #include php.h @@ -29,6 +29,7 @@ #include php_open_temporary_file.h #include ext/standard/file.h #include ext/standard/basic_functions.h /* for BG(mmap_file) (not strictly required) */ +#include ext/standard/php_string.h /* for php_memnstr, used by +php_stream_get_record() */ #ifdef HAVE_SYS_MMAN_H #include sys/mman.h #endif @@ -2607,6 +2608,40 @@ PHPAPI HashTable *php_stream_get_url_stream_wrappers_hash() { return url_stream_wrappers_hash; +} + +PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t +*returned_len, char *delim, size_t delim_len TSRMLS_DC) +{ + char *e, *buf; + size_t toread; + + php_stream_fill_read_buffer(stream, maxlen TSRMLS_CC); + + if (delim_len == 0) { + toread = maxlen; + } else { + if (delim_len == 1) { + e = memchr(stream-readbuf, *delim, stream-readbuflen); + } else { + e = php_memnstr(stream-readbuf, delim, delim_len, +(stream-readbuf + stream-readbuflen)); + } + + if (!e) { + toread = maxlen; + } else { + toread = e - (char *) stream-readbuf; + } + } + + buf = emalloc(toread + 1); + *returned_len = php_stream_read(stream, buf, toread); + + if (*returned_len = 0) { + return buf; + } else { + efree(buf); + return NULL; + } } /* Index: php4/main/php_streams.h diff -u php4/main/php_streams.h:1.67 php4/main/php_streams.h:1.68 --- php4/main/php_streams.h:1.67Fri Feb 7 17:49:21 2003 +++ php4/main/php_streams.h Sun Feb 9 15:43:05 2003 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: php_streams.h,v 1.67 2003/02/07 22:49:21 iliaa Exp $ */ +/* $Id: php_streams.h,v 1.68 2003/02/09 20:43:05 iliaa Exp $ */ #ifndef PHP_STREAMS_H #define PHP_STREAMS_H @@ -290,6 +290,7 @@ PHPAPI php_stream_filter *php_stream_filter_remove(php_stream *stream, php_stream_filter *filter, int call_dtor TSRMLS_DC); PHPAPI void php_stream_filter_free(php_stream_filter *filter TSRMLS_DC); PHPAPI php_stream_filter *_php_stream_filter_alloc(php_stream_filter_ops *fops, void *abstract, int persistent STREAMS_DC TSRMLS_DC); +PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t +*returned_len, char *delim, size_t delim_len TSRMLS_DC); #define php_stream_filter_alloc(fops, thisptr, persistent) _php_stream_filter_alloc((fops), (thisptr), (persistent) STREAMS_CC TSRMLS_CC) #define php_stream_filter_alloc_rel(fops, thisptr, persistent) _php_stream_filter_alloc((fops), (thisptr), (persistent) STREAMS_REL_CC TSRMLS_CC) Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.298 php4/ext/standard/file.c:1.299 --- php4/ext/standard/file.c:1.298 Sun Feb 9 15:35:54 2003 +++ php4/ext/standard/file.cSun Feb 9 15:43:05 2003 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: file.c,v 1.298 2003/02/09 20:35:54 iliaa Exp $ */ +/* $Id: file.c,v 1.299 2003/02/09 20:43:05 iliaa Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -1128,6 +1128,37 @@ apply_filter_to_stream(1, INTERNAL_FUNCTION_PARAM_PASSTHRU); } /* }}} */ + +/* {{{ proto string stream_get_line(resource stream, int maxlen, string ending) + Read up to maxlen bytes from a stream or until the ending string is found */ +PHP_FUNCTION(stream_get_line) +{ + char *str; + int str_len; + long max_length; + zval *zstream; + char *buf; + size_t buf_size; + php_stream *stream; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, rls, zstream, +max_length, str, str_len) == FAILURE) { + RETURN_FALSE; + } + + if (max_length 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, The maximum allowed +length must be greater then or equal to zero.); + RETURN_FALSE; + } + + php_stream_from_zval(stream, zstream);
[PHP-CVS] cvs: php4 /ext/standard basic_functions.c file.c file.h
pollita Fri Jan 3 03:02:38 2003 EDT Modified files: /php4/ext/standard file.c file.h basic_functions.c Log: Added stream_get_wrappers() Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.284 php4/ext/standard/file.c:1.285 --- php4/ext/standard/file.c:1.284 Tue Dec 31 11:07:38 2002 +++ php4/ext/standard/file.cFri Jan 3 03:02:35 2003 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: file.c,v 1.284 2002/12/31 16:07:38 sebastian Exp $ */ +/* $Id: file.c,v 1.285 2003/01/03 08:02:35 pollita Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -621,6 +621,31 @@ add_assoc_bool(return_value, timed_out, 0); add_assoc_bool(return_value, blocked, 1); add_assoc_bool(return_value, eof, php_stream_eof(stream)); + } + +} +/* }}} */ + +/* {{{ proto array stream_get_wrappers() +Retrieves list of registered stream wrappers */ +PHP_FUNCTION(stream_get_wrappers) +{ + HashTable *url_stream_wrappers_hash; + char *stream_protocol; + int stream_protocol_len = 0; + + if (ZEND_NUM_ARGS() != 0) { + WRONG_PARAM_COUNT; + } + + if (url_stream_wrappers_hash = php_stream_get_url_stream_wrappers_hash()) { + array_init(return_value); + for(zend_hash_internal_pointer_reset(url_stream_wrappers_hash); + zend_hash_get_current_key_ex(url_stream_wrappers_hash, +stream_protocol, stream_protocol_len, NULL, 0, NULL) == HASH_KEY_IS_STRING; + zend_hash_move_forward(url_stream_wrappers_hash)) + add_next_index_string(return_value,stream_protocol,1); + } else { + RETURN_FALSE; } } Index: php4/ext/standard/file.h diff -u php4/ext/standard/file.h:1.72 php4/ext/standard/file.h:1.73 --- php4/ext/standard/file.h:1.72 Tue Dec 31 11:07:39 2002 +++ php4/ext/standard/file.hFri Jan 3 03:02:36 2003 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: file.h,v 1.72 2002/12/31 16:07:39 sebastian Exp $ */ +/* $Id: file.h,v 1.73 2003/01/03 08:02:36 pollita Exp $ */ /* Synced with php 3.0 revision 1.30 1999-06-16 [ssb] */ @@ -59,6 +59,7 @@ PHP_FUNCTION(stream_select); PHP_FUNCTION(stream_set_timeout); PHP_FUNCTION(stream_set_write_buffer); +PHP_FUNCTION(stream_get_wrappers); PHP_FUNCTION(get_meta_tags); PHP_FUNCTION(flock); PHP_FUNCTION(fd_set); Index: php4/ext/standard/basic_functions.c diff -u php4/ext/standard/basic_functions.c:1.552 php4/ext/standard/basic_functions.c:1.553 --- php4/ext/standard/basic_functions.c:1.552 Wed Jan 1 06:04:43 2003 +++ php4/ext/standard/basic_functions.c Fri Jan 3 03:02:36 2003 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: basic_functions.c,v 1.552 2003/01/01 11:04:43 wez Exp $ */ +/* $Id: basic_functions.c,v 1.553 2003/01/03 08:02:36 pollita Exp $ */ #include php.h #include php_streams.h @@ -670,6 +670,7 @@ PHP_FE(stream_get_meta_data, NULL) PHP_FE(stream_register_wrapper, NULL) + PHP_FE(stream_get_wrappers, + NULL) #if HAVE_SYS_TIME_H || defined(PHP_WIN32) PHP_FE(stream_set_timeout, NULL) -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard basic_functions.c file.c file.h http_fopen_wrapper.c /ext/standard/tests/file userstreams.phpt /main user_streams.c
wez Sat Sep 28 18:14:21 2002 EDT Modified files: /php4/ext/standard basic_functions.c file.c file.h http_fopen_wrapper.c /php4/ext/standard/tests/file userstreams.phpt /php4/main user_streams.c Log: Rename streams functions to fit with naming conventions, adding aliases for old functions where required. Make use of recent changes to chunk size and timeout setting code. Index: php4/ext/standard/basic_functions.c diff -u php4/ext/standard/basic_functions.c:1.514 php4/ext/standard/basic_functions.c:1.515 --- php4/ext/standard/basic_functions.c:1.514 Fri Sep 27 19:42:38 2002 +++ php4/ext/standard/basic_functions.c Sat Sep 28 18:14:20 2002 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: basic_functions.c,v 1.514 2002/09/27 23:42:38 wez Exp $ */ +/* $Id: basic_functions.c,v 1.515 2002/09/28 22:14:20 wez Exp $ */ #include php.h #include php_streams.h @@ -630,20 +630,22 @@ PHP_FE(fgetcsv, NULL) PHP_FE(flock, NULL) PHP_FE(get_meta_tags, NULL) - PHP_FE(set_file_buffer, NULL) + PHP_FE(stream_set_write_buffer, + NULL) + PHP_FALIAS(set_file_buffer, stream_set_write_buffer, + NULL) PHP_FE(set_socket_blocking, NULL) PHP_FE(stream_set_blocking, NULL) PHP_FALIAS(socket_set_blocking, stream_set_blocking, NULL) - PHP_FE(file_get_meta_data, NULL) - PHP_FE(file_register_wrapper, NULL) + PHP_FE(stream_get_meta_data, + NULL) + PHP_FE(stream_register_wrapper, + NULL) #if HAVE_SYS_TIME_H || defined(PHP_WIN32) - PHP_FE(socket_set_timeout, NULL) + PHP_FE(stream_set_timeout, + NULL) + PHP_FALIAS(socket_set_timeout, stream_set_timeout, + NULL) #endif - PHP_FALIAS(socket_get_status, file_get_meta_data, NULL) + PHP_FALIAS(socket_get_status, stream_get_meta_data, + NULL) #if (!defined(PHP_WIN32) !defined(__BEOS__) !defined(NETWARE) HAVE_REALPATH) || defined(ZTS) PHP_FE(realpath, NULL) Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.265 php4/ext/standard/file.c:1.266 --- php4/ext/standard/file.c:1.265 Sat Sep 28 09:04:47 2002 +++ php4/ext/standard/file.cSat Sep 28 18:14:21 2002 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: file.c,v 1.265 2002/09/28 13:04:47 wez Exp $ */ +/* $Id: file.c,v 1.266 2002/09/28 22:14:21 wez Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -582,9 +582,9 @@ } /* }}} */ -/* {{{ proto resource file_get_meta_data(resource fp) +/* {{{ proto resource stream_get_meta_data(resource fp) Retrieves header/meta data from streams/file pointers */ -PHP_FUNCTION(file_get_meta_data) +PHP_FUNCTION(stream_get_meta_data) { zval **arg1; php_stream *stream; @@ -639,6 +639,7 @@ } /* }}} */ +/* {{{ stream_select related functions */ static int stream_array_to_fd_set(zval *stream_array, fd_set *fds, int *max_fd TSRMLS_DC) { zval **elem; @@ -664,9 +665,7 @@ } } } - return 1; - } static int stream_array_from_fd_set(zval *stream_array, fd_set *fds TSRMLS_DC) @@ -708,9 +707,8 @@ Z_ARRVAL_P(stream_array) = new_hash; return 1; - } - +/* }}} */ /* {{{ proto int stream_select(array
[PHP-CVS] cvs: php4 /ext/standard basic_functions.c file.c file.h
wez Fri Sep 27 19:42:38 2002 EDT Modified files: /php4/ext/standard basic_functions.c file.c file.h Log: Implement stream_select() which works just like socket_select, but only on streams. - Added stream_select() which works like socket_select but only works on streams returned by fopen(), fsockopen() and pfsockopen(). (Wez) Index: php4/ext/standard/basic_functions.c diff -u php4/ext/standard/basic_functions.c:1.513 php4/ext/standard/basic_functions.c:1.514 --- php4/ext/standard/basic_functions.c:1.513 Thu Sep 26 06:14:40 2002 +++ php4/ext/standard/basic_functions.c Fri Sep 27 19:42:38 2002 -17,7 +17,7 +--+ */ -/* $Id: basic_functions.c,v 1.513 2002/09/26 10:14:40 wez Exp $ */ +/* $Id: basic_functions.c,v 1.514 2002/09/27 23:42:38 wez Exp $ */ #include php.h #include php_streams.h -99,6 +99,9 static unsigned char second_args_force_ref[] = { 2, BYREF_NONE, BYREF_FORCE }; static unsigned char third_and_fourth_args_force_ref[] = { 4, BYREF_NONE, BYREF_NONE, BYREF_FORCE, BYREF_FORCE }; static unsigned char third_and_rest_force_ref[] = { 3, BYREF_NONE, BYREF_NONE, BYREF_FORCE_REST }; +static unsigned char first_through_third_args_force_ref[] = +{3, BYREF_FORCE, BYREF_FORCE, BYREF_FORCE}; + typedef struct _php_shutdown_function_entry { zval **arguments; -617,6 +620,7 PHP_STATIC_FE(tmpfile,php_if_tmpfile, NULL) PHP_FE(file, NULL) PHP_FE(file_get_contents, NULL) + PHP_FE(stream_select, +first_through_third_args_force_ref) PHP_FE(stream_context_create, NULL) PHP_FE(stream_context_set_params, NULL) PHP_FE(stream_context_set_option, NULL) -628,11 +632,9 PHP_FE(get_meta_tags, NULL) PHP_FE(set_file_buffer, NULL) - /* set_socket_blocking() is deprecated, - use socket_set_blocking() instead - */ PHP_FE(set_socket_blocking, NULL) - PHP_FE(socket_set_blocking, NULL) + PHP_FE(stream_set_blocking, + NULL) + PHP_FALIAS(socket_set_blocking, stream_set_blocking, + NULL) PHP_FE(file_get_meta_data, NULL) PHP_FE(file_register_wrapper, NULL) Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.263 php4/ext/standard/file.c:1.264 --- php4/ext/standard/file.c:1.263 Thu Sep 26 08:12:26 2002 +++ php4/ext/standard/file.cFri Sep 27 19:42:38 2002 -21,7 +21,7 +--+ */ -/* $Id: file.c,v 1.263 2002/09/26 12:12:26 wez Exp $ */ +/* $Id: file.c,v 1.264 2002/09/27 23:42:38 wez Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ -639,6 +639,130 } /* }}} */ +static int stream_array_to_fd_set(zval *stream_array, fd_set *fds, int *max_fd +TSRMLS_DC) +{ + zval **elem; + php_stream *stream; + int this_fd; + + if (Z_TYPE_P(stream_array) != IS_ARRAY) + return 0; + + for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(stream_array)); +zend_hash_get_current_data(Z_ARRVAL_P(stream_array), (void **) elem) +== SUCCESS; +zend_hash_move_forward(Z_ARRVAL_P(stream_array))) { + + php_stream_from_zval_no_verify(stream, elem); + if (stream == NULL) + continue; + + /* get the fd */ + if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD, +(void*)this_fd, 1)) { + FD_SET(this_fd, fds); + if (this_fd *max_fd) { + *max_fd = this_fd; + } + } + } + + return 1; +
[PHP-CVS] cvs: php4 /ext/standard basic_functions.c file.c file.h fsock.c /main main.c network.c php.h php_network.h php_streams.h streams.c
wez Wed Sep 25 11:25:13 2002 EDT Modified files: /php4/ext/standard basic_functions.c file.c file.h fsock.c /php4/main main.c network.c php.h php_network.h php_streams.h streams.c Log: Implement persistent streams. (for pfsockopen). Juggle some includes/definitions. Tidy up streams use in ext/standard/file.c Index: php4/ext/standard/basic_functions.c diff -u php4/ext/standard/basic_functions.c:1.510 php4/ext/standard/basic_functions.c:1.511 --- php4/ext/standard/basic_functions.c:1.510 Tue Sep 24 06:55:56 2002 +++ php4/ext/standard/basic_functions.c Wed Sep 25 11:25:11 2002 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: basic_functions.c,v 1.510 2002/09/24 10:55:56 zeev Exp $ */ +/* $Id: basic_functions.c,v 1.511 2002/09/25 15:25:11 wez Exp $ */ #include php.h #include php_streams.h @@ -1136,6 +1136,7 @@ PHP_RSHUTDOWN(syslog) (SHUTDOWN_FUNC_ARGS_PASSTHRU); PHP_RSHUTDOWN(assert) (SHUTDOWN_FUNC_ARGS_PASSTHRU); PHP_RSHUTDOWN(url_scanner_ex) (SHUTDOWN_FUNC_ARGS_PASSTHRU); + PHP_RSHUTDOWN(streams) (SHUTDOWN_FUNC_ARGS_PASSTHRU); if (BG(user_tick_functions)) { zend_llist_destroy(BG(user_tick_functions)); @@ -1148,7 +1149,7 @@ efree(BG(aggregation_table)); BG(aggregation_table) = NULL; } - + #ifdef HAVE_MMAP if (BG(mmap_file)) { munmap(BG(mmap_file), BG(mmap_len)); Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.257 php4/ext/standard/file.c:1.258 --- php4/ext/standard/file.c:1.257 Mon Sep 23 22:46:38 2002 +++ php4/ext/standard/file.cWed Sep 25 11:25:11 2002 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: file.c,v 1.257 2002/09/24 02:46:38 wez Exp $ */ +/* $Id: file.c,v 1.258 2002/09/25 15:25:11 wez Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -119,7 +119,6 @@ /* {{{ ZTS-stuff / Globals / Prototypes */ /* sharing globals is *evil* */ -static int le_stream = FAILURE; static int le_stream_context = FAILURE; /* }}} */ @@ -130,29 +129,14 @@ php_stream_context_free((php_stream_context*)rsrc-ptr); } -static void _file_stream_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) -{ - php_stream *stream = (php_stream*)rsrc-ptr; - /* the stream might be a pipe, so set the return value for pclose */ - FG(pclose_ret) = php_stream_free(stream, PHP_STREAM_FREE_CLOSE | PHP_STREAM_FREE_RSRC_DTOR); -} - -PHPAPI int php_file_le_stream(void) -{ - return le_stream; -} - static void file_globals_ctor(php_file_globals *file_globals_p TSRMLS_DC) { - zend_hash_init(FG(ht_persistent_socks), 0, NULL, NULL, 1); FG(pclose_ret) = 0; FG(def_chunk_size) = PHP_SOCK_CHUNK_SIZE; } - static void file_globals_dtor(php_file_globals *file_globals_p TSRMLS_DC) { - zend_hash_destroy(FG(ht_persistent_socks)); } @@ -164,7 +148,6 @@ PHP_MINIT_FUNCTION(file) { - le_stream = zend_register_list_destructors_ex(_file_stream_dtor, NULL, stream, module_number); le_stream_context = zend_register_list_destructors_ex(file_context_dtor, NULL, stream-context, module_number); #ifdef ZTS @@ -219,17 +202,16 @@ PHP_FUNCTION(flock) { zval **arg1, **arg2, **arg3; -int type, fd, act, ret, arg_count = ZEND_NUM_ARGS(); - void *what; +int fd, act, ret, arg_count = ZEND_NUM_ARGS(); + php_stream *stream; if (arg_count 3 || zend_get_parameters_ex(arg_count, arg1, arg2, arg3) == FAILURE) { WRONG_PARAM_COUNT; } - what = zend_fetch_resource(arg1 TSRMLS_CC, -1, File-Handle, type, 1, le_stream); - ZEND_VERIFY_RESOURCE(what); + php_stream_from_zval(stream, arg1); - if (php_stream_cast((php_stream*)what, PHP_STREAM_AS_FD, (void*)fd, 1) == FAILURE) { + if (php_stream_cast(stream, PHP_STREAM_AS_FD, (void*)fd, 1) == FAILURE) + { RETURN_FALSE; } @@ -600,8 +582,7 @@ if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, arg1) == FAILURE) { WRONG_PARAM_COUNT; } - stream = (php_stream*)zend_fetch_resource(arg1 TSRMLS_CC, -1, File-Handle, NULL, 1, le_stream); - ZEND_VERIFY_RESOURCE(stream); + php_stream_from_zval(stream, arg1); if (stream-wrapperdata){ *return_value = *(stream-wrapperdata); @@ -707,19 +688,23 @@ /* given a zval which is either a stream or a context, return the underlying * stream_context. If it is a stream that does not have a context assigned, it * will create and assign a context and return that. */ -static php_stream_context *decode_context_param(zval *contextresource TSRMLS_DC) { - php_stream_context *context = NULL; void *what; int type; - - what =