summaryrefslogtreecommitdiffstats
path: root/xattr-php7.patch
blob: fbd2285395e63487de708369cbfc7f3579ebf946 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
--- pecl/xattr/trunk/php_xattr.h	2015/04/06 16:58:20	336402
+++ pecl/xattr/trunk/php_xattr.h	2015/04/06 17:01:25	336403
@@ -1,13 +1,13 @@
 /*
   +----------------------------------------------------------------------+
-  | PHP Version 5                                                        |
+  | PHP Version 5, 7                                                     |
   +----------------------------------------------------------------------+
-  | Copyright (c) 1997-2004 The PHP Group                                |
+  | Copyright (c) 1997-2015 The PHP Group                                |
   +----------------------------------------------------------------------+
-  | This source file is subject to version 3.0 of the PHP license,       |
+  | This source file is subject to version 3.01 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
   | available through the world-wide-web at the following url:           |
-  | http://www.php.net/license/3_0.txt.                                  |
+  | http://www.php.net/license/3_01.txt.                                 |
   | If you did not receive a copy of the PHP license and are unable to   |
   | obtain it through the world-wide-web, please send a note to          |
   | license@php.net so we can mail you a copy immediately.               |
@@ -45,6 +45,17 @@
 PHP_FUNCTION(xattr_list);
 PHP_FUNCTION(xattr_supported);
 
+#if PHP_MAJOR_VERSION < 7
+typedef long zend_long;
+typedef int strsize_t;
+#define _RETVAL_STRINGL(s,l,d) RETVAL_STRINGL(s,l,d)
+#define _RETURN_STRINGL(s,l,d) RETURN_STRINGL(s,l,d)
+#else
+typedef size_t strsize_t;
+#define _RETVAL_STRINGL(s,l,d) { RETVAL_STRINGL(s,l); if (!d) efree(s); }
+#define _RETURN_STRINGL(s,l,d) { _RETVAL_STRINGL(s,l,d); return; }
+#endif
+
 #endif	/* PHP_XATTR_H */
 
 
--- pecl/xattr/trunk/xattr.c	2015/04/06 16:58:20	336402
+++ pecl/xattr/trunk/xattr.c	2015/04/06 17:01:25	336403
@@ -1,13 +1,13 @@
 /*
   +----------------------------------------------------------------------+
-  | PHP Version 5                                                        |
+  | PHP Version 5, 7                                                     |
   +----------------------------------------------------------------------+
-  | Copyright (c) 1997-2004 The PHP Group                                |
+  | Copyright (c) 1997-2015 The PHP Group                                |
   +----------------------------------------------------------------------+
-  | This source file is subject to version 3.0 of the PHP license,       |
+  | This source file is subject to version 3.01 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
   | available through the world-wide-web at the following url:           |
-  | http://www.php.net/license/3_0.txt.                                  |
+  | http://www.php.net/license/3_01.txt                                  |
   | If you did not receive a copy of the PHP license and are unable to   |
   | obtain it through the world-wide-web, please send a note to          |
   | license@php.net so we can mail you a copy immediately.               |
@@ -43,17 +43,39 @@
 #include <sys/types.h>
 #include <attr/xattr.h>
 
+ZEND_BEGIN_ARG_INFO_EX(xattr_set_arginfo, 0, 0, 3)
+  ZEND_ARG_INFO(0, path)
+  ZEND_ARG_INFO(0, name)
+  ZEND_ARG_INFO(0, value)
+  ZEND_ARG_INFO(0, flags)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(xattr_get_arginfo, 0, 0, 2)
+  ZEND_ARG_INFO(0, path)
+  ZEND_ARG_INFO(0, name)
+  ZEND_ARG_INFO(0, flags)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(xattr_list_arginfo, 0, 0, 1)
+  ZEND_ARG_INFO(0, path)
+  ZEND_ARG_INFO(0, flags)
+ZEND_END_ARG_INFO()
+
 /* {{{ xattr_functions[]
  *
  * Every user visible function must have an entry in xattr_functions[].
  */
 zend_function_entry xattr_functions[] = {
-	PHP_FE(xattr_set,		NULL)
-	PHP_FE(xattr_get,		NULL)
-	PHP_FE(xattr_remove,	NULL)
-	PHP_FE(xattr_list,		NULL)
-	PHP_FE(xattr_supported,	NULL)
-	{NULL, NULL, NULL}	/* Must be the last line in xattr_functions[] */
+	PHP_FE(xattr_set,       xattr_set_arginfo)
+	PHP_FE(xattr_get,       xattr_get_arginfo)
+	PHP_FE(xattr_remove,    xattr_get_arginfo)
+	PHP_FE(xattr_list,      xattr_list_arginfo)
+	PHP_FE(xattr_supported,	xattr_list_arginfo)
+#ifdef PHP_FE_END
+	PHP_FE_END
+#else
+	{ NULL, NULL, NULL }
+#endif
 };
 /* }}} */
 
@@ -112,7 +134,9 @@
 	char *attr_name = NULL;
 	char *attr_value = NULL;
 	char *path = NULL;
-	int error, tmp, value_len, flags = 0;
+	int error;
+	zend_long flags = 0;
+	strsize_t tmp, value_len;
 
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss|l", &path, &tmp, &attr_name, &tmp, &attr_value, &value_len, &flags) == FAILURE) {
 		return;
@@ -131,7 +155,7 @@
 	flags &= ATTR_ROOT | ATTR_DONTFOLLOW | ATTR_CREATE | ATTR_REPLACE; 
 	
 	/* Attempt to set an attribute, warn if failed. */ 
-	error = attr_set(path, attr_name, attr_value, value_len, flags);
+	error = attr_set(path, attr_name, attr_value, (int)value_len, (int)flags);
 	if (error == -1) {
 		switch (errno) {
 			case E2BIG:
@@ -164,8 +188,10 @@
 	char *attr_name = NULL;
 	char *attr_value = NULL;
 	char *path = NULL;
-	int error, tmp, flags = 0;
-	size_t buffer_size = XATTR_BUFFER_SIZE;
+	int error;
+	strsize_t tmp;
+	zend_long flags = 0;
+	int buffer_size = XATTR_BUFFER_SIZE;
 
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &path, &tmp, &attr_name, &tmp, &flags) == FAILURE) {
 		return;
@@ -192,7 +218,7 @@
 	 * If buffer is too small then attr_get sets errno to E2BIG and tells us
 	 * how many bytes are required by setting buffer_size variable.
 	 */
-	error = attr_get(path, attr_name, attr_value, &buffer_size, flags);
+	error = attr_get(path, attr_name, attr_value, &buffer_size, (int)flags);
 
 	/* 
 	 * Loop is necessary in case that someone edited extended attributes
@@ -203,13 +229,14 @@
 		if (!attr_value)
 			RETURN_FALSE;
 		
-		error = attr_get(path, attr_name, attr_value, &buffer_size, flags);		
+		error = attr_get(path, attr_name, attr_value, &buffer_size, (int)flags);
 	}
 
 	/* Return a string if everything is ok */
 	if (!error) {
-		attr_value = erealloc(attr_value, buffer_size);
-		RETURN_STRINGL(attr_value, buffer_size, 0);
+		_RETVAL_STRINGL(attr_value, buffer_size, 1); /* copy + free instead of realloc */
+		efree(attr_value);
+		return;
 	}
 	
 	/* Error handling part */
@@ -240,8 +267,10 @@
    Checks if filesystem supports extended attributes */
 PHP_FUNCTION(xattr_supported)
 {
-	char *buffer, *path = NULL;
-	int error, tmp, flags = 0;
+	char *buffer="", *path = NULL;
+	int error;
+	strsize_t tmp;
+	zend_long flags = 0;
 
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &path, &tmp, &flags) == FAILURE) {
 		return;
@@ -290,7 +319,9 @@
 {
 	char *attr_name = NULL;
 	char *path = NULL;
-	int error, tmp, flags = 0;
+	int error;
+	strsize_t tmp;
+	zend_long flags = 0;
 	
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &path, &tmp, &attr_name, &tmp, &flags) == FAILURE) {
 		return;
@@ -309,7 +340,7 @@
 	flags &= ATTR_ROOT | ATTR_DONTFOLLOW; 
 	
 	/* Attempt to remove an attribute, warn if failed. */ 
-	error = attr_remove(path, attr_name, flags);
+	error = attr_remove(path, attr_name, (int)flags);
 	if (error == -1) {
 		switch (errno) {
 			case E2BIG:
@@ -341,8 +372,10 @@
 {
 	char *buffer, *path = NULL;
 	char *p, *prefix;
-	int error, tmp, flags = 0;
-	ssize_t i = 0, buffer_size = XATTR_BUFFER_SIZE;
+	int error;
+	strsize_t tmp;
+	zend_long flags = 0;
+	size_t i = 0, buffer_size = XATTR_BUFFER_SIZE;
 	size_t len, prefix_len;
 	
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &path, &tmp, &flags) == FAILURE) {
@@ -442,7 +475,11 @@
 	while (i != buffer_size) {
 		len = strlen(p) + 1;	/* +1 for NULL */
 		if (strstr(p, prefix) == p) {
+#if PHP_MAJOR_VERSION < 7
 			add_next_index_stringl(return_value, p + prefix_len, len - 1 - prefix_len, 1);
+#else
+			add_next_index_stringl(return_value, p + prefix_len, len - 1 - prefix_len);
+#endif
 		}
 		
 		p += len;