cvs: php4(PHP_4_2_0) /ext/pgsql pgsql.c

From: Date: Mon, 20 May 2002 10:30:51 +0000
Subject: cvs: php4(PHP_4_2_0) /ext/pgsql pgsql.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-12013@lists.php.net to get a copy of this message
yohgaki Mon May 20 06:30:51 2002 EDT Modified files: (Branch: PHP_4_2_0) /php4/ext/pgsql pgsql.c Log: MFH Index: php4/ext/pgsql/pgsql.c diff -u php4/ext/pgsql/pgsql.c:1.150.2.5 php4/ext/pgsql/pgsql.c:1.150.2.6 --- php4/ext/pgsql/pgsql.c:1.150.2.5 Fri Apr 5 01:45:25 2002 +++ php4/ext/pgsql/pgsql.c Mon May 20 06:30:49 2002 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pgsql.c,v 1.150.2.5 2002/04/05 06:45:25 yohgaki Exp $ */ +/* $Id: pgsql.c,v 1.150.2.6 2002/05/20 10:30:49 yohgaki Exp $ */ #include <stdlib.h> @@ -1765,12 +1765,14 @@ } /* }}} */ +#define PGSQL_LO_READ_BUF_SIZE 8192 + /* {{{ proto string pg_lo_read(resource large_object [, int len]) Read a large object */ PHP_FUNCTION(pg_lo_read) { zval **pgsql_id, **len; - int buf_len = 1024, nbytes; + int buf_len = PGSQL_LO_READ_BUF_SIZE, nbytes; char *buf; pgLofp *pgsql; @@ -1816,6 +1818,16 @@ if (argc > 2) { convert_to_long_ex(z_len); + if (Z_LVAL_PP(z_len) > Z_STRLEN_PP(str)) { + php_error(E_WARNING, "%s() cannot write more than buffer size %d. Tried to wtite %d", + get_active_function_name(TSRMLS_C), Z_LVAL_PP(str), Z_LVAL_PP(z_len)); + RETURN_FALSE; + } + if (Z_LVAL_PP(z_len) < 0) { + php_error(E_WARNING, "%s() buffer size must be larger than 0. %d specified for buffer size.", + get_active_function_name(TSRMLS_C), Z_LVAL_PP(str), Z_LVAL_PP(z_len)); + RETURN_FALSE; + } len = Z_LVAL_PP(z_len); } else { @@ -1837,11 +1849,10 @@ PHP_FUNCTION(pg_lo_read_all) { zval **pgsql_id; - int i, tbytes; + int tbytes; volatile int nbytes; - char buf[8192]; + char buf[PGSQL_LO_READ_BUF_SIZE]; pgLofp *pgsql; - int output=1; switch(ZEND_NUM_ARGS()) { case 1: @@ -1857,11 +1868,9 @@ ZEND_FETCH_RESOURCE(pgsql, pgLofp *, pgsql_id, -1, "PostgreSQL large object", le_lofp); tbytes = 0; - while ((nbytes = lo_read((PGconn *)pgsql->conn, pgsql->lofd, buf, 8192))>0) { - for(i=0; i<nbytes; i++) { - if (output) { (void) PUTC(buf[i]); } - } - tbytes += i; + while ((nbytes = lo_read((PGconn *)pgsql->conn, pgsql->lofd, buf, PGSQL_LO_READ_BUF_SIZE))>0) { + php_body_write(buf, nbytes TSRMLS_CC); + tbytes += nbytes; } RETURN_LONG(tbytes); } @@ -1888,7 +1897,7 @@ CHECK_DEFAULT_LINK(id); } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, - "rs", &pgsql_link, &file_in, &name_len) == SUCCESS) { + "sr", &file_in, &name_len, &pgsql_link) == SUCCESS) { php_error(E_NOTICE, "Old API for %s() is used.", get_active_function_name(TSRMLS_C)); } else {

« previous php.cvs (#12013) next »