}
if (user_stub) {
+ zend_string *suser_stub;
if (len < 0) {
/* resource passed in */
if (!(php_stream_from_zval_no_verify(stubfile, (zval **)user_stub))) {
}
user_stub = 0;
- if (!(len = php_stream_copy_to_mem(stubfile, &user_stub, len, 0)) || !user_stub) {
+ if (!(suser_stub = php_stream_copy_to_mem(stubfile, len, 0))) {
if (closeoldfile) {
php_stream_close(oldfile);
}
return EOF;
}
free_user_stub = 1;
+ user_stub = suser_stub->val;
+ len = suser_stub->len;
} else {
free_user_stub = 0;
}
spprintf(error, 0, "illegal stub for phar \"%s\"", phar->fname);
}
if (free_user_stub) {
- efree(user_stub);
+ STR_FREE(suser_stub);
}
return EOF;
}
spprintf(error, 0, "unable to create stub from string in new phar \"%s\"", phar->fname);
}
if (free_user_stub) {
- efree(user_stub);
+ STR_FREE(suser_stub);
}
return EOF;
}
phar->halt_offset = len + 5;
if (free_user_stub) {
- efree(user_stub);
+ STR_FREE(suser_stub);
}
} else {
size_t written;
PHP_FUNCTION(shell_exec)
{
FILE *in;
- size_t total_readbytes;
char *command;
int command_len;
- char *ret;
+ zend_string *ret;
php_stream *stream;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &command, &command_len) == FAILURE) {
}
stream = php_stream_fopen_from_pipe(in, "rb");
- total_readbytes = php_stream_copy_to_mem(stream, &ret, PHP_STREAM_COPY_ALL, 0);
+ ret = php_stream_copy_to_mem(stream, PHP_STREAM_COPY_ALL, 0);
php_stream_close(stream);
- if (total_readbytes > 0) {
-//??? RETVAL_STRINGL(ret, total_readbytes, 0);
- RETVAL_STRINGL(ret, total_readbytes);
+ if (ret->len > 0) {
+ RETVAL_STR(ret);
}
}
/* }}} */
{
char *filename;
int filename_len;
- char *contents;
zend_bool use_include_path = 0;
php_stream *stream;
- int len;
long offset = -1;
long maxlen = PHP_STREAM_COPY_ALL;
zval *zcontext = NULL;
php_stream_context *context = NULL;
+ zend_string *contents;
/* Parse arguments */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|br!ll", &filename, &filename_len, &use_include_path, &zcontext, &offset, &maxlen) == FAILURE) {
RETURN_FALSE;
}
- if ((len = php_stream_copy_to_mem(stream, &contents, maxlen, 0)) > 0) {
-//??? RETVAL_STRINGL(contents, len, 0);
- RETVAL_STRINGL(contents, len);
- efree(contents);
- } else if (len == 0) {
- RETVAL_EMPTY_STRING();
+ if ((contents = php_stream_copy_to_mem(stream, maxlen, 0)) != NULL) {
+ RETVAL_STR(contents);
} else {
RETVAL_FALSE;
}
{
char *filename;
int filename_len;
- char *target_buf=NULL, *p, *s, *e;
+ char *p, *s, *e;
register int i = 0;
- int target_len;
char eol_marker = '\n';
long flags = 0;
zend_bool use_include_path;
php_stream *stream;
zval *zcontext = NULL;
php_stream_context *context = NULL;
+ zend_string *target_buf;
/* Parse arguments */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|lr!", &filename, &filename_len, &flags, &zcontext) == FAILURE) {
/* Initialize return array */
array_init(return_value);
- if ((target_len = php_stream_copy_to_mem(stream, &target_buf, PHP_STREAM_COPY_ALL, 0))) {
- s = target_buf;
- e = target_buf + target_len;
+ if ((target_buf = php_stream_copy_to_mem(stream, PHP_STREAM_COPY_ALL, 0)) != NULL) {
+ s = target_buf->val;
+ e = target_buf->val + target_buf->len;
- if (!(p = (char*)php_stream_locate_eol(stream, target_buf, target_len TSRMLS_CC))) {
+ if (!(p = (char*)php_stream_locate_eol(stream, target_buf TSRMLS_CC))) {
p = e;
goto parse_eol;
}
} else {
do {
int windows_eol = 0;
- if (p != target_buf && eol_marker == '\n' && *(p - 1) == '\r') {
+ if (p != target_buf->val && eol_marker == '\n' && *(p - 1) == '\r') {
windows_eol++;
}
if (skip_blank_lines && !(p-s-windows_eol)) {
}
if (target_buf) {
- efree(target_buf);
+ STR_FREE(target_buf);
}
php_stream_close(stream);
}
zval *zsrc;
long maxlen = PHP_STREAM_COPY_ALL,
desiredpos = -1L;
- int len;
- char *contents = NULL;
+ zend_string *contents;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|ll", &zsrc, &maxlen, &desiredpos) == FAILURE) {
RETURN_FALSE;
}
}
- len = php_stream_copy_to_mem(stream, &contents, maxlen, 0);
+ contents = php_stream_copy_to_mem(stream, maxlen, 0);
- if (contents) {
-//??? RETVAL_STRINGL(contents, len, 0);
- RETVAL_STRINGL(contents, len);
- } else {
- RETVAL_EMPTY_STRING();
- }
+ RETURN_STR(contents);
}
/* }}} */
* the ultimate ancestor, which is useful, because there can be several layers of calls */
#define php_stream_alloc_rel(ops, thisptr, persistent, mode) _php_stream_alloc((ops), (thisptr), (persistent), (mode) STREAMS_REL_CC TSRMLS_CC)
-#define php_stream_copy_to_mem_rel(src, buf, maxlen, persistent) _php_stream_copy_to_mem((src), (buf), (maxlen), (persistent) STREAMS_REL_CC TSRMLS_CC)
+#define php_stream_copy_to_mem_rel(src, maxlen, persistent) _php_stream_copy_to_mem((src), (buf), (maxlen), (persistent) STREAMS_REL_CC TSRMLS_CC)
#define php_stream_fopen_rel(filename, mode, opened, options) _php_stream_fopen((filename), (mode), (opened), (options) STREAMS_REL_CC TSRMLS_CC)
/* read all data from stream and put into a buffer. Caller must free buffer
* when done. */
-PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen,
- int persistent STREAMS_DC TSRMLS_DC);
-#define php_stream_copy_to_mem(src, buf, maxlen, persistent) _php_stream_copy_to_mem((src), (buf), (maxlen), (persistent) STREAMS_CC TSRMLS_CC)
+PHPAPI zend_string *_php_stream_copy_to_mem(php_stream *src, size_t maxlen, int persistent STREAMS_DC TSRMLS_DC);
+#define php_stream_copy_to_mem(src, maxlen, persistent) _php_stream_copy_to_mem((src), (maxlen), (persistent) STREAMS_CC TSRMLS_CC)
/* output all data from a stream */
PHPAPI size_t _php_stream_passthru(php_stream * src STREAMS_DC TSRMLS_DC);
PHPAPI int php_unregister_url_stream_wrapper_volatile(const char *protocol TSRMLS_DC);
PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC);
PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const char **path_for_open, int options TSRMLS_DC);
-PHPAPI const char *php_stream_locate_eol(php_stream *stream, const char *buf, size_t buf_len TSRMLS_DC);
+PHPAPI const char *php_stream_locate_eol(php_stream *stream, zend_string *buf TSRMLS_DC);
#define php_stream_open_wrapper(path, mode, options, opened) _php_stream_open_wrapper_ex((path), (mode), (options), (opened), NULL STREAMS_CC TSRMLS_CC)
#define php_stream_open_wrapper_ex(path, mode, options, opened, context) _php_stream_open_wrapper_ex((path), (mode), (options), (opened), (context) STREAMS_CC TSRMLS_CC)
return (stream->ops->stat)(stream, ssb TSRMLS_CC);
}
-PHPAPI const char *php_stream_locate_eol(php_stream *stream, const char *buf, size_t buf_len TSRMLS_DC)
+PHPAPI const char *php_stream_locate_eol(php_stream *stream, zend_string *buf TSRMLS_DC)
{
size_t avail;
const char *cr, *lf, *eol = NULL;
readptr = (char*)stream->readbuf + stream->readpos;
avail = stream->writepos - stream->readpos;
} else {
- readptr = buf;
- avail = buf_len;
+ readptr = buf->val;
+ avail = buf->len;
}
/* Look for EOL */
int done = 0;
readptr = (char*)stream->readbuf + stream->readpos;
- eol = php_stream_locate_eol(stream, NULL, 0 TSRMLS_CC);
+ eol = php_stream_locate_eol(stream, NULL TSRMLS_CC);
if (eol) {
cpysz = eol - readptr + 1;
}
-PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen, int persistent STREAMS_DC TSRMLS_DC)
+PHPAPI zend_string *_php_stream_copy_to_mem(php_stream *src, size_t maxlen, int persistent STREAMS_DC TSRMLS_DC)
{
size_t ret = 0;
char *ptr;
int step = CHUNK_SIZE;
int min_room = CHUNK_SIZE / 4;
php_stream_statbuf ssbuf;
+ zend_string *result;
if (maxlen == 0) {
- return 0;
+ return STR_EMPTY_ALLOC();
}
if (maxlen == PHP_STREAM_COPY_ALL) {
}
if (maxlen > 0) {
- ptr = *buf = pemalloc_rel_orig(maxlen + 1, persistent);
+ result = STR_ALLOC(maxlen, persistent);
+ ptr = result->val;
while ((len < maxlen) && !php_stream_eof(src)) {
ret = php_stream_read(src, ptr, maxlen - len);
if (!ret) {
}
if (len) {
*ptr = '\0';
+ result->len = len;
} else {
- pefree(*buf, persistent);
- *buf = NULL;
+ STR_FREE(result);
+ result = NULL;
}
- return len;
+ return result;
}
/* avoid many reallocs by allocating a good sized chunk to begin with, if
max_len = step;
}
- ptr = *buf = pemalloc_rel_orig(max_len, persistent);
+ result = STR_ALLOC(max_len, persistent);
+ ptr = result->val;
- while((ret = php_stream_read(src, ptr, max_len - len))) {
+ while ((ret = php_stream_read(src, ptr, max_len - len))) {
len += ret;
if (len + min_room >= max_len) {
- *buf = perealloc_rel_orig(*buf, max_len + step, persistent);
+ result = STR_REALLOC(result, max_len + step, persistent);
max_len += step;
- ptr = *buf + len;
+ ptr = result->val + len;
} else {
ptr += ret;
}
}
if (len) {
- *buf = perealloc_rel_orig(*buf, len + 1, persistent);
- (*buf)[len] = '\0';
+ result = STR_REALLOC(result, len, persistent);
+ result->val[len] = '\0';
} else {
- pefree(*buf, persistent);
- *buf = NULL;
+ STR_FREE(result);
+ result = NULL;
}
- return len;
+
+ return result;
}
/* Returns SUCCESS/FAILURE and sets *len to the number of bytes moved */