static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mimetype_emu) /* {{{ */ { zend_long options = 0; char *ret_val = NULL, *buffer = NULL; size_t buffer_len; php_fileinfo *finfo = NULL; zval *zfinfo, *zcontext = NULL; zval *what; char mime_directory[] = "directory"; struct magic_set *magic = NULL; FILEINFO_DECLARE_INIT_OBJECT(object) if (mimetype_emu) { /* mime_content_type(..) emulation */ if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &what) == FAILURE) { return; } switch (Z_TYPE_P(what)) { case IS_STRING: buffer = Z_STRVAL_P(what); buffer_len = Z_STRLEN_P(what); mode = FILEINFO_MODE_FILE; break; case IS_RESOURCE: mode = FILEINFO_MODE_STREAM; break; default: php_error_docref(NULL, E_WARNING, "Can only process string or stream arguments"); RETURN_FALSE; } magic = magic_open(MAGIC_MIME_TYPE); if (magic_load(magic, NULL) == -1) { php_error_docref(NULL, E_WARNING, "Failed to load magic database."); goto common; } } else if (object) { if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|lr", &buffer, &buffer_len, &options, &zcontext) == FAILURE) { RETURN_FALSE; } FILEINFO_FROM_OBJECT(finfo, object); magic = finfo->magic; } else { if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|lr", &zfinfo, &buffer, &buffer_len, &options, &zcontext) == FAILURE) { RETURN_FALSE; } if ((finfo = (php_fileinfo *)zend_fetch_resource(Z_RES_P(zfinfo), "file_info", le_fileinfo)) == NULL) { RETURN_FALSE; } magic = finfo->magic; } /* Set options for the current file/buffer. */ if (options) { FINFO_SET_OPTION(magic, options) } switch (mode) { case FILEINFO_MODE_BUFFER: { ret_val = (char *) magic_buffer(magic, buffer, buffer_len); break; } case FILEINFO_MODE_STREAM: { php_stream *stream; zend_off_t streampos; php_stream_from_zval_no_verify(stream, what); if (!stream) { goto common; } streampos = php_stream_tell(stream); /* remember stream position for restoration */ php_stream_seek(stream, 0, SEEK_SET); ret_val = (char *) magic_stream(magic, stream); php_stream_seek(stream, streampos, SEEK_SET); break; } case FILEINFO_MODE_FILE: { /* determine if the file is a local file or remote URL */ const char *tmp2; php_stream_wrapper *wrap; php_stream_statbuf ssb; if (buffer == NULL || !*buffer) { php_error_docref(NULL, E_WARNING, "Empty filename or path"); RETVAL_FALSE; goto clean; } wrap = php_stream_locate_url_wrapper(buffer, &tmp2, 0); if (wrap) { php_stream *stream; php_stream_context *context = php_stream_context_from_zval(zcontext, 0); #ifdef PHP_WIN32 if (php_stream_stat_path_ex(buffer, 0, &ssb, context) == SUCCESS) { if (ssb.sb.st_mode & S_IFDIR) { ret_val = mime_directory; goto common; } } #endif #if PHP_API_VERSION < 20100412 stream = php_stream_open_wrapper_ex(buffer, "rb", ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, context); #else stream = php_stream_open_wrapper_ex(buffer, "rb", REPORT_ERRORS, NULL, context); #endif if (!stream) { RETVAL_FALSE; goto clean; } if (php_stream_stat(stream, &ssb) == SUCCESS) { if (ssb.sb.st_mode & S_IFDIR) { ret_val = mime_directory; } else { ret_val = (char *)magic_stream(magic, stream); } } php_stream_close(stream); } break; } default: php_error_docref(NULL, E_WARNING, "Can only process string or stream arguments"); } common: if (ret_val) { RETVAL_STRING(ret_val); } else { php_error_docref(NULL, E_WARNING, "Failed identify data %d:%s", magic_errno(magic), magic_error(magic)); RETVAL_FALSE; } clean: if (mimetype_emu) { magic_close(magic); } /* Restore options */ if (options) { FINFO_SET_OPTION(magic, finfo->options) } return; }
/* {{{ inifile_find_group * if found pos_grp_start points to "[group_name]" */ static int inifile_find_group(inifile *dba, const key_type *key, size_t *pos_grp_start) { int ret = FAILURE; php_stream_flush(dba->fp); php_stream_seek(dba->fp, 0, SEEK_SET); inifile_line_free(&dba->curr); inifile_line_free(&dba->next); if (key->group && strlen(key->group)) { int res; line_type ln = {{NULL,NULL},{NULL}}; res = 1; while(inifile_read(dba, &ln)) { if ((res=inifile_key_cmp(&ln.key, key)) < 2) { ret = SUCCESS; break; } *pos_grp_start = php_stream_tell(dba->fp); } inifile_line_free(&ln); } else { *pos_grp_start = 0; ret = SUCCESS; } if (ret == FAILURE) { *pos_grp_start = php_stream_tell(dba->fp); } return ret; }
/* {{{ inifile_findkey */ static int inifile_read(inifile *dba, line_type *ln) { char *fline; char *pos; inifile_val_free(&ln->val); while ((fline = php_stream_gets(dba->fp, NULL, 0)) != NULL) { if (fline) { if (fline[0] == '[') { /* A value name cannot start with '[' * So either we find a ']' or we found an error */ pos = strchr(fline+1, ']'); if (pos) { *pos = '\0'; inifile_key_free(&ln->key); ln->key.group = etrim(fline+1); ln->key.name = estrdup(""); ln->pos = php_stream_tell(dba->fp); efree(fline); return 1; } else { efree(fline); continue; } } else { pos = strchr(fline, '='); if (pos) { *pos = '\0'; /* keep group or make empty if not existent */ if (!ln->key.group) { ln->key.group = estrdup(""); } if (ln->key.name) { efree(ln->key.name); } ln->key.name = etrim(fline); ln->val.value = etrim(pos+1); ln->pos = php_stream_tell(dba->fp); efree(fline); return 1; } else { /* simply ignore lines without '=' * those should be comments */ efree(fline); continue; } } } } inifile_line_free(ln); return 0; }
static size_t on_data_available(char *data, size_t size, size_t nmemb, void *ctx) { php_stream *stream = (php_stream *) ctx; php_curl_stream *curlstream = (php_curl_stream *) stream->abstract; size_t wrote; TSRMLS_FETCH(); /* TODO: I'd like to deprecate this. * This code is here because until we start getting real data, we don't know * if we have had all of the headers * */ if (curlstream->readbuffer.writepos == 0) { zval *sym; if (!EG(active_symbol_table)) { zend_rebuild_symbol_table(TSRMLS_C); } MAKE_STD_ZVAL(sym); *sym = *curlstream->headers; zval_copy_ctor(sym); ZEND_SET_SYMBOL(EG(active_symbol_table), "http_response_header", sym); } php_stream_seek(curlstream->readbuffer.buf, curlstream->readbuffer.writepos, SEEK_SET); wrote = php_stream_write(curlstream->readbuffer.buf, data, size * nmemb); curlstream->readbuffer.writepos = php_stream_tell(curlstream->readbuffer.buf); return wrote; }
static size_t php_curl_stream_read(php_stream *stream, char *buf, size_t count TSRMLS_DC) { php_curl_stream *curlstream = (php_curl_stream *) stream->abstract; size_t didread = 0; if (curlstream->readbuffer.readpos >= curlstream->readbuffer.writepos && curlstream->pending) { /* we need to read some more data */ struct timeval tv; /* fire up the connection */ if (curlstream->readbuffer.writepos == 0) { while (CURLM_CALL_MULTI_PERFORM == curl_multi_perform(curlstream->multi, &curlstream->pending)); } do { FD_ZERO(&curlstream->readfds); FD_ZERO(&curlstream->writefds); FD_ZERO(&curlstream->excfds); /* get the descriptors from curl */ curl_multi_fdset(curlstream->multi, &curlstream->readfds, &curlstream->writefds, &curlstream->excfds, &curlstream->maxfd); /* if we are in blocking mode, set a timeout */ tv.tv_usec = 0; tv.tv_sec = 15; /* TODO: allow this to be configured from the script */ /* wait for data */ switch ((curlstream->maxfd < 0) ? 1 : select(curlstream->maxfd + 1, &curlstream->readfds, &curlstream->writefds, &curlstream->excfds, &tv)) { case -1: /* error */ return 0; case 0: /* no data yet: timed-out */ return 0; default: /* fetch the data */ do { curlstream->mcode = curl_multi_perform(curlstream->multi, &curlstream->pending); } while (curlstream->mcode == CURLM_CALL_MULTI_PERFORM); } } while (curlstream->maxfd >= 0 && curlstream->readbuffer.readpos >= curlstream->readbuffer.writepos && curlstream->pending > 0); } /* if there is data in the buffer, try and read it */ if (curlstream->readbuffer.writepos > 0 && curlstream->readbuffer.readpos < curlstream->readbuffer.writepos) { php_stream_seek(curlstream->readbuffer.buf, curlstream->readbuffer.readpos, SEEK_SET); didread = php_stream_read(curlstream->readbuffer.buf, buf, count); curlstream->readbuffer.readpos = php_stream_tell(curlstream->readbuffer.buf); } if (didread == 0) { stream->eof = 1; } return didread; }
/* {{{ inifile_next_group * only valid after a call to inifile_find_group * if any next group is found pos_grp_start points to "[group_name]" or whitespace before that */ static int inifile_next_group(inifile *dba, const key_type *key, size_t *pos_grp_start) { int ret = FAILURE; line_type ln = {{NULL,NULL},{NULL}}; *pos_grp_start = php_stream_tell(dba->fp); ln.key.group = estrdup(key->group); while(inifile_read(dba, &ln)) { if (inifile_key_cmp(&ln.key, key) == 2) { ret = SUCCESS; break; } *pos_grp_start = php_stream_tell(dba->fp); } inifile_line_free(&ln); return ret; }
/* {{{ inifile_filter * copy from to dba while ignoring key name (group must equal) */ static int inifile_filter(inifile *dba, inifile *from, const key_type *key, zend_bool *found) { size_t pos_start = 0, pos_next = 0, pos_curr; int ret = SUCCESS; line_type ln = {{NULL,NULL},{NULL}}; php_stream_seek(from->fp, 0, SEEK_SET); php_stream_seek(dba->fp, 0, SEEK_END); while(inifile_read(from, &ln)) { switch(inifile_key_cmp(&ln.key, key)) { case 0: if (found) { *found = (zend_bool) 1; } pos_curr = php_stream_tell(from->fp); if (pos_start != pos_next) { php_stream_seek(from->fp, pos_start, SEEK_SET); if (SUCCESS != php_stream_copy_to_stream_ex(from->fp, dba->fp, pos_next - pos_start, NULL)) { php_error_docref(NULL, E_WARNING, "Could not copy [%zu - %zu] from temporary stream", pos_next, pos_start); ret = FAILURE; } php_stream_seek(from->fp, pos_curr, SEEK_SET); } pos_next = pos_start = pos_curr; break; case 1: pos_next = php_stream_tell(from->fp); break; case 2: /* the function is meant to process only entries from same group */ assert(0); break; } } if (pos_start != pos_next) { php_stream_seek(from->fp, pos_start, SEEK_SET); if (SUCCESS != php_stream_copy_to_stream_ex(from->fp, dba->fp, pos_next - pos_start, NULL)) { php_error_docref(NULL, E_WARNING, "Could not copy [%zu - %zu] from temporary stream", pos_next, pos_start); ret = FAILURE; } } inifile_line_free(&ln); return ret; }
/* {{{ flatfile_delete */ int flatfile_delete(flatfile *dba, datum key_datum TSRMLS_DC) { char *key = key_datum.dptr; size_t size = key_datum.dsize; size_t buf_size = FLATFILE_BLOCK_SIZE; char *buf = emalloc(buf_size); size_t num; size_t pos; php_stream_rewind(dba->fp); while(!php_stream_eof(dba->fp)) { /* read in the length of the key name */ if (!php_stream_gets(dba->fp, buf, 15)) { break; } num = atoi(buf); if (num >= buf_size) { buf_size = num + FLATFILE_BLOCK_SIZE; buf = erealloc(buf, buf_size); } pos = php_stream_tell(dba->fp); /* read in the key name */ num = php_stream_read(dba->fp, buf, num); if (num < 0) { break; } if (size == num && !memcmp(buf, key, size)) { php_stream_seek(dba->fp, pos, SEEK_SET); php_stream_putc(dba->fp, 0); php_stream_flush(dba->fp); php_stream_seek(dba->fp, 0L, SEEK_END); efree(buf); return SUCCESS; } /* read in the length of the value */ if (!php_stream_gets(dba->fp, buf, 15)) { break; } num = atoi(buf); if (num >= buf_size) { buf_size = num + FLATFILE_BLOCK_SIZE; buf = erealloc(buf, buf_size); } /* read in the value */ num = php_stream_read(dba->fp, buf, num); if (num < 0) { break; } } efree(buf); return FAILURE; }
/* {{{ inifile_fetch */ val_type inifile_fetch(inifile *dba, const key_type *key, int skip) { line_type ln = {{NULL,NULL},{NULL}}; val_type val; int res, grp_eq = 0; if (skip == -1 && dba->next.key.group && dba->next.key.name && !inifile_key_cmp(&dba->next.key, key)) { /* we got position already from last fetch */ php_stream_seek(dba->fp, dba->next.pos, SEEK_SET); ln.key.group = estrdup(dba->next.key.group); } else { /* specific instance or not same key -> restart search */ /* the slow way: restart and seacrch */ php_stream_rewind(dba->fp); inifile_line_free(&dba->next); } if (skip == -1) { skip = 0; } while(inifile_read(dba, &ln)) { if (!(res=inifile_key_cmp(&ln.key, key))) { if (!skip) { val.value = estrdup(ln.val.value ? ln.val.value : ""); /* allow faster access by updating key read into next */ inifile_line_free(&dba->next); dba->next = ln; dba->next.pos = php_stream_tell(dba->fp); return val; } skip--; } else if (res == 1) { grp_eq = 1; } else if (grp_eq) { /* we are leaving group now: that means we cannot find the key */ break; } } inifile_line_free(&ln); dba->next.pos = php_stream_tell(dba->fp); return ln.val; }
/* {{{ flatfile_nextkey */ datum flatfile_nextkey(flatfile *dba) { datum res; size_t num; size_t buf_size = FLATFILE_BLOCK_SIZE; char *buf = emalloc(buf_size); php_stream_seek(dba->fp, dba->CurrentFlatFilePos, SEEK_SET); while(!php_stream_eof(dba->fp)) { if (!php_stream_gets(dba->fp, buf, 15)) { break; } num = atoi(buf); if (num >= buf_size) { buf_size = num + FLATFILE_BLOCK_SIZE; buf = erealloc(buf, buf_size); } num = php_stream_read(dba->fp, buf, num); if (!php_stream_gets(dba->fp, buf, 15)) { break; } num = atoi(buf); if (num >= buf_size) { buf_size = num + FLATFILE_BLOCK_SIZE; buf = erealloc(buf, buf_size); } num = php_stream_read(dba->fp, buf, num); if (*(buf)!=0) { dba->CurrentFlatFilePos = php_stream_tell(dba->fp); res.dptr = buf; res.dsize = num; return res; } } efree(buf); res.dptr = NULL; res.dsize = 0; return res; }
/* {{{ php_stream_cast */ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show_err) { int flags = castas & PHP_STREAM_CAST_MASK; castas &= ~PHP_STREAM_CAST_MASK; /* synchronize our buffer (if possible) */ if (ret && castas != PHP_STREAM_AS_FD_FOR_SELECT) { php_stream_flush(stream); if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) { zend_off_t dummy; stream->ops->seek(stream, stream->position, SEEK_SET, &dummy); stream->readpos = stream->writepos = 0; } } /* filtered streams can only be cast as stdio, and only when fopencookie is present */ if (castas == PHP_STREAM_AS_STDIO) { if (stream->stdiocast) { if (ret) { *(FILE**)ret = stream->stdiocast; } goto exit_success; } /* if the stream is a stdio stream let's give it a chance to respond * first, to avoid doubling up the layers of stdio with an fopencookie */ if (php_stream_is(stream, PHP_STREAM_IS_STDIO) && stream->ops->cast && !php_stream_is_filtered(stream) && stream->ops->cast(stream, castas, ret) == SUCCESS ) { goto exit_success; } #if HAVE_FOPENCOOKIE /* if just checking, say yes we can be a FILE*, but don't actually create it yet */ if (ret == NULL) { goto exit_success; } { char fixed_mode[5]; php_stream_mode_sanitize_fdopen_fopencookie(stream, fixed_mode); *(FILE**)ret = fopencookie(stream, fixed_mode, PHP_STREAM_COOKIE_FUNCTIONS); } if (*ret != NULL) { zend_off_t pos; stream->fclose_stdiocast = PHP_STREAM_FCLOSE_FOPENCOOKIE; /* If the stream position is not at the start, we need to force * the stdio layer to believe it's real location. */ pos = php_stream_tell(stream); if (pos > 0) { zend_fseek(*ret, pos, SEEK_SET); } goto exit_success; } /* must be either: a) programmer error b) no memory -> lets bail */ php_error_docref(NULL, E_ERROR, "fopencookie failed"); return FAILURE; #endif if (!php_stream_is_filtered(stream) && stream->ops->cast && stream->ops->cast(stream, castas, NULL) == SUCCESS) { if (FAILURE == stream->ops->cast(stream, castas, ret)) { return FAILURE; } goto exit_success; } else if (flags & PHP_STREAM_CAST_TRY_HARD) { php_stream *newstream; newstream = php_stream_fopen_tmpfile(); if (newstream) { int retcopy = php_stream_copy_to_stream_ex(stream, newstream, PHP_STREAM_COPY_ALL, NULL); if (retcopy != SUCCESS) { php_stream_close(newstream); } else { int retcast = php_stream_cast(newstream, castas | flags, (void **)ret, show_err); if (retcast == SUCCESS) { rewind(*(FILE**)ret); } /* do some specialized cleanup */ if ((flags & PHP_STREAM_CAST_RELEASE)) { php_stream_free(stream, PHP_STREAM_FREE_CLOSE_CASTED); } /* TODO: we probably should be setting .stdiocast and .fclose_stdiocast or * we may be leaking the FILE*. Needs investigation, though. */ return retcast; } } } } if (php_stream_is_filtered(stream)) { php_error_docref(NULL, E_WARNING, "cannot cast a filtered stream on this system"); return FAILURE; } else if (stream->ops->cast && stream->ops->cast(stream, castas, ret) == SUCCESS) { goto exit_success; } if (show_err) { /* these names depend on the values of the PHP_STREAM_AS_XXX defines in php_streams.h */ static const char *cast_names[4] = { "STDIO FILE*", "File Descriptor", "Socket Descriptor", "select()able descriptor" }; php_error_docref(NULL, E_WARNING, "cannot represent a stream of type %s as a %s", stream->ops->label, cast_names[castas]); } return FAILURE; exit_success: if ((stream->writepos - stream->readpos) > 0 && stream->fclose_stdiocast != PHP_STREAM_FCLOSE_FOPENCOOKIE && (flags & PHP_STREAM_CAST_INTERNAL) == 0 ) { /* the data we have buffered will be lost to the third party library that * will be accessing the stream. Emit a warning so that the end-user will * know that they should try something else */ php_error_docref(NULL, E_WARNING, ZEND_LONG_FMT " bytes of buffered data lost during stream conversion!", (zend_long)(stream->writepos - stream->readpos)); } if (castas == PHP_STREAM_AS_STDIO && ret) { stream->stdiocast = *(FILE**)ret; } if (flags & PHP_STREAM_CAST_RELEASE) { php_stream_free(stream, PHP_STREAM_FREE_CLOSE_CASTED); } return SUCCESS; }
static zend_bool php_cairo_create_ft_font_face(pecl_ft_container *ft_container, cairo_ft_font_face_object *font_face_object, php_stream *stream, zend_bool owned_stream, int load_flags, zend_bool throw_exceptions TSRMLS_DC) { FT_Stream ft_stream; stream_closure *closure; php_stream_statbuf ssbuf; FT_Open_Args open_args; int error; if (php_stream_stat(stream,&ssbuf) < 0) { return 1; } ft_container->ft_face = NULL; ft_container->ft_stream = NULL; font_face_object->closure = NULL; closure = ecalloc(1, sizeof(stream_closure)); closure->stream = stream; closure->owned_stream = owned_stream; #ifdef ZTS closure->TSRMLS_C = TSRMLS_C; #endif ft_stream = pecalloc(1, sizeof(*ft_stream), TRUE); ft_stream->descriptor.pointer = (void *)closure; ft_stream->pos = php_stream_tell(stream); ft_stream->size = ssbuf.sb.st_size; ft_stream->read = php_cairo_ft_read_func; open_args.flags = FT_OPEN_STREAM; open_args.stream = ft_stream; error = FT_Open_Face(ft_container->ft_lib, &open_args, 0, &ft_container->ft_face); if (error) { if (owned_stream) { php_stream_close(stream); } efree(closure); pefree(ft_stream, TRUE); return error; } font_face_object->closure = closure; ft_container->ft_stream = ft_stream; font_face_object->font_face = (cairo_font_face_t *)cairo_ft_font_face_create_for_ft_face(ft_container->ft_face, (int)load_flags); /* Set Cairo to automatically destroy the FT_Face when the cairo_font_face_t is destroyed */ error = cairo_font_face_set_user_data ( font_face_object->font_face, &font_face_object->key, ft_container, (cairo_destroy_func_t) cairo_user_data_callback_ft_free); if (error) { cairo_font_face_destroy (font_face_object->font_face); FT_Done_Face(ft_container->ft_face); pefree(ft_stream, TRUE); return error; } return 0; }
int cdb_file_lseek(php_stream *fp, off_t offset, int whence TSRMLS_DC) { php_stream_seek(fp, offset, whence); return php_stream_tell(fp); }
zend_off_t cdb_file_lseek(php_stream *fp, zend_off_t offset, int whence) { php_stream_seek(fp, offset, whence); return php_stream_tell(fp); }
/* {{{ inifile_delete_replace_append */ static int inifile_delete_replace_append(inifile *dba, const key_type *key, const val_type *value, int append, zend_bool *found) { size_t pos_grp_start=0, pos_grp_next; inifile *ini_tmp = NULL; php_stream *fp_tmp = NULL; int ret; /* 1) Search group start * 2) Search next group * 3) If not append: Copy group to ini_tmp * 4) Open temp_stream and copy remainder * 5) Truncate stream * 6) If not append AND key.name given: Filtered copy back from ini_tmp * to stream. Otherwise the user wanted to delete the group. * 7) Append value if given * 8) Append temporary stream */ assert(!append || (key->name && value)); /* missuse */ /* 1 - 3 */ inifile_find_group(dba, key, &pos_grp_start); inifile_next_group(dba, key, &pos_grp_next); if (append) { ret = SUCCESS; } else { ret = inifile_copy_to(dba, pos_grp_start, pos_grp_next, &ini_tmp); } /* 4 */ if (ret == SUCCESS) { fp_tmp = php_stream_temp_create(0, 64 * 1024); if (!fp_tmp) { php_error_docref(NULL, E_WARNING, "Could not create temporary stream"); ret = FAILURE; } else { php_stream_seek(dba->fp, 0, SEEK_END); if (pos_grp_next != (size_t)php_stream_tell(dba->fp)) { php_stream_seek(dba->fp, pos_grp_next, SEEK_SET); if (SUCCESS != php_stream_copy_to_stream_ex(dba->fp, fp_tmp, PHP_STREAM_COPY_ALL, NULL)) { php_error_docref(NULL, E_WARNING, "Could not copy remainder to temporary stream"); ret = FAILURE; } } } } /* 5 */ if (ret == SUCCESS) { if (!value || (key->name && strlen(key->name))) { ret = inifile_truncate(dba, append ? pos_grp_next : pos_grp_start); /* writes error on fail */ } } if (ret == SUCCESS) { if (key->name && strlen(key->name)) { /* 6 */ if (!append && ini_tmp) { ret = inifile_filter(dba, ini_tmp, key, found); } /* 7 */ /* important: do not query ret==SUCCESS again: inifile_filter might fail but * however next operation must be done. */ if (value) { if (pos_grp_start == pos_grp_next && key->group && strlen(key->group)) { php_stream_printf(dba->fp, "[%s]\n", key->group); } php_stream_printf(dba->fp, "%s=%s\n", key->name, value->value ? value->value : ""); } } /* 8 */ /* important: do not query ret==SUCCESS again: inifile_filter might fail but * however next operation must be done. */ if (fp_tmp && php_stream_tell(fp_tmp)) { php_stream_seek(fp_tmp, 0, SEEK_SET); php_stream_seek(dba->fp, 0, SEEK_END); if (SUCCESS != php_stream_copy_to_stream_ex(fp_tmp, dba->fp, PHP_STREAM_COPY_ALL, NULL)) { zend_throw_error(NULL, "Could not copy from temporary stream - ini file truncated"); ret = FAILURE; } } } if (ini_tmp) { php_stream_close(ini_tmp->fp); inifile_free(ini_tmp, 0); } if (fp_tmp) { php_stream_close(fp_tmp); } php_stream_flush(dba->fp); php_stream_seek(dba->fp, 0, SEEK_SET); return ret; }