xref: /PHP-8.2/main/streams/php_streams_int.h (revision 3240a747)
1 /*
2   +----------------------------------------------------------------------+
3   | Copyright (c) The PHP Group                                          |
4   +----------------------------------------------------------------------+
5   | This source file is subject to version 3.01 of the PHP license,      |
6   | that is bundled with this package in the file LICENSE, and is        |
7   | available through the world-wide-web at the following url:           |
8   | https://www.php.net/license/3_01.txt                                 |
9   | If you did not receive a copy of the PHP license and are unable to   |
10   | obtain it through the world-wide-web, please send a note to          |
11   | license@php.net so we can mail you a copy immediately.               |
12   +----------------------------------------------------------------------+
13   | Author: Wez Furlong <wez@thebrainroom.com>                           |
14   +----------------------------------------------------------------------+
15 */
16 
17 #if ZEND_DEBUG
18 
19 #define emalloc_rel_orig(size)	\
20 		( __php_stream_call_depth == 0 \
21 		? _emalloc((size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_RELAY_CC) \
22 		: _emalloc((size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_ORIG_RELAY_CC) )
23 
24 #define erealloc_rel_orig(ptr, size)	\
25 		( __php_stream_call_depth == 0 \
26 		? _erealloc((ptr), (size), 0 ZEND_FILE_LINE_CC ZEND_FILE_LINE_RELAY_CC) \
27 		: _erealloc((ptr), (size), 0 ZEND_FILE_LINE_CC ZEND_FILE_LINE_ORIG_RELAY_CC) )
28 
29 #define pemalloc_rel_orig(size, persistent)	((persistent) ? malloc((size)) : emalloc_rel_orig((size)))
30 #define perealloc_rel_orig(ptr, size, persistent)	((persistent) ? realloc((ptr), (size)) : erealloc_rel_orig((ptr), (size)))
31 #else
32 # define pemalloc_rel_orig(size, persistent)				pemalloc((size), (persistent))
33 # define perealloc_rel_orig(ptr, size, persistent)			perealloc((ptr), (size), (persistent))
34 # define emalloc_rel_orig(size)								emalloc((size))
35 #endif
36 
37 #define STREAM_DEBUG 0
38 #define STREAM_WRAPPER_PLAIN_FILES	((php_stream_wrapper*)-1)
39 
40 #ifndef MAP_FAILED
41 #define MAP_FAILED ((void *) -1)
42 #endif
43 
44 #define CHUNK_SIZE	8192
45 
46 #ifdef PHP_WIN32
47 # ifdef EWOULDBLOCK
48 #  undef EWOULDBLOCK
49 # endif
50 # define EWOULDBLOCK WSAEWOULDBLOCK
51 # ifdef EMSGSIZE
52 #  undef EMSGSIZE
53 # endif
54 # define EMSGSIZE WSAEMSGSIZE
55 #endif
56 
57 /* This functions transforms the first char to 'w' if it's not 'r', 'a' or 'w'
58  * and strips any subsequent chars except '+' and 'b'.
59  * Use this to sanitize stream->mode if you call e.g. fdopen, fopencookie or
60  * any other function that expects standard modes and you allow non-standard
61  * ones. result should be a char[5]. */
62 void php_stream_mode_sanitize_fdopen_fopencookie(php_stream *stream, char *result);
63