int len;
char *buf = NULL;
int argc = ZEND_NUM_ARGS();
+ size_t line_len = 0;
php_stream *stream;
if (argc<1 || argc>2 || zend_get_parameters_ex(argc, &arg1, &arg2) == FAILURE) {
if (argc == 1) {
/* ask streams to give us a buffer of an appropriate size */
- buf = php_stream_gets(stream, NULL, 0);
+ buf = php_stream_get_line(stream, NULL, 0, &line_len);
if (buf == NULL)
goto exit_failed;
} else if (argc > 1) {
}
buf = ecalloc(len + 1, sizeof(char));
- if (php_stream_gets(stream, buf, len) == NULL)
+ if (php_stream_get_line(stream, buf, len, &line_len) == NULL)
goto exit_failed;
}
if (PG(magic_quotes_runtime)) {
- Z_STRVAL_P(return_value) = php_addslashes(buf, 0, &Z_STRLEN_P(return_value), 1 TSRMLS_CC);
+ Z_STRVAL_P(return_value) = php_addslashes(buf, line_len, &Z_STRLEN_P(return_value), 1 TSRMLS_CC);
Z_TYPE_P(return_value) = IS_STRING;
} else {
- ZVAL_STRING(return_value, buf, 0);
+ ZVAL_STRINGL(return_value, buf, line_len, 0);
/* resize buffer if it's much larger than the result.
* Only needed if the user requested a buffer size. */
if (argc > 1 && Z_STRLEN_P(return_value) < len / 2) {
- Z_STRVAL_P(return_value) = erealloc(buf, Z_STRLEN_P(return_value) + 1);
+ Z_STRVAL_P(return_value) = erealloc(buf, line_len + 1);
}
}
return;
PHPAPI int _php_stream_flush(php_stream *stream, int closing TSRMLS_DC);
#define php_stream_flush(stream) _php_stream_flush((stream), 0 TSRMLS_CC)
-PHPAPI char *_php_stream_gets(php_stream *stream, char *buf, size_t maxlen TSRMLS_DC);
-#define php_stream_gets(stream, buf, maxlen) _php_stream_gets((stream), (buf), (maxlen) TSRMLS_CC)
+PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen, size_t *returned_len TSRMLS_DC);
+#define php_stream_gets(stream, buf, maxlen) _php_stream_get_line((stream), (buf), (maxlen), NULL TSRMLS_CC)
+
+#define php_stream_get_line(stream, buf, maxlen, retlen) _php_stream_get_line((stream), (buf), (maxlen), (retlen) TSRMLS_CC)
/* CAREFUL! this is equivalent to puts NOT fputs! */
PHPAPI int _php_stream_puts(php_stream *stream, char *buf TSRMLS_DC);
/* If buf == NULL, the buffer will be allocated automatically and will be of an
* appropriate length to hold the line, regardless of the line length, memory
* permitting */
-PHPAPI char *_php_stream_gets(php_stream *stream, char *buf, size_t maxlen TSRMLS_DC)
+PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen,
+ size_t *returned_len TSRMLS_DC)
{
size_t avail = 0;
size_t current_buf_size = 0;
}
buf[0] = '\0';
+ if (returned_len)
+ *returned_len = total_copied;
return bufstart;
}