Skip to content

Commit 1a66e04

Browse files
committed
Add silent version of php_stream_fopen_tmpfile()
1 parent 2c3da76 commit 1a66e04

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

main/streams/cast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show
282282
} else if (flags & PHP_STREAM_CAST_TRY_HARD) {
283283
php_stream *newstream;
284284

285-
newstream = php_stream_fopen_tmpfile();
285+
newstream = php_stream_fopen_tmpfile_ex(/* emit errors */ false);
286286
if (newstream) {
287287
int retcopy = php_stream_copy_to_stream_ex(stream, newstream, PHP_STREAM_COPY_ALL, NULL);
288288

main/streams/php_stream_plain_wrapper.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,13 @@ PHPAPI php_stream *_php_stream_fopen_from_fd(int fd, const char *mode, const cha
3838
PHPAPI php_stream *_php_stream_fopen_from_pipe(FILE *file, const char *mode STREAMS_DC);
3939
#define php_stream_fopen_from_pipe(file, mode) _php_stream_fopen_from_pipe((file), (mode) STREAMS_CC)
4040

41+
PHPAPI php_stream *_php_stream_fopen_tmpfile_ex(bool emit_errors, int dummy STREAMS_DC);
42+
#define php_stream_fopen_tmpfile_ex(emit_errors) _php_stream_fopen_tmpfile_ex((emit_errors), 0 STREAMS_CC)
4143
PHPAPI php_stream *_php_stream_fopen_tmpfile(int dummy STREAMS_DC);
4244
#define php_stream_fopen_tmpfile() _php_stream_fopen_tmpfile(0 STREAMS_CC)
4345

46+
PHPAPI php_stream *_php_stream_fopen_temporary_file_ex(bool emit_errors, const char *dir, const char *pfx, zend_string **opened_path_ptr STREAMS_DC);
47+
#define php_stream_fopen_temporary_file_ex(emit_errors, dir, pfx, opened_path) _php_stream_fopen_temporary_file_ex((emit_errors), (dir), (pfx), (opened_path) STREAMS_CC)
4448
PHPAPI php_stream *_php_stream_fopen_temporary_file(const char *dir, const char *pfx, zend_string **opened_path STREAMS_DC);
4549
#define php_stream_fopen_temporary_file(dir, pfx, opened_path) _php_stream_fopen_temporary_file((dir), (pfx), (opened_path) STREAMS_CC)
4650

main/streams/plain_wrapper.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static php_stream *_php_stream_fopen_from_file_int(FILE *file, const char *mode
213213
return php_stream_alloc_rel(&php_stream_stdio_ops, self, 0, mode);
214214
}
215215

216-
PHPAPI php_stream *_php_stream_fopen_temporary_file(const char *dir, const char *pfx, zend_string **opened_path_ptr STREAMS_DC)
216+
PHPAPI php_stream *_php_stream_fopen_temporary_file_ex(bool emit_errors, const char *dir, const char *pfx, zend_string **opened_path_ptr STREAMS_DC)
217217
{
218218
zend_string *opened_path = NULL;
219219
int fd;
@@ -239,13 +239,25 @@ PHPAPI php_stream *_php_stream_fopen_temporary_file(const char *dir, const char
239239
}
240240
close(fd);
241241

242-
php_error_docref(NULL, E_WARNING, "Unable to allocate stream");
242+
if (emit_errors) {
243+
php_error_docref(NULL, E_WARNING, "Unable to allocate stream");
244+
}
243245

244246
return NULL;
245247
}
246248
return NULL;
247249
}
248250

251+
PHPAPI php_stream *_php_stream_fopen_temporary_file(const char *dir, const char *pfx, zend_string **opened_path_ptr STREAMS_DC)
252+
{
253+
return php_stream_fopen_temporary_file_ex(/* emit_errors */ true, dir, pfx, opened_path_ptr);
254+
}
255+
256+
PHPAPI php_stream *_php_stream_fopen_tmpfile_ex(bool emit_errors, int dummy STREAMS_DC)
257+
{
258+
return php_stream_fopen_temporary_file_ex(emit_errors, NULL, "php", NULL);
259+
}
260+
249261
PHPAPI php_stream *_php_stream_fopen_tmpfile(int dummy STREAMS_DC)
250262
{
251263
return php_stream_fopen_temporary_file(NULL, "php", NULL);

0 commit comments

Comments
 (0)