Annotation of embedaddon/php/ext/spl/spl_directory.c, revision 1.1.1.3
1.1 misho 1: /*
2: +----------------------------------------------------------------------+
3: | PHP Version 5 |
4: +----------------------------------------------------------------------+
1.1.1.3 ! misho 5: | Copyright (c) 1997-2013 The PHP Group |
1.1 misho 6: +----------------------------------------------------------------------+
7: | This source file is subject to version 3.01 of the PHP license, |
8: | that is bundled with this package in the file LICENSE, and is |
9: | available through the world-wide-web at the following url: |
10: | http://www.php.net/license/3_01.txt |
11: | If you did not receive a copy of the PHP license and are unable to |
12: | obtain it through the world-wide-web, please send a note to |
13: | license@php.net so we can mail you a copy immediately. |
14: +----------------------------------------------------------------------+
15: | Author: Marcus Boerger <helly@php.net> |
16: +----------------------------------------------------------------------+
17: */
18:
1.1.1.2 misho 19: /* $Id$ */
1.1 misho 20:
21: #ifdef HAVE_CONFIG_H
22: # include "config.h"
23: #endif
24:
25: #include "php.h"
26: #include "php_ini.h"
27: #include "ext/standard/info.h"
28: #include "ext/standard/file.h"
29: #include "ext/standard/php_string.h"
30: #include "zend_compile.h"
31: #include "zend_exceptions.h"
32: #include "zend_interfaces.h"
33:
34: #include "php_spl.h"
35: #include "spl_functions.h"
36: #include "spl_engine.h"
37: #include "spl_iterators.h"
38: #include "spl_directory.h"
39: #include "spl_exceptions.h"
40:
41: #include "php.h"
42: #include "fopen_wrappers.h"
43:
44: #include "ext/standard/basic_functions.h"
45: #include "ext/standard/php_filestat.h"
46:
47: #define SPL_HAS_FLAG(flags, test_flag) ((flags & test_flag) ? 1 : 0)
48:
49: /* declare the class handlers */
50: static zend_object_handlers spl_filesystem_object_handlers;
51: /* includes handler to validate object state when retrieving methods */
52: static zend_object_handlers spl_filesystem_object_check_handlers;
53:
54: /* decalre the class entry */
55: PHPAPI zend_class_entry *spl_ce_SplFileInfo;
56: PHPAPI zend_class_entry *spl_ce_DirectoryIterator;
57: PHPAPI zend_class_entry *spl_ce_FilesystemIterator;
58: PHPAPI zend_class_entry *spl_ce_RecursiveDirectoryIterator;
59: PHPAPI zend_class_entry *spl_ce_GlobIterator;
60: PHPAPI zend_class_entry *spl_ce_SplFileObject;
61: PHPAPI zend_class_entry *spl_ce_SplTempFileObject;
62:
63: static void spl_filesystem_file_free_line(spl_filesystem_object *intern TSRMLS_DC) /* {{{ */
64: {
65: if (intern->u.file.current_line) {
66: efree(intern->u.file.current_line);
67: intern->u.file.current_line = NULL;
68: }
69: if (intern->u.file.current_zval) {
70: zval_ptr_dtor(&intern->u.file.current_zval);
71: intern->u.file.current_zval = NULL;
72: }
73: } /* }}} */
74:
75: static void spl_filesystem_object_free_storage(void *object TSRMLS_DC) /* {{{ */
76: {
77: spl_filesystem_object *intern = (spl_filesystem_object*)object;
78:
79: if (intern->oth_handler && intern->oth_handler->dtor) {
80: intern->oth_handler->dtor(intern TSRMLS_CC);
81: }
82:
83: zend_object_std_dtor(&intern->std TSRMLS_CC);
84:
85: if (intern->_path) {
86: efree(intern->_path);
87: }
88: if (intern->file_name) {
89: efree(intern->file_name);
90: }
91: switch(intern->type) {
92: case SPL_FS_INFO:
93: break;
94: case SPL_FS_DIR:
95: if (intern->u.dir.dirp) {
96: php_stream_close(intern->u.dir.dirp);
97: intern->u.dir.dirp = NULL;
98: }
99: if (intern->u.dir.sub_path) {
100: efree(intern->u.dir.sub_path);
101: }
102: break;
103: case SPL_FS_FILE:
104: if (intern->u.file.stream) {
105: if (intern->u.file.zcontext) {
106: /* zend_list_delref(Z_RESVAL_P(intern->zcontext));*/
107: }
108: if (!intern->u.file.stream->is_persistent) {
109: php_stream_free(intern->u.file.stream, PHP_STREAM_FREE_CLOSE);
110: } else {
111: php_stream_free(intern->u.file.stream, PHP_STREAM_FREE_CLOSE_PERSISTENT);
112: }
113: if (intern->u.file.open_mode) {
114: efree(intern->u.file.open_mode);
115: }
116: if (intern->orig_path) {
117: efree(intern->orig_path);
118: }
119: }
120: spl_filesystem_file_free_line(intern TSRMLS_CC);
121: break;
122: }
1.1.1.2 misho 123:
124: {
125: zend_object_iterator *iterator;
126: iterator = (zend_object_iterator*)
127: spl_filesystem_object_to_iterator(intern);
128: if (iterator->data != NULL) {
129: iterator->data = NULL;
130: iterator->funcs->dtor(iterator TSRMLS_CC);
131: }
132: }
1.1 misho 133: efree(object);
134: } /* }}} */
135:
136: /* {{{ spl_ce_dir_object_new */
137: /* creates the object by
138: - allocating memory
139: - initializing the object members
140: - storing the object
141: - setting it's handlers
142:
143: called from
144: - clone
145: - new
146: */
147: static zend_object_value spl_filesystem_object_new_ex(zend_class_entry *class_type, spl_filesystem_object **obj TSRMLS_DC)
148: {
149: zend_object_value retval;
150: spl_filesystem_object *intern;
151:
152: intern = emalloc(sizeof(spl_filesystem_object));
153: memset(intern, 0, sizeof(spl_filesystem_object));
154: /* intern->type = SPL_FS_INFO; done by set 0 */
155: intern->file_class = spl_ce_SplFileObject;
156: intern->info_class = spl_ce_SplFileInfo;
157: if (obj) *obj = intern;
158:
159: zend_object_std_init(&intern->std, class_type TSRMLS_CC);
1.1.1.2 misho 160: object_properties_init(&intern->std, class_type);
1.1 misho 161:
162: retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, (zend_objects_free_object_storage_t) spl_filesystem_object_free_storage, NULL TSRMLS_CC);
163: retval.handlers = &spl_filesystem_object_handlers;
164: return retval;
165: }
166: /* }}} */
167:
168: /* {{{ spl_filesystem_object_new */
169: /* See spl_filesystem_object_new_ex */
170: static zend_object_value spl_filesystem_object_new(zend_class_entry *class_type TSRMLS_DC)
171: {
172: return spl_filesystem_object_new_ex(class_type, NULL TSRMLS_CC);
173: }
174: /* }}} */
175:
176: /* {{{ spl_filesystem_object_new_ex */
177: static zend_object_value spl_filesystem_object_new_check(zend_class_entry *class_type TSRMLS_DC)
178: {
179: zend_object_value ret = spl_filesystem_object_new_ex(class_type, NULL TSRMLS_CC);
180: ret.handlers = &spl_filesystem_object_check_handlers;
181: return ret;
182: }
183: /* }}} */
184:
185:
186: PHPAPI char* spl_filesystem_object_get_path(spl_filesystem_object *intern, int *len TSRMLS_DC) /* {{{ */
187: {
188: #ifdef HAVE_GLOB
189: if (intern->type == SPL_FS_DIR) {
190: if (php_stream_is(intern->u.dir.dirp ,&php_glob_stream_ops)) {
191: return php_glob_stream_get_path(intern->u.dir.dirp, 0, len);
192: }
193: }
194: #endif
195: if (len) {
196: *len = intern->_path_len;
197: }
198: return intern->_path;
199: } /* }}} */
200:
201: static inline void spl_filesystem_object_get_file_name(spl_filesystem_object *intern TSRMLS_DC) /* {{{ */
202: {
203: char slash = SPL_HAS_FLAG(intern->flags, SPL_FILE_DIR_UNIXPATHS) ? '/' : DEFAULT_SLASH;
204:
205: if (!intern->file_name) {
206: switch (intern->type) {
207: case SPL_FS_INFO:
208: case SPL_FS_FILE:
209: php_error_docref(NULL TSRMLS_CC, E_ERROR, "Object not initialized");
210: break;
211: case SPL_FS_DIR:
212: intern->file_name_len = spprintf(&intern->file_name, 0, "%s%c%s",
213: spl_filesystem_object_get_path(intern, NULL TSRMLS_CC),
214: slash, intern->u.dir.entry.d_name);
215: break;
216: }
217: }
218: } /* }}} */
219:
220: static int spl_filesystem_dir_read(spl_filesystem_object *intern TSRMLS_DC) /* {{{ */
221: {
222: if (!intern->u.dir.dirp || !php_stream_readdir(intern->u.dir.dirp, &intern->u.dir.entry)) {
223: intern->u.dir.entry.d_name[0] = '\0';
224: return 0;
225: } else {
226: return 1;
227: }
228: }
229: /* }}} */
230:
231: #define IS_SLASH_AT(zs, pos) (IS_SLASH(zs[pos]))
232:
233: static inline int spl_filesystem_is_dot(const char * d_name) /* {{{ */
234: {
235: return !strcmp(d_name, ".") || !strcmp(d_name, "..");
236: }
237: /* }}} */
238:
239: /* {{{ spl_filesystem_dir_open */
240: /* open a directory resource */
241: static void spl_filesystem_dir_open(spl_filesystem_object* intern, char *path TSRMLS_DC)
242: {
243: int skip_dots = SPL_HAS_FLAG(intern->flags, SPL_FILE_DIR_SKIPDOTS);
244:
245: intern->type = SPL_FS_DIR;
246: intern->_path_len = strlen(path);
1.1.1.2 misho 247: intern->u.dir.dirp = php_stream_opendir(path, REPORT_ERRORS, FG(default_context));
1.1 misho 248:
249: if (intern->_path_len > 1 && IS_SLASH_AT(path, intern->_path_len-1)) {
250: intern->_path = estrndup(path, --intern->_path_len);
251: } else {
252: intern->_path = estrndup(path, intern->_path_len);
253: }
254: intern->u.dir.index = 0;
255:
256: if (EG(exception) || intern->u.dir.dirp == NULL) {
257: intern->u.dir.entry.d_name[0] = '\0';
258: if (!EG(exception)) {
259: /* open failed w/out notice (turned to exception due to EH_THROW) */
260: zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0
261: TSRMLS_CC, "Failed to open directory \"%s\"", path);
262: }
263: } else {
264: do {
265: spl_filesystem_dir_read(intern TSRMLS_CC);
266: } while (skip_dots && spl_filesystem_is_dot(intern->u.dir.entry.d_name));
267: }
268: }
269: /* }}} */
270:
271: static int spl_filesystem_file_open(spl_filesystem_object *intern, int use_include_path, int silent TSRMLS_DC) /* {{{ */
272: {
1.1.1.2 misho 273: zval tmp;
274:
1.1 misho 275: intern->type = SPL_FS_FILE;
1.1.1.2 misho 276:
277: php_stat(intern->file_name, intern->file_name_len, FS_IS_DIR, &tmp TSRMLS_CC);
278: if (Z_LVAL(tmp)) {
279: intern->u.file.open_mode = NULL;
280: intern->file_name = NULL;
281: zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Cannot use SplFileObject with directories");
282: return FAILURE;
283: }
284:
1.1 misho 285: intern->u.file.context = php_stream_context_from_zval(intern->u.file.zcontext, 0);
1.1.1.2 misho 286: intern->u.file.stream = php_stream_open_wrapper_ex(intern->file_name, intern->u.file.open_mode, (use_include_path ? USE_PATH : 0) | REPORT_ERRORS, NULL, intern->u.file.context);
1.1 misho 287:
288: if (!intern->file_name_len || !intern->u.file.stream) {
289: if (!EG(exception)) {
290: zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Cannot open file '%s'", intern->file_name_len ? intern->file_name : "");
291: }
292: intern->file_name = NULL; /* until here it is not a copy */
293: intern->u.file.open_mode = NULL;
294: return FAILURE;
295: }
296:
297: if (intern->u.file.zcontext) {
298: zend_list_addref(Z_RESVAL_P(intern->u.file.zcontext));
299: }
300:
301: if (intern->file_name_len > 1 && IS_SLASH_AT(intern->file_name, intern->file_name_len-1)) {
302: intern->file_name_len--;
303: }
304:
305: intern->orig_path = estrndup(intern->u.file.stream->orig_path, strlen(intern->u.file.stream->orig_path));
306:
307: intern->file_name = estrndup(intern->file_name, intern->file_name_len);
308: intern->u.file.open_mode = estrndup(intern->u.file.open_mode, intern->u.file.open_mode_len);
309:
310: /* avoid reference counting in debug mode, thus do it manually */
311: ZVAL_RESOURCE(&intern->u.file.zresource, php_stream_get_resource_id(intern->u.file.stream));
312: Z_SET_REFCOUNT(intern->u.file.zresource, 1);
313:
314: intern->u.file.delimiter = ',';
315: intern->u.file.enclosure = '"';
316: intern->u.file.escape = '\\';
317:
318: zend_hash_find(&intern->std.ce->function_table, "getcurrentline", sizeof("getcurrentline"), (void **) &intern->u.file.func_getCurr);
319:
320: return SUCCESS;
321: } /* }}} */
322:
323: /* {{{ spl_filesystem_object_clone */
324: /* Local zend_object_value creation (on stack)
325: Load the 'other' object
326: Create a new empty object (See spl_filesystem_object_new_ex)
327: Open the directory
328: Clone other members (properties)
329: */
330: static zend_object_value spl_filesystem_object_clone(zval *zobject TSRMLS_DC)
331: {
332: zend_object_value new_obj_val;
333: zend_object *old_object;
334: zend_object *new_object;
335: zend_object_handle handle = Z_OBJ_HANDLE_P(zobject);
336: spl_filesystem_object *intern;
337: spl_filesystem_object *source;
338: int index, skip_dots;
339:
340: old_object = zend_objects_get_address(zobject TSRMLS_CC);
341: source = (spl_filesystem_object*)old_object;
342:
343: new_obj_val = spl_filesystem_object_new_ex(old_object->ce, &intern TSRMLS_CC);
344: new_object = &intern->std;
345:
346: intern->flags = source->flags;
347:
348: switch (source->type) {
349: case SPL_FS_INFO:
350: intern->_path_len = source->_path_len;
351: intern->_path = estrndup(source->_path, source->_path_len);
352: intern->file_name_len = source->file_name_len;
353: intern->file_name = estrndup(source->file_name, intern->file_name_len);
354: break;
355: case SPL_FS_DIR:
356: spl_filesystem_dir_open(intern, source->_path TSRMLS_CC);
357: /* read until we hit the position in which we were before */
358: skip_dots = SPL_HAS_FLAG(source->flags, SPL_FILE_DIR_SKIPDOTS);
359: for(index = 0; index < source->u.dir.index; ++index) {
360: do {
361: spl_filesystem_dir_read(intern TSRMLS_CC);
362: } while (skip_dots && spl_filesystem_is_dot(intern->u.dir.entry.d_name));
363: }
364: intern->u.dir.index = index;
365: break;
366: case SPL_FS_FILE:
367: php_error_docref(NULL TSRMLS_CC, E_ERROR, "An object of class %s cannot be cloned", old_object->ce->name);
368: break;
369: }
370:
371: intern->file_class = source->file_class;
372: intern->info_class = source->info_class;
373: intern->oth = source->oth;
374: intern->oth_handler = source->oth_handler;
375:
376: zend_objects_clone_members(new_object, new_obj_val, old_object, handle TSRMLS_CC);
377:
378: if (intern->oth_handler && intern->oth_handler->clone) {
379: intern->oth_handler->clone(source, intern TSRMLS_CC);
380: }
381:
382: return new_obj_val;
383: }
384: /* }}} */
385:
386: void spl_filesystem_info_set_filename(spl_filesystem_object *intern, char *path, int len, int use_copy TSRMLS_DC) /* {{{ */
387: {
388: char *p1, *p2;
1.1.1.2 misho 389:
390: if (intern->file_name) {
391: efree(intern->file_name);
392: }
1.1 misho 393:
394: intern->file_name = use_copy ? estrndup(path, len) : path;
395: intern->file_name_len = len;
396:
397: while(IS_SLASH_AT(intern->file_name, intern->file_name_len-1) && intern->file_name_len > 1) {
398: intern->file_name[intern->file_name_len-1] = 0;
399: intern->file_name_len--;
400: }
401:
402: p1 = strrchr(intern->file_name, '/');
403: #if defined(PHP_WIN32) || defined(NETWARE)
404: p2 = strrchr(intern->file_name, '\\');
405: #else
406: p2 = 0;
407: #endif
408: if (p1 || p2) {
409: intern->_path_len = (p1 > p2 ? p1 : p2) - intern->file_name;
410: } else {
411: intern->_path_len = 0;
412: }
1.1.1.2 misho 413:
414: if (intern->_path) {
415: efree(intern->_path);
416: }
1.1 misho 417: intern->_path = estrndup(path, intern->_path_len);
418: } /* }}} */
419:
420: static spl_filesystem_object * spl_filesystem_object_create_info(spl_filesystem_object *source, char *file_path, int file_path_len, int use_copy, zend_class_entry *ce, zval *return_value TSRMLS_DC) /* {{{ */
421: {
422: spl_filesystem_object *intern;
423: zval *arg1;
424: zend_error_handling error_handling;
425:
426: if (!file_path || !file_path_len) {
427: #if defined(PHP_WIN32)
428: zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Cannot create SplFileInfo for empty path");
429: if (file_path && !use_copy) {
430: efree(file_path);
431: }
432: #else
433: if (file_path && !use_copy) {
434: efree(file_path);
435: }
436: file_path_len = 1;
437: file_path = "/";
438: #endif
439: return NULL;
440: }
441:
442: zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling TSRMLS_CC);
443:
444: ce = ce ? ce : source->info_class;
445:
446: zend_update_class_constants(ce TSRMLS_CC);
447:
448: return_value->value.obj = spl_filesystem_object_new_ex(ce, &intern TSRMLS_CC);
449: Z_TYPE_P(return_value) = IS_OBJECT;
450:
451: if (ce->constructor->common.scope != spl_ce_SplFileInfo) {
452: MAKE_STD_ZVAL(arg1);
453: ZVAL_STRINGL(arg1, file_path, file_path_len, use_copy);
454: zend_call_method_with_1_params(&return_value, ce, &ce->constructor, "__construct", NULL, arg1);
455: zval_ptr_dtor(&arg1);
456: } else {
457: spl_filesystem_info_set_filename(intern, file_path, file_path_len, use_copy TSRMLS_CC);
458: }
459:
460: zend_restore_error_handling(&error_handling TSRMLS_CC);
461: return intern;
462: } /* }}} */
463:
464: static spl_filesystem_object * spl_filesystem_object_create_type(int ht, spl_filesystem_object *source, int type, zend_class_entry *ce, zval *return_value TSRMLS_DC) /* {{{ */
465: {
466: spl_filesystem_object *intern;
467: zend_bool use_include_path = 0;
468: zval *arg1, *arg2;
469: zend_error_handling error_handling;
470:
471: zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling TSRMLS_CC);
472:
473: switch (source->type) {
474: case SPL_FS_INFO:
475: case SPL_FS_FILE:
476: break;
477: case SPL_FS_DIR:
478: if (!source->u.dir.entry.d_name[0]) {
479: zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Could not open file");
480: zend_restore_error_handling(&error_handling TSRMLS_CC);
481: return NULL;
482: }
483: }
484:
485: switch (type) {
486: case SPL_FS_INFO:
487: ce = ce ? ce : source->info_class;
488:
489: zend_update_class_constants(ce TSRMLS_CC);
490:
491: return_value->value.obj = spl_filesystem_object_new_ex(ce, &intern TSRMLS_CC);
492: Z_TYPE_P(return_value) = IS_OBJECT;
493:
494: spl_filesystem_object_get_file_name(source TSRMLS_CC);
495: if (ce->constructor->common.scope != spl_ce_SplFileInfo) {
496: MAKE_STD_ZVAL(arg1);
497: ZVAL_STRINGL(arg1, source->file_name, source->file_name_len, 1);
498: zend_call_method_with_1_params(&return_value, ce, &ce->constructor, "__construct", NULL, arg1);
499: zval_ptr_dtor(&arg1);
500: } else {
501: intern->file_name = estrndup(source->file_name, source->file_name_len);
502: intern->file_name_len = source->file_name_len;
503: intern->_path = spl_filesystem_object_get_path(source, &intern->_path_len TSRMLS_CC);
504: intern->_path = estrndup(intern->_path, intern->_path_len);
505: }
506: break;
507: case SPL_FS_FILE:
508: ce = ce ? ce : source->file_class;
509:
510: zend_update_class_constants(ce TSRMLS_CC);
511:
512: return_value->value.obj = spl_filesystem_object_new_ex(ce, &intern TSRMLS_CC);
513: Z_TYPE_P(return_value) = IS_OBJECT;
514:
515: spl_filesystem_object_get_file_name(source TSRMLS_CC);
516:
517: if (ce->constructor->common.scope != spl_ce_SplFileObject) {
518: MAKE_STD_ZVAL(arg1);
519: MAKE_STD_ZVAL(arg2);
520: ZVAL_STRINGL(arg1, source->file_name, source->file_name_len, 1);
521: ZVAL_STRINGL(arg2, "r", 1, 1);
522: zend_call_method_with_2_params(&return_value, ce, &ce->constructor, "__construct", NULL, arg1, arg2);
523: zval_ptr_dtor(&arg1);
524: zval_ptr_dtor(&arg2);
525: } else {
526: intern->file_name = source->file_name;
527: intern->file_name_len = source->file_name_len;
528: intern->_path = spl_filesystem_object_get_path(source, &intern->_path_len TSRMLS_CC);
529: intern->_path = estrndup(intern->_path, intern->_path_len);
530:
531: intern->u.file.open_mode = "r";
532: intern->u.file.open_mode_len = 1;
533:
534: if (ht && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sbr",
535: &intern->u.file.open_mode, &intern->u.file.open_mode_len,
536: &use_include_path, &intern->u.file.zcontext) == FAILURE) {
537: zend_restore_error_handling(&error_handling TSRMLS_CC);
538: intern->u.file.open_mode = NULL;
539: intern->file_name = NULL;
540: zval_dtor(return_value);
541: Z_TYPE_P(return_value) = IS_NULL;
542: return NULL;
543: }
544:
545: if (spl_filesystem_file_open(intern, use_include_path, 0 TSRMLS_CC) == FAILURE) {
546: zend_restore_error_handling(&error_handling TSRMLS_CC);
547: zval_dtor(return_value);
548: Z_TYPE_P(return_value) = IS_NULL;
549: return NULL;
550: }
551: }
552: break;
553: case SPL_FS_DIR:
554: zend_restore_error_handling(&error_handling TSRMLS_CC);
555: zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Operation not supported");
556: return NULL;
557: }
558: zend_restore_error_handling(&error_handling TSRMLS_CC);
559: return NULL;
560: } /* }}} */
561:
562: static int spl_filesystem_is_invalid_or_dot(const char * d_name) /* {{{ */
563: {
564: return d_name[0] == '\0' || spl_filesystem_is_dot(d_name);
565: }
566: /* }}} */
567:
568: static char *spl_filesystem_object_get_pathname(spl_filesystem_object *intern, int *len TSRMLS_DC) { /* {{{ */
569: switch (intern->type) {
570: case SPL_FS_INFO:
571: case SPL_FS_FILE:
572: *len = intern->file_name_len;
573: return intern->file_name;
574: case SPL_FS_DIR:
575: if (intern->u.dir.entry.d_name[0]) {
576: spl_filesystem_object_get_file_name(intern TSRMLS_CC);
577: *len = intern->file_name_len;
578: return intern->file_name;
579: }
580: }
581: *len = 0;
582: return NULL;
583: }
584: /* }}} */
585:
586: static HashTable* spl_filesystem_object_get_debug_info(zval *obj, int *is_temp TSRMLS_DC) /* {{{ */
587: {
588: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(obj TSRMLS_CC);
589: HashTable *rv;
590: zval *tmp, zrv;
591: char *pnstr, *path;
592: int pnlen, path_len;
593: char stmp[2];
594:
595: *is_temp = 1;
596:
1.1.1.2 misho 597: if (!intern->std.properties) {
598: rebuild_object_properties(&intern->std);
599: }
600:
1.1 misho 601: ALLOC_HASHTABLE(rv);
602: ZEND_INIT_SYMTABLE_EX(rv, zend_hash_num_elements(intern->std.properties) + 3, 0);
603:
604: INIT_PZVAL(&zrv);
605: Z_ARRVAL(zrv) = rv;
606:
607: zend_hash_copy(rv, intern->std.properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
608:
609: pnstr = spl_gen_private_prop_name(spl_ce_SplFileInfo, "pathName", sizeof("pathName")-1, &pnlen TSRMLS_CC);
610: path = spl_filesystem_object_get_pathname(intern, &path_len TSRMLS_CC);
611: add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, path, path_len, 1);
612: efree(pnstr);
613:
614: if (intern->file_name) {
615: pnstr = spl_gen_private_prop_name(spl_ce_SplFileInfo, "fileName", sizeof("fileName")-1, &pnlen TSRMLS_CC);
616: spl_filesystem_object_get_path(intern, &path_len TSRMLS_CC);
617:
618: if (path_len && path_len < intern->file_name_len) {
619: add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, intern->file_name + path_len + 1, intern->file_name_len - (path_len + 1), 1);
620: } else {
621: add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, intern->file_name, intern->file_name_len, 1);
622: }
623: efree(pnstr);
624: }
625: if (intern->type == SPL_FS_DIR) {
626: #ifdef HAVE_GLOB
627: pnstr = spl_gen_private_prop_name(spl_ce_DirectoryIterator, "glob", sizeof("glob")-1, &pnlen TSRMLS_CC);
628: if (php_stream_is(intern->u.dir.dirp ,&php_glob_stream_ops)) {
629: add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, intern->_path, intern->_path_len, 1);
630: } else {
631: add_assoc_bool_ex(&zrv, pnstr, pnlen+1, 0);
632: }
633: efree(pnstr);
634: #endif
635: pnstr = spl_gen_private_prop_name(spl_ce_RecursiveDirectoryIterator, "subPathName", sizeof("subPathName")-1, &pnlen TSRMLS_CC);
636: if (intern->u.dir.sub_path) {
637: add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, intern->u.dir.sub_path, intern->u.dir.sub_path_len, 1);
638: } else {
639: add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, "", 0, 1);
640: }
641: efree(pnstr);
642: }
643: if (intern->type == SPL_FS_FILE) {
644: pnstr = spl_gen_private_prop_name(spl_ce_SplFileObject, "openMode", sizeof("openMode")-1, &pnlen TSRMLS_CC);
645: add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, intern->u.file.open_mode, intern->u.file.open_mode_len, 1);
646: efree(pnstr);
647: stmp[1] = '\0';
648: stmp[0] = intern->u.file.delimiter;
649: pnstr = spl_gen_private_prop_name(spl_ce_SplFileObject, "delimiter", sizeof("delimiter")-1, &pnlen TSRMLS_CC);
650: add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, stmp, 1, 1);
651: efree(pnstr);
652: stmp[0] = intern->u.file.enclosure;
653: pnstr = spl_gen_private_prop_name(spl_ce_SplFileObject, "enclosure", sizeof("enclosure")-1, &pnlen TSRMLS_CC);
654: add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, stmp, 1, 1);
655: efree(pnstr);
656: }
657:
658: return rv;
659: }
660: /* }}} */
661:
1.1.1.2 misho 662: zend_function *spl_filesystem_object_get_method_check(zval **object_ptr, char *method, int method_len, const struct _zend_literal *key TSRMLS_DC) /* {{{ */
1.1 misho 663: {
664: spl_filesystem_object *fsobj = zend_object_store_get_object(*object_ptr TSRMLS_CC);
665:
666: if (fsobj->u.dir.entry.d_name[0] == '\0' && fsobj->orig_path == NULL) {
667: method = "_bad_state_ex";
668: method_len = sizeof("_bad_state_ex") - 1;
1.1.1.2 misho 669: key = NULL;
1.1 misho 670: }
671:
1.1.1.2 misho 672: return zend_get_std_object_handlers()->get_method(object_ptr, method, method_len, key TSRMLS_CC);
1.1 misho 673: }
674: /* }}} */
675:
676: #define DIT_CTOR_FLAGS 0x00000001
677: #define DIT_CTOR_GLOB 0x00000002
678:
679: void spl_filesystem_object_construct(INTERNAL_FUNCTION_PARAMETERS, long ctor_flags) /* {{{ */
680: {
681: spl_filesystem_object *intern;
682: char *path;
683: int parsed, len;
684: long flags;
685: zend_error_handling error_handling;
686:
687: zend_replace_error_handling(EH_THROW, spl_ce_UnexpectedValueException, &error_handling TSRMLS_CC);
688:
689: if (SPL_HAS_FLAG(ctor_flags, DIT_CTOR_FLAGS)) {
690: flags = SPL_FILE_DIR_KEY_AS_PATHNAME|SPL_FILE_DIR_CURRENT_AS_FILEINFO;
691: parsed = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &path, &len, &flags);
692: } else {
693: flags = SPL_FILE_DIR_KEY_AS_PATHNAME|SPL_FILE_DIR_CURRENT_AS_SELF;
694: parsed = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &path, &len);
695: }
696: if (SPL_HAS_FLAG(ctor_flags, SPL_FILE_DIR_SKIPDOTS)) {
697: flags |= SPL_FILE_DIR_SKIPDOTS;
698: }
699: if (SPL_HAS_FLAG(ctor_flags, SPL_FILE_DIR_UNIXPATHS)) {
700: flags |= SPL_FILE_DIR_UNIXPATHS;
701: }
702: if (parsed == FAILURE) {
703: zend_restore_error_handling(&error_handling TSRMLS_CC);
704: return;
705: }
706: if (!len) {
707: zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Directory name must not be empty.");
708: zend_restore_error_handling(&error_handling TSRMLS_CC);
709: return;
710: }
711:
712: intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
713: intern->flags = flags;
714: #ifdef HAVE_GLOB
715: if (SPL_HAS_FLAG(ctor_flags, DIT_CTOR_GLOB) && strstr(path, "glob://") != path) {
716: spprintf(&path, 0, "glob://%s", path);
717: spl_filesystem_dir_open(intern, path TSRMLS_CC);
718: efree(path);
719: } else
720: #endif
721: {
722: spl_filesystem_dir_open(intern, path TSRMLS_CC);
723:
724: }
725:
726: intern->u.dir.is_recursive = instanceof_function(intern->std.ce, spl_ce_RecursiveDirectoryIterator TSRMLS_CC) ? 1 : 0;
727:
728: zend_restore_error_handling(&error_handling TSRMLS_CC);
729: }
730: /* }}} */
731:
732: /* {{{ proto void DirectoryIterator::__construct(string path)
733: Cronstructs a new dir iterator from a path. */
734: SPL_METHOD(DirectoryIterator, __construct)
735: {
736: spl_filesystem_object_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
737: }
738: /* }}} */
739:
740: /* {{{ proto void DirectoryIterator::rewind()
741: Rewind dir back to the start */
742: SPL_METHOD(DirectoryIterator, rewind)
743: {
744: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
745:
746: if (zend_parse_parameters_none() == FAILURE) {
747: return;
748: }
749:
750: intern->u.dir.index = 0;
751: if (intern->u.dir.dirp) {
752: php_stream_rewinddir(intern->u.dir.dirp);
753: }
754: spl_filesystem_dir_read(intern TSRMLS_CC);
755: }
756: /* }}} */
757:
758: /* {{{ proto string DirectoryIterator::key()
759: Return current dir entry */
760: SPL_METHOD(DirectoryIterator, key)
761: {
762: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
763:
764: if (zend_parse_parameters_none() == FAILURE) {
765: return;
766: }
767:
768: if (intern->u.dir.dirp) {
769: RETURN_LONG(intern->u.dir.index);
770: } else {
771: RETURN_FALSE;
772: }
773: }
774: /* }}} */
775:
776: /* {{{ proto DirectoryIterator DirectoryIterator::current()
777: Return this (needed for Iterator interface) */
778: SPL_METHOD(DirectoryIterator, current)
779: {
780: if (zend_parse_parameters_none() == FAILURE) {
781: return;
782: }
783: RETURN_ZVAL(getThis(), 1, 0);
784: }
785: /* }}} */
786:
787: /* {{{ proto void DirectoryIterator::next()
788: Move to next entry */
789: SPL_METHOD(DirectoryIterator, next)
790: {
791: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
792: int skip_dots = SPL_HAS_FLAG(intern->flags, SPL_FILE_DIR_SKIPDOTS);
793:
794: if (zend_parse_parameters_none() == FAILURE) {
795: return;
796: }
797:
798: intern->u.dir.index++;
799: do {
800: spl_filesystem_dir_read(intern TSRMLS_CC);
801: } while (skip_dots && spl_filesystem_is_dot(intern->u.dir.entry.d_name));
802: if (intern->file_name) {
803: efree(intern->file_name);
804: intern->file_name = NULL;
805: }
806: }
807: /* }}} */
808:
809: /* {{{ proto void DirectoryIterator::seek(int position)
810: Seek to the given position */
811: SPL_METHOD(DirectoryIterator, seek)
812: {
813: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
814: zval *retval = NULL;
815: long pos;
816:
817: if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &pos) == FAILURE) {
818: return;
819: }
820:
821: if (intern->u.dir.index > pos) {
822: /* we first rewind */
823: zend_call_method_with_0_params(&this_ptr, Z_OBJCE_P(getThis()), &intern->u.dir.func_rewind, "rewind", &retval);
824: if (retval) {
825: zval_ptr_dtor(&retval);
826: }
827: }
828:
829: while (intern->u.dir.index < pos) {
830: int valid = 0;
831: zend_call_method_with_0_params(&this_ptr, Z_OBJCE_P(getThis()), &intern->u.dir.func_valid, "valid", &retval);
832: if (retval) {
833: valid = zend_is_true(retval);
834: zval_ptr_dtor(&retval);
835: }
836: if (!valid) {
837: break;
838: }
839: zend_call_method_with_0_params(&this_ptr, Z_OBJCE_P(getThis()), &intern->u.dir.func_next, "next", &retval);
840: if (retval) {
841: zval_ptr_dtor(&retval);
842: }
843: }
844: } /* }}} */
845:
846: /* {{{ proto string DirectoryIterator::valid()
847: Check whether dir contains more entries */
848: SPL_METHOD(DirectoryIterator, valid)
849: {
850: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
851:
852: if (zend_parse_parameters_none() == FAILURE) {
853: return;
854: }
855:
856: RETURN_BOOL(intern->u.dir.entry.d_name[0] != '\0');
857: }
858: /* }}} */
859:
860: /* {{{ proto string SplFileInfo::getPath()
861: Return the path */
862: SPL_METHOD(SplFileInfo, getPath)
863: {
864: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
865: char *path;
866: int path_len;
867:
868: if (zend_parse_parameters_none() == FAILURE) {
869: return;
870: }
871:
872: path = spl_filesystem_object_get_path(intern, &path_len TSRMLS_CC);
873: RETURN_STRINGL(path, path_len, 1);
874: }
875: /* }}} */
876:
877: /* {{{ proto string SplFileInfo::getFilename()
878: Return filename only */
879: SPL_METHOD(SplFileInfo, getFilename)
880: {
881: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
882: int path_len;
883:
884: if (zend_parse_parameters_none() == FAILURE) {
885: return;
886: }
887:
888: spl_filesystem_object_get_path(intern, &path_len TSRMLS_CC);
889:
890: if (path_len && path_len < intern->file_name_len) {
891: RETURN_STRINGL(intern->file_name + path_len + 1, intern->file_name_len - (path_len + 1), 1);
892: } else {
893: RETURN_STRINGL(intern->file_name, intern->file_name_len, 1);
894: }
895: }
896: /* }}} */
897:
898: /* {{{ proto string DirectoryIterator::getFilename()
899: Return filename of current dir entry */
900: SPL_METHOD(DirectoryIterator, getFilename)
901: {
902: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
903:
904: if (zend_parse_parameters_none() == FAILURE) {
905: return;
906: }
907:
908: RETURN_STRING(intern->u.dir.entry.d_name, 1);
909: }
910: /* }}} */
911:
912: /* {{{ proto string SplFileInfo::getExtension()
913: Returns file extension component of path */
914: SPL_METHOD(SplFileInfo, getExtension)
915: {
916: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
917: char *fname = NULL;
918: const char *p;
919: size_t flen;
920: int path_len, idx;
921:
922: if (zend_parse_parameters_none() == FAILURE) {
923: return;
924: }
925:
926: spl_filesystem_object_get_path(intern, &path_len TSRMLS_CC);
927:
928: if (path_len && path_len < intern->file_name_len) {
929: fname = intern->file_name + path_len + 1;
930: flen = intern->file_name_len - (path_len + 1);
931: } else {
932: fname = intern->file_name;
933: flen = intern->file_name_len;
934: }
935:
936: php_basename(fname, flen, NULL, 0, &fname, &flen TSRMLS_CC);
937:
938: p = zend_memrchr(fname, '.', flen);
939: if (p) {
940: idx = p - fname;
941: RETVAL_STRINGL(fname + idx + 1, flen - idx - 1, 1);
942: efree(fname);
943: return;
944: } else {
945: if (fname) {
946: efree(fname);
947: }
948: RETURN_EMPTY_STRING();
949: }
950: }
951: /* }}}*/
952:
953: /* {{{ proto string DirectoryIterator::getExtension()
954: Returns the file extension component of path */
955: SPL_METHOD(DirectoryIterator, getExtension)
956: {
957: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
958: char *fname = NULL;
959: const char *p;
960: size_t flen;
961: int idx;
962:
963: if (zend_parse_parameters_none() == FAILURE) {
964: return;
965: }
966:
967: php_basename(intern->u.dir.entry.d_name, strlen(intern->u.dir.entry.d_name), NULL, 0, &fname, &flen TSRMLS_CC);
968:
969: p = zend_memrchr(fname, '.', flen);
970: if (p) {
971: idx = p - fname;
972: RETVAL_STRINGL(fname + idx + 1, flen - idx - 1, 1);
973: efree(fname);
974: return;
975: } else {
976: if (fname) {
977: efree(fname);
978: }
979: RETURN_EMPTY_STRING();
980: }
981: }
982: /* }}} */
983:
984: /* {{{ proto string SplFileInfo::getBasename([string $suffix]) U
985: Returns filename component of path */
986: SPL_METHOD(SplFileInfo, getBasename)
987: {
988: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
989: char *fname, *suffix = 0;
990: size_t flen;
991: int slen = 0, path_len;
992:
993: if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &suffix, &slen) == FAILURE) {
994: return;
995: }
996:
997: spl_filesystem_object_get_path(intern, &path_len TSRMLS_CC);
998:
999: if (path_len && path_len < intern->file_name_len) {
1000: fname = intern->file_name + path_len + 1;
1001: flen = intern->file_name_len - (path_len + 1);
1002: } else {
1003: fname = intern->file_name;
1004: flen = intern->file_name_len;
1005: }
1006:
1007: php_basename(fname, flen, suffix, slen, &fname, &flen TSRMLS_CC);
1008:
1009: RETURN_STRINGL(fname, flen, 0);
1010: }
1011: /* }}}*/
1012:
1013: /* {{{ proto string DirectoryIterator::getBasename([string $suffix]) U
1014: Returns filename component of current dir entry */
1015: SPL_METHOD(DirectoryIterator, getBasename)
1016: {
1017: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
1018: char *suffix = 0, *fname;
1019: int slen = 0;
1020: size_t flen;
1021:
1022: if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &suffix, &slen) == FAILURE) {
1023: return;
1024: }
1025:
1026: php_basename(intern->u.dir.entry.d_name, strlen(intern->u.dir.entry.d_name), suffix, slen, &fname, &flen TSRMLS_CC);
1027:
1028: RETURN_STRINGL(fname, flen, 0);
1029: }
1030: /* }}} */
1031:
1032: /* {{{ proto string SplFileInfo::getPathname()
1033: Return path and filename */
1034: SPL_METHOD(SplFileInfo, getPathname)
1035: {
1036: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
1037: char *path;
1038: int path_len;
1039:
1040: if (zend_parse_parameters_none() == FAILURE) {
1041: return;
1042: }
1043: path = spl_filesystem_object_get_pathname(intern, &path_len TSRMLS_CC);
1044: if (path != NULL) {
1045: RETURN_STRINGL(path, path_len, 1);
1046: } else {
1047: RETURN_FALSE;
1048: }
1049: }
1050: /* }}} */
1051:
1052: /* {{{ proto string FilesystemIterator::key()
1053: Return getPathname() or getFilename() depending on flags */
1054: SPL_METHOD(FilesystemIterator, key)
1055: {
1056: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
1057:
1058: if (zend_parse_parameters_none() == FAILURE) {
1059: return;
1060: }
1061:
1062: if (SPL_FILE_DIR_KEY(intern, SPL_FILE_DIR_KEY_AS_FILENAME)) {
1063: RETURN_STRING(intern->u.dir.entry.d_name, 1);
1064: } else {
1065: spl_filesystem_object_get_file_name(intern TSRMLS_CC);
1066: RETURN_STRINGL(intern->file_name, intern->file_name_len, 1);
1067: }
1068: }
1069: /* }}} */
1070:
1071: /* {{{ proto string FilesystemIterator::current()
1072: Return getFilename(), getFileInfo() or $this depending on flags */
1073: SPL_METHOD(FilesystemIterator, current)
1074: {
1075: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
1076:
1077: if (zend_parse_parameters_none() == FAILURE) {
1078: return;
1079: }
1080:
1081: if (SPL_FILE_DIR_CURRENT(intern, SPL_FILE_DIR_CURRENT_AS_PATHNAME)) {
1082: spl_filesystem_object_get_file_name(intern TSRMLS_CC);
1083: RETURN_STRINGL(intern->file_name, intern->file_name_len, 1);
1084: } else if (SPL_FILE_DIR_CURRENT(intern, SPL_FILE_DIR_CURRENT_AS_FILEINFO)) {
1085: spl_filesystem_object_get_file_name(intern TSRMLS_CC);
1086: spl_filesystem_object_create_type(0, intern, SPL_FS_INFO, NULL, return_value TSRMLS_CC);
1087: } else {
1088: RETURN_ZVAL(getThis(), 1, 0);
1089: /*RETURN_STRING(intern->u.dir.entry.d_name, 1);*/
1090: }
1091: }
1092: /* }}} */
1093:
1094: /* {{{ proto bool DirectoryIterator::isDot()
1095: Returns true if current entry is '.' or '..' */
1096: SPL_METHOD(DirectoryIterator, isDot)
1097: {
1098: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
1099:
1100: if (zend_parse_parameters_none() == FAILURE) {
1101: return;
1102: }
1103:
1104: RETURN_BOOL(spl_filesystem_is_dot(intern->u.dir.entry.d_name));
1105: }
1106: /* }}} */
1107:
1108: /* {{{ proto void SplFileInfo::__construct(string file_name)
1109: Cronstructs a new SplFileInfo from a path. */
1110: /* zend_replace_error_handling() is used to throw exceptions in case
1111: the constructor fails. Here we use this to ensure the object
1112: has a valid directory resource.
1113:
1114: When the constructor gets called the object is already created
1115: by the engine, so we must only call 'additional' initializations.
1116: */
1117: SPL_METHOD(SplFileInfo, __construct)
1118: {
1119: spl_filesystem_object *intern;
1120: char *path;
1121: int len;
1122: zend_error_handling error_handling;
1123:
1124: zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling TSRMLS_CC);
1125:
1126: if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &path, &len) == FAILURE) {
1127: zend_restore_error_handling(&error_handling TSRMLS_CC);
1128: return;
1129: }
1130:
1131: intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
1132:
1133: spl_filesystem_info_set_filename(intern, path, len, 1 TSRMLS_CC);
1134:
1135: zend_restore_error_handling(&error_handling TSRMLS_CC);
1136:
1137: /* intern->type = SPL_FS_INFO; already set */
1138: }
1139: /* }}} */
1140:
1141: /* {{{ FileInfoFunction */
1142: #define FileInfoFunction(func_name, func_num) \
1143: SPL_METHOD(SplFileInfo, func_name) \
1144: { \
1145: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); \
1146: zend_error_handling error_handling; \
1147: if (zend_parse_parameters_none() == FAILURE) { \
1148: return; \
1149: } \
1150: \
1151: zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling TSRMLS_CC);\
1152: spl_filesystem_object_get_file_name(intern TSRMLS_CC); \
1153: php_stat(intern->file_name, intern->file_name_len, func_num, return_value TSRMLS_CC); \
1154: zend_restore_error_handling(&error_handling TSRMLS_CC); \
1155: }
1156: /* }}} */
1157:
1158: /* {{{ proto int SplFileInfo::getPerms()
1159: Get file permissions */
1160: FileInfoFunction(getPerms, FS_PERMS)
1161: /* }}} */
1162:
1163: /* {{{ proto int SplFileInfo::getInode()
1164: Get file inode */
1165: FileInfoFunction(getInode, FS_INODE)
1166: /* }}} */
1167:
1168: /* {{{ proto int SplFileInfo::getSize()
1169: Get file size */
1170: FileInfoFunction(getSize, FS_SIZE)
1171: /* }}} */
1172:
1173: /* {{{ proto int SplFileInfo::getOwner()
1174: Get file owner */
1175: FileInfoFunction(getOwner, FS_OWNER)
1176: /* }}} */
1177:
1178: /* {{{ proto int SplFileInfo::getGroup()
1179: Get file group */
1180: FileInfoFunction(getGroup, FS_GROUP)
1181: /* }}} */
1182:
1183: /* {{{ proto int SplFileInfo::getATime()
1184: Get last access time of file */
1185: FileInfoFunction(getATime, FS_ATIME)
1186: /* }}} */
1187:
1188: /* {{{ proto int SplFileInfo::getMTime()
1189: Get last modification time of file */
1190: FileInfoFunction(getMTime, FS_MTIME)
1191: /* }}} */
1192:
1193: /* {{{ proto int SplFileInfo::getCTime()
1194: Get inode modification time of file */
1195: FileInfoFunction(getCTime, FS_CTIME)
1196: /* }}} */
1197:
1198: /* {{{ proto string SplFileInfo::getType()
1199: Get file type */
1200: FileInfoFunction(getType, FS_TYPE)
1201: /* }}} */
1202:
1203: /* {{{ proto bool SplFileInfo::isWritable()
1204: Returns true if file can be written */
1205: FileInfoFunction(isWritable, FS_IS_W)
1206: /* }}} */
1207:
1208: /* {{{ proto bool SplFileInfo::isReadable()
1209: Returns true if file can be read */
1210: FileInfoFunction(isReadable, FS_IS_R)
1211: /* }}} */
1212:
1213: /* {{{ proto bool SplFileInfo::isExecutable()
1214: Returns true if file is executable */
1215: FileInfoFunction(isExecutable, FS_IS_X)
1216: /* }}} */
1217:
1218: /* {{{ proto bool SplFileInfo::isFile()
1219: Returns true if file is a regular file */
1220: FileInfoFunction(isFile, FS_IS_FILE)
1221: /* }}} */
1222:
1223: /* {{{ proto bool SplFileInfo::isDir()
1224: Returns true if file is directory */
1225: FileInfoFunction(isDir, FS_IS_DIR)
1226: /* }}} */
1227:
1228: /* {{{ proto bool SplFileInfo::isLink()
1229: Returns true if file is symbolic link */
1230: FileInfoFunction(isLink, FS_IS_LINK)
1231: /* }}} */
1232:
1233: /* {{{ proto string SplFileInfo::getLinkTarget() U
1234: Return the target of a symbolic link */
1235: SPL_METHOD(SplFileInfo, getLinkTarget)
1236: {
1237: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
1238: int ret;
1239: char buff[MAXPATHLEN];
1240: zend_error_handling error_handling;
1241:
1242: if (zend_parse_parameters_none() == FAILURE) {
1243: return;
1244: }
1245:
1246: zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling TSRMLS_CC);
1247:
1248: #if defined(PHP_WIN32) || HAVE_SYMLINK
1249: if (intern->file_name == NULL) {
1250: php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty filename");
1251: RETURN_FALSE;
1252: } else if (!IS_ABSOLUTE_PATH(intern->file_name, intern->file_name_len)) {
1253: char expanded_path[MAXPATHLEN];
1.1.1.2 misho 1254: if (!expand_filepath_with_mode(intern->file_name, expanded_path, NULL, 0, CWD_EXPAND TSRMLS_CC)) {
1.1 misho 1255: php_error_docref(NULL TSRMLS_CC, E_WARNING, "No such file or directory");
1256: RETURN_FALSE;
1257: }
1258: ret = php_sys_readlink(expanded_path, buff, MAXPATHLEN - 1);
1259: } else {
1260: ret = php_sys_readlink(intern->file_name, buff, MAXPATHLEN-1);
1261: }
1262: #else
1263: ret = -1; /* always fail if not implemented */
1264: #endif
1265:
1266: if (ret == -1) {
1267: zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Unable to read link %s, error: %s", intern->file_name, strerror(errno));
1268: RETVAL_FALSE;
1269: } else {
1270: /* Append NULL to the end of the string */
1271: buff[ret] = '\0';
1272:
1273: RETVAL_STRINGL(buff, ret, 1);
1274: }
1275:
1276: zend_restore_error_handling(&error_handling TSRMLS_CC);
1277: }
1278: /* }}} */
1279:
1280: #if (!defined(__BEOS__) && !defined(NETWARE) && HAVE_REALPATH) || defined(ZTS)
1281: /* {{{ proto string SplFileInfo::getRealPath()
1282: Return the resolved path */
1283: SPL_METHOD(SplFileInfo, getRealPath)
1284: {
1285: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
1286: char buff[MAXPATHLEN];
1287: char *filename;
1288: zend_error_handling error_handling;
1289:
1290: if (zend_parse_parameters_none() == FAILURE) {
1291: return;
1292: }
1293:
1294: zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling TSRMLS_CC);
1295:
1296: if (intern->type == SPL_FS_DIR && !intern->file_name && intern->u.dir.entry.d_name[0]) {
1297: spl_filesystem_object_get_file_name(intern TSRMLS_CC);
1298: }
1299:
1300: if (intern->orig_path) {
1301: filename = intern->orig_path;
1302: } else {
1303: filename = intern->file_name;
1304: }
1305:
1306:
1307: if (filename && VCWD_REALPATH(filename, buff)) {
1308: #ifdef ZTS
1309: if (VCWD_ACCESS(buff, F_OK)) {
1310: RETVAL_FALSE;
1311: } else
1312: #endif
1313: RETVAL_STRING(buff, 1);
1314: } else {
1315: RETVAL_FALSE;
1316: }
1317:
1318: zend_restore_error_handling(&error_handling TSRMLS_CC);
1319: }
1320: /* }}} */
1321: #endif
1322:
1323: /* {{{ proto SplFileObject SplFileInfo::openFile([string mode = 'r' [, bool use_include_path [, resource context]]])
1324: Open the current file */
1325: SPL_METHOD(SplFileInfo, openFile)
1326: {
1327: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
1328:
1329: spl_filesystem_object_create_type(ht, intern, SPL_FS_FILE, NULL, return_value TSRMLS_CC);
1330: }
1331: /* }}} */
1332:
1333: /* {{{ proto void SplFileInfo::setFileClass([string class_name])
1334: Class to use in openFile() */
1335: SPL_METHOD(SplFileInfo, setFileClass)
1336: {
1337: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
1338: zend_class_entry *ce = spl_ce_SplFileObject;
1339: zend_error_handling error_handling;
1340:
1341: zend_replace_error_handling(EH_THROW, spl_ce_UnexpectedValueException, &error_handling TSRMLS_CC);
1342:
1343: if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &ce) == SUCCESS) {
1344: intern->file_class = ce;
1345: }
1346:
1347: zend_restore_error_handling(&error_handling TSRMLS_CC);
1348: }
1349: /* }}} */
1350:
1351: /* {{{ proto void SplFileInfo::setInfoClass([string class_name])
1352: Class to use in getFileInfo(), getPathInfo() */
1353: SPL_METHOD(SplFileInfo, setInfoClass)
1354: {
1355: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
1356: zend_class_entry *ce = spl_ce_SplFileInfo;
1357: zend_error_handling error_handling;
1358:
1359: zend_replace_error_handling(EH_THROW, spl_ce_UnexpectedValueException, &error_handling TSRMLS_CC);
1360:
1361: if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &ce) == SUCCESS) {
1362: intern->info_class = ce;
1363: }
1364:
1365: zend_restore_error_handling(&error_handling TSRMLS_CC);
1366: }
1367: /* }}} */
1368:
1369: /* {{{ proto SplFileInfo SplFileInfo::getFileInfo([string $class_name])
1370: Get/copy file info */
1371: SPL_METHOD(SplFileInfo, getFileInfo)
1372: {
1373: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
1374: zend_class_entry *ce = intern->info_class;
1375: zend_error_handling error_handling;
1376:
1377: zend_replace_error_handling(EH_THROW, spl_ce_UnexpectedValueException, &error_handling TSRMLS_CC);
1378:
1379: if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &ce) == SUCCESS) {
1380: spl_filesystem_object_create_type(ht, intern, SPL_FS_INFO, ce, return_value TSRMLS_CC);
1381: }
1382:
1383: zend_restore_error_handling(&error_handling TSRMLS_CC);
1384: }
1385: /* }}} */
1386:
1387: /* {{{ proto SplFileInfo SplFileInfo::getPathInfo([string $class_name])
1388: Get/copy file info */
1389: SPL_METHOD(SplFileInfo, getPathInfo)
1390: {
1391: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
1392: zend_class_entry *ce = intern->info_class;
1393: zend_error_handling error_handling;
1394:
1395: zend_replace_error_handling(EH_THROW, spl_ce_UnexpectedValueException, &error_handling TSRMLS_CC);
1396:
1397: if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &ce) == SUCCESS) {
1398: int path_len;
1399: char *path = spl_filesystem_object_get_pathname(intern, &path_len TSRMLS_CC);
1400: if (path) {
1401: char *dpath = estrndup(path, path_len);
1402: path_len = php_dirname(dpath, path_len);
1403: spl_filesystem_object_create_info(intern, dpath, path_len, 1, ce, return_value TSRMLS_CC);
1404: efree(dpath);
1405: }
1406: }
1407:
1408: zend_restore_error_handling(&error_handling TSRMLS_CC);
1409: }
1410: /* }}} */
1411:
1412: /* {{{ */
1413: SPL_METHOD(SplFileInfo, _bad_state_ex)
1414: {
1415: zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC,
1416: "The parent constructor was not called: the object is in an "
1417: "invalid state ");
1418: }
1419: /* }}} */
1420:
1421: /* {{{ proto void FilesystemIterator::__construct(string path [, int flags])
1422: Cronstructs a new dir iterator from a path. */
1423: SPL_METHOD(FilesystemIterator, __construct)
1424: {
1425: spl_filesystem_object_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, DIT_CTOR_FLAGS | SPL_FILE_DIR_SKIPDOTS);
1426: }
1427: /* }}} */
1428:
1429: /* {{{ proto void FilesystemIterator::rewind()
1430: Rewind dir back to the start */
1431: SPL_METHOD(FilesystemIterator, rewind)
1432: {
1433: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
1.1.1.3 ! misho 1434: int skip_dots = SPL_HAS_FLAG(intern->flags, SPL_FILE_DIR_SKIPDOTS);
1.1 misho 1435:
1436: if (zend_parse_parameters_none() == FAILURE) {
1437: return;
1438: }
1439:
1440: intern->u.dir.index = 0;
1441: if (intern->u.dir.dirp) {
1442: php_stream_rewinddir(intern->u.dir.dirp);
1443: }
1444: do {
1445: spl_filesystem_dir_read(intern TSRMLS_CC);
1.1.1.3 ! misho 1446: } while (skip_dots && spl_filesystem_is_dot(intern->u.dir.entry.d_name));
1.1 misho 1447: }
1448: /* }}} */
1449:
1450: /* {{{ proto int FilesystemIterator::getFlags()
1451: Get handling flags */
1452: SPL_METHOD(FilesystemIterator, getFlags)
1453: {
1454: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
1455:
1456: if (zend_parse_parameters_none() == FAILURE) {
1457: return;
1458: }
1459:
1460: RETURN_LONG(intern->flags & (SPL_FILE_DIR_KEY_MODE_MASK | SPL_FILE_DIR_CURRENT_MODE_MASK | SPL_FILE_DIR_OTHERS_MASK));
1461: } /* }}} */
1462:
1463: /* {{{ proto void FilesystemIterator::setFlags(long $flags)
1464: Set handling flags */
1465: SPL_METHOD(FilesystemIterator, setFlags)
1466: {
1467: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
1468: long flags;
1469:
1470: if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &flags) == FAILURE) {
1471: return;
1472: }
1473:
1474: intern->flags &= ~(SPL_FILE_DIR_KEY_MODE_MASK|SPL_FILE_DIR_CURRENT_MODE_MASK|SPL_FILE_DIR_OTHERS_MASK);
1475: intern->flags |= ((SPL_FILE_DIR_KEY_MODE_MASK|SPL_FILE_DIR_CURRENT_MODE_MASK|SPL_FILE_DIR_OTHERS_MASK) & flags);
1476: } /* }}} */
1477:
1478: /* {{{ proto bool RecursiveDirectoryIterator::hasChildren([bool $allow_links = false])
1479: Returns whether current entry is a directory and not '.' or '..' */
1480: SPL_METHOD(RecursiveDirectoryIterator, hasChildren)
1481: {
1482: zend_bool allow_links = 0;
1483: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
1484:
1485: if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &allow_links) == FAILURE) {
1486: return;
1487: }
1488: if (spl_filesystem_is_invalid_or_dot(intern->u.dir.entry.d_name)) {
1489: RETURN_FALSE;
1490: } else {
1491: spl_filesystem_object_get_file_name(intern TSRMLS_CC);
1492: if (!allow_links && !(intern->flags & SPL_FILE_DIR_FOLLOW_SYMLINKS)) {
1493: php_stat(intern->file_name, intern->file_name_len, FS_IS_LINK, return_value TSRMLS_CC);
1494: if (zend_is_true(return_value)) {
1495: RETURN_FALSE;
1496: }
1497: }
1498: php_stat(intern->file_name, intern->file_name_len, FS_IS_DIR, return_value TSRMLS_CC);
1499: }
1500: }
1501: /* }}} */
1502:
1503: /* {{{ proto RecursiveDirectoryIterator DirectoryIterator::getChildren()
1504: Returns an iterator for the current entry if it is a directory */
1505: SPL_METHOD(RecursiveDirectoryIterator, getChildren)
1506: {
1507: zval zpath, zflags;
1508: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
1509: spl_filesystem_object *subdir;
1510: char slash = SPL_HAS_FLAG(intern->flags, SPL_FILE_DIR_UNIXPATHS) ? '/' : DEFAULT_SLASH;
1511:
1512: if (zend_parse_parameters_none() == FAILURE) {
1513: return;
1514: }
1515:
1516: spl_filesystem_object_get_file_name(intern TSRMLS_CC);
1517:
1518: if (SPL_HAS_FLAG(intern->flags, SPL_FILE_DIR_CURRENT_AS_PATHNAME)) {
1519: RETURN_STRINGL(intern->file_name, intern->file_name_len, 1);
1520: } else {
1521: INIT_PZVAL(&zflags);
1522: INIT_PZVAL(&zpath);
1523: ZVAL_LONG(&zflags, intern->flags);
1524: ZVAL_STRINGL(&zpath, intern->file_name, intern->file_name_len, 0);
1525: spl_instantiate_arg_ex2(Z_OBJCE_P(getThis()), &return_value, 0, &zpath, &zflags TSRMLS_CC);
1526:
1527: subdir = (spl_filesystem_object*)zend_object_store_get_object(return_value TSRMLS_CC);
1528: if (subdir) {
1529: if (intern->u.dir.sub_path && intern->u.dir.sub_path[0]) {
1530: subdir->u.dir.sub_path_len = spprintf(&subdir->u.dir.sub_path, 0, "%s%c%s", intern->u.dir.sub_path, slash, intern->u.dir.entry.d_name);
1531: } else {
1532: subdir->u.dir.sub_path_len = strlen(intern->u.dir.entry.d_name);
1533: subdir->u.dir.sub_path = estrndup(intern->u.dir.entry.d_name, subdir->u.dir.sub_path_len);
1534: }
1535: subdir->info_class = intern->info_class;
1536: subdir->file_class = intern->file_class;
1537: subdir->oth = intern->oth;
1538: }
1539: }
1540: }
1541: /* }}} */
1542:
1543: /* {{{ proto void RecursiveDirectoryIterator::getSubPath()
1544: Get sub path */
1545: SPL_METHOD(RecursiveDirectoryIterator, getSubPath)
1546: {
1547: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
1548:
1549: if (zend_parse_parameters_none() == FAILURE) {
1550: return;
1551: }
1552:
1553: if (intern->u.dir.sub_path) {
1554: RETURN_STRINGL(intern->u.dir.sub_path, intern->u.dir.sub_path_len, 1);
1555: } else {
1556: RETURN_STRINGL("", 0, 1);
1557: }
1558: }
1559: /* }}} */
1560:
1561: /* {{{ proto void RecursiveDirectoryIterator::getSubPathname()
1562: Get sub path and file name */
1563: SPL_METHOD(RecursiveDirectoryIterator, getSubPathname)
1564: {
1565: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
1566: char *sub_name;
1567: int len;
1568: char slash = SPL_HAS_FLAG(intern->flags, SPL_FILE_DIR_UNIXPATHS) ? '/' : DEFAULT_SLASH;
1569:
1570: if (zend_parse_parameters_none() == FAILURE) {
1571: return;
1572: }
1573:
1574: if (intern->u.dir.sub_path) {
1575: len = spprintf(&sub_name, 0, "%s%c%s", intern->u.dir.sub_path, slash, intern->u.dir.entry.d_name);
1576: RETURN_STRINGL(sub_name, len, 0);
1577: } else {
1578: RETURN_STRING(intern->u.dir.entry.d_name, 1);
1579: }
1580: }
1581: /* }}} */
1582:
1583: /* {{{ proto int RecursiveDirectoryIterator::__construct(string path [, int flags])
1584: Cronstructs a new dir iterator from a path. */
1585: SPL_METHOD(RecursiveDirectoryIterator, __construct)
1586: {
1587: spl_filesystem_object_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, DIT_CTOR_FLAGS);
1588: }
1589: /* }}} */
1590:
1591: #ifdef HAVE_GLOB
1592: /* {{{ proto int GlobIterator::__construct(string path [, int flags])
1593: Cronstructs a new dir iterator from a glob expression (no glob:// needed). */
1594: SPL_METHOD(GlobIterator, __construct)
1595: {
1596: spl_filesystem_object_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, DIT_CTOR_FLAGS|DIT_CTOR_GLOB);
1597: }
1598: /* }}} */
1599:
1600: /* {{{ proto int GlobIterator::cont()
1601: Return the number of directories and files found by globbing */
1602: SPL_METHOD(GlobIterator, count)
1603: {
1604: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
1605:
1606: if (zend_parse_parameters_none() == FAILURE) {
1607: return;
1608: }
1609:
1610: if (php_stream_is(intern->u.dir.dirp ,&php_glob_stream_ops)) {
1611: RETURN_LONG(php_glob_stream_get_count(intern->u.dir.dirp, NULL));
1612: } else {
1613: /* should not happen */
1614: php_error_docref(NULL TSRMLS_CC, E_ERROR, "GlobIterator lost glob state");
1615: }
1616: }
1617: /* }}} */
1618: #endif /* HAVE_GLOB */
1619:
1620: /* {{{ forward declarations to the iterator handlers */
1621: static void spl_filesystem_dir_it_dtor(zend_object_iterator *iter TSRMLS_DC);
1622: static int spl_filesystem_dir_it_valid(zend_object_iterator *iter TSRMLS_DC);
1623: static void spl_filesystem_dir_it_current_data(zend_object_iterator *iter, zval ***data TSRMLS_DC);
1624: static int spl_filesystem_dir_it_current_key(zend_object_iterator *iter, char **str_key, uint *str_key_len, ulong *int_key TSRMLS_DC);
1625: static void spl_filesystem_dir_it_move_forward(zend_object_iterator *iter TSRMLS_DC);
1626: static void spl_filesystem_dir_it_rewind(zend_object_iterator *iter TSRMLS_DC);
1627:
1628: /* iterator handler table */
1629: zend_object_iterator_funcs spl_filesystem_dir_it_funcs = {
1630: spl_filesystem_dir_it_dtor,
1631: spl_filesystem_dir_it_valid,
1632: spl_filesystem_dir_it_current_data,
1633: spl_filesystem_dir_it_current_key,
1634: spl_filesystem_dir_it_move_forward,
1635: spl_filesystem_dir_it_rewind
1636: };
1637: /* }}} */
1638:
1639: /* {{{ spl_ce_dir_get_iterator */
1640: zend_object_iterator *spl_filesystem_dir_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC)
1641: {
1642: spl_filesystem_iterator *iterator;
1643: spl_filesystem_object *dir_object;
1644:
1645: if (by_ref) {
1646: zend_error(E_ERROR, "An iterator cannot be used with foreach by reference");
1647: }
1648: dir_object = (spl_filesystem_object*)zend_object_store_get_object(object TSRMLS_CC);
1649: iterator = spl_filesystem_object_to_iterator(dir_object);
1650:
1.1.1.2 misho 1651: /* initialize iterator if it wasn't gotten before */
1652: if (iterator->intern.data == NULL) {
1653: iterator->intern.data = object;
1654: iterator->intern.funcs = &spl_filesystem_dir_it_funcs;
1655: /* ->current must be initialized; rewind doesn't set it and valid
1656: * doesn't check whether it's set */
1657: iterator->current = object;
1658: }
1659: zval_add_ref(&object);
1.1 misho 1660:
1661: return (zend_object_iterator*)iterator;
1662: }
1663: /* }}} */
1664:
1665: /* {{{ spl_filesystem_dir_it_dtor */
1666: static void spl_filesystem_dir_it_dtor(zend_object_iterator *iter TSRMLS_DC)
1667: {
1668: spl_filesystem_iterator *iterator = (spl_filesystem_iterator *)iter;
1669:
1.1.1.2 misho 1670: if (iterator->intern.data) {
1671: zval *object = iterator->intern.data;
1672: zval_ptr_dtor(&object);
1673: }
1674: /* Otherwise we were called from the owning object free storage handler as
1675: * it sets
1676: * iterator->intern.data to NULL.
1677: * We don't even need to destroy iterator->current as we didn't add a
1678: * reference to it in move_forward or get_iterator */
1.1 misho 1679: }
1680: /* }}} */
1681:
1682: /* {{{ spl_filesystem_dir_it_valid */
1683: static int spl_filesystem_dir_it_valid(zend_object_iterator *iter TSRMLS_DC)
1684: {
1685: spl_filesystem_object *object = spl_filesystem_iterator_to_object((spl_filesystem_iterator *)iter);
1686:
1687: return object->u.dir.entry.d_name[0] != '\0' ? SUCCESS : FAILURE;
1688: }
1689: /* }}} */
1690:
1691: /* {{{ spl_filesystem_dir_it_current_data */
1692: static void spl_filesystem_dir_it_current_data(zend_object_iterator *iter, zval ***data TSRMLS_DC)
1693: {
1694: spl_filesystem_iterator *iterator = (spl_filesystem_iterator *)iter;
1695:
1696: *data = &iterator->current;
1697: }
1698: /* }}} */
1699:
1700: /* {{{ spl_filesystem_dir_it_current_key */
1701: static int spl_filesystem_dir_it_current_key(zend_object_iterator *iter, char **str_key, uint *str_key_len, ulong *int_key TSRMLS_DC)
1702: {
1703: spl_filesystem_object *object = spl_filesystem_iterator_to_object((spl_filesystem_iterator *)iter);
1704:
1705: *int_key = object->u.dir.index;
1706: return HASH_KEY_IS_LONG;
1707: }
1708: /* }}} */
1709:
1710: /* {{{ spl_filesystem_dir_it_move_forward */
1711: static void spl_filesystem_dir_it_move_forward(zend_object_iterator *iter TSRMLS_DC)
1712: {
1713: spl_filesystem_object *object = spl_filesystem_iterator_to_object((spl_filesystem_iterator *)iter);
1714:
1715: object->u.dir.index++;
1716: spl_filesystem_dir_read(object TSRMLS_CC);
1717: if (object->file_name) {
1718: efree(object->file_name);
1719: object->file_name = NULL;
1720: }
1721: }
1722: /* }}} */
1723:
1724: /* {{{ spl_filesystem_dir_it_rewind */
1725: static void spl_filesystem_dir_it_rewind(zend_object_iterator *iter TSRMLS_DC)
1726: {
1727: spl_filesystem_object *object = spl_filesystem_iterator_to_object((spl_filesystem_iterator *)iter);
1728:
1729: object->u.dir.index = 0;
1730: if (object->u.dir.dirp) {
1731: php_stream_rewinddir(object->u.dir.dirp);
1732: }
1733: spl_filesystem_dir_read(object TSRMLS_CC);
1734: }
1735: /* }}} */
1736:
1737: /* {{{ spl_filesystem_tree_it_dtor */
1738: static void spl_filesystem_tree_it_dtor(zend_object_iterator *iter TSRMLS_DC)
1739: {
1740: spl_filesystem_iterator *iterator = (spl_filesystem_iterator *)iter;
1741:
1.1.1.2 misho 1742: if (iterator->intern.data) {
1743: zval *object = iterator->intern.data;
1744: zval_ptr_dtor(&object);
1745: } else {
1746: if (iterator->current) {
1747: zval_ptr_dtor(&iterator->current);
1748: }
1.1 misho 1749: }
1750: }
1751: /* }}} */
1752:
1753: /* {{{ spl_filesystem_tree_it_current_data */
1754: static void spl_filesystem_tree_it_current_data(zend_object_iterator *iter, zval ***data TSRMLS_DC)
1755: {
1756: spl_filesystem_iterator *iterator = (spl_filesystem_iterator *)iter;
1757: spl_filesystem_object *object = spl_filesystem_iterator_to_object(iterator);
1758:
1759: if (SPL_FILE_DIR_CURRENT(object, SPL_FILE_DIR_CURRENT_AS_PATHNAME)) {
1760: if (!iterator->current) {
1761: ALLOC_INIT_ZVAL(iterator->current);
1762: spl_filesystem_object_get_file_name(object TSRMLS_CC);
1763: ZVAL_STRINGL(iterator->current, object->file_name, object->file_name_len, 1);
1764: }
1765: *data = &iterator->current;
1766: } else if (SPL_FILE_DIR_CURRENT(object, SPL_FILE_DIR_CURRENT_AS_FILEINFO)) {
1767: if (!iterator->current) {
1768: ALLOC_INIT_ZVAL(iterator->current);
1769: spl_filesystem_object_get_file_name(object TSRMLS_CC);
1770: spl_filesystem_object_create_type(0, object, SPL_FS_INFO, NULL, iterator->current TSRMLS_CC);
1771: }
1772: *data = &iterator->current;
1773: } else {
1774: *data = (zval**)&iterator->intern.data;
1775: }
1776: }
1777: /* }}} */
1778:
1779: /* {{{ spl_filesystem_tree_it_current_key */
1780: static int spl_filesystem_tree_it_current_key(zend_object_iterator *iter, char **str_key, uint *str_key_len, ulong *int_key TSRMLS_DC)
1781: {
1782: spl_filesystem_object *object = spl_filesystem_iterator_to_object((spl_filesystem_iterator *)iter);
1783:
1784: if (SPL_FILE_DIR_KEY(object, SPL_FILE_DIR_KEY_AS_FILENAME)) {
1785: *str_key_len = strlen(object->u.dir.entry.d_name) + 1;
1786: *str_key = estrndup(object->u.dir.entry.d_name, *str_key_len - 1);
1787: } else {
1788: spl_filesystem_object_get_file_name(object TSRMLS_CC);
1789: *str_key_len = object->file_name_len + 1;
1790: *str_key = estrndup(object->file_name, object->file_name_len);
1791: }
1792: return HASH_KEY_IS_STRING;
1793: }
1794: /* }}} */
1795:
1796: /* {{{ spl_filesystem_tree_it_move_forward */
1797: static void spl_filesystem_tree_it_move_forward(zend_object_iterator *iter TSRMLS_DC)
1798: {
1799: spl_filesystem_iterator *iterator = (spl_filesystem_iterator *)iter;
1800: spl_filesystem_object *object = spl_filesystem_iterator_to_object(iterator);
1801:
1802: object->u.dir.index++;
1803: do {
1804: spl_filesystem_dir_read(object TSRMLS_CC);
1805: } while (spl_filesystem_is_dot(object->u.dir.entry.d_name));
1806: if (object->file_name) {
1807: efree(object->file_name);
1808: object->file_name = NULL;
1809: }
1810: if (iterator->current) {
1811: zval_ptr_dtor(&iterator->current);
1812: iterator->current = NULL;
1813: }
1814: }
1815: /* }}} */
1816:
1817: /* {{{ spl_filesystem_tree_it_rewind */
1818: static void spl_filesystem_tree_it_rewind(zend_object_iterator *iter TSRMLS_DC)
1819: {
1820: spl_filesystem_iterator *iterator = (spl_filesystem_iterator *)iter;
1821: spl_filesystem_object *object = spl_filesystem_iterator_to_object(iterator);
1822:
1823: object->u.dir.index = 0;
1824: if (object->u.dir.dirp) {
1825: php_stream_rewinddir(object->u.dir.dirp);
1826: }
1827: do {
1828: spl_filesystem_dir_read(object TSRMLS_CC);
1829: } while (spl_filesystem_is_dot(object->u.dir.entry.d_name));
1830: if (iterator->current) {
1831: zval_ptr_dtor(&iterator->current);
1832: iterator->current = NULL;
1833: }
1834: }
1835: /* }}} */
1836:
1837: /* {{{ iterator handler table */
1838: zend_object_iterator_funcs spl_filesystem_tree_it_funcs = {
1839: spl_filesystem_tree_it_dtor,
1840: spl_filesystem_dir_it_valid,
1841: spl_filesystem_tree_it_current_data,
1842: spl_filesystem_tree_it_current_key,
1843: spl_filesystem_tree_it_move_forward,
1844: spl_filesystem_tree_it_rewind
1845: };
1846: /* }}} */
1847:
1848: /* {{{ spl_ce_dir_get_iterator */
1849: zend_object_iterator *spl_filesystem_tree_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC)
1850: {
1851: spl_filesystem_iterator *iterator;
1852: spl_filesystem_object *dir_object;
1853:
1854: if (by_ref) {
1855: zend_error(E_ERROR, "An iterator cannot be used with foreach by reference");
1856: }
1857: dir_object = (spl_filesystem_object*)zend_object_store_get_object(object TSRMLS_CC);
1858: iterator = spl_filesystem_object_to_iterator(dir_object);
1859:
1.1.1.2 misho 1860: /* initialize iterator if wasn't gotten before */
1861: if (iterator->intern.data == NULL) {
1862: iterator->intern.data = object;
1863: iterator->intern.funcs = &spl_filesystem_tree_it_funcs;
1864: }
1865: zval_add_ref(&object);
1.1 misho 1866:
1867: return (zend_object_iterator*)iterator;
1868: }
1869: /* }}} */
1870:
1871: /* {{{ spl_filesystem_object_cast */
1872: static int spl_filesystem_object_cast(zval *readobj, zval *writeobj, int type TSRMLS_DC)
1873: {
1874: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(readobj TSRMLS_CC);
1875:
1876: if (type == IS_STRING) {
1.1.1.3 ! misho 1877: if (Z_OBJCE_P(readobj)->__tostring) {
! 1878: return std_object_handlers.cast_object(readobj, writeobj, type TSRMLS_CC);
! 1879: }
! 1880:
1.1 misho 1881: switch (intern->type) {
1882: case SPL_FS_INFO:
1883: case SPL_FS_FILE:
1884: if (readobj == writeobj) {
1885: zval retval;
1886: zval *retval_ptr = &retval;
1887:
1888: ZVAL_STRINGL(retval_ptr, intern->file_name, intern->file_name_len, 1);
1889: zval_dtor(readobj);
1890: ZVAL_ZVAL(writeobj, retval_ptr, 0, 0);
1891: } else {
1892: ZVAL_STRINGL(writeobj, intern->file_name, intern->file_name_len, 1);
1893: }
1894: return SUCCESS;
1895: case SPL_FS_DIR:
1896: if (readobj == writeobj) {
1897: zval retval;
1898: zval *retval_ptr = &retval;
1899:
1900: ZVAL_STRING(retval_ptr, intern->u.dir.entry.d_name, 1);
1901: zval_dtor(readobj);
1902: ZVAL_ZVAL(writeobj, retval_ptr, 0, 0);
1903: } else {
1904: ZVAL_STRING(writeobj, intern->u.dir.entry.d_name, 1);
1905: }
1906: return SUCCESS;
1907: }
1908: }
1909: if (readobj == writeobj) {
1910: zval_dtor(readobj);
1911: }
1912: ZVAL_NULL(writeobj);
1913: return FAILURE;
1914: }
1915: /* }}} */
1916:
1917: /* {{{ declare method parameters */
1918: /* supply a name and default to call by parameter */
1919: ZEND_BEGIN_ARG_INFO(arginfo_info___construct, 0)
1920: ZEND_ARG_INFO(0, file_name)
1921: ZEND_END_ARG_INFO()
1922:
1923: ZEND_BEGIN_ARG_INFO_EX(arginfo_info_openFile, 0, 0, 0)
1924: ZEND_ARG_INFO(0, open_mode)
1925: ZEND_ARG_INFO(0, use_include_path)
1926: ZEND_ARG_INFO(0, context)
1927: ZEND_END_ARG_INFO()
1928:
1929: ZEND_BEGIN_ARG_INFO_EX(arginfo_info_optinalFileClass, 0, 0, 0)
1930: ZEND_ARG_INFO(0, class_name)
1931: ZEND_END_ARG_INFO()
1932:
1933: ZEND_BEGIN_ARG_INFO_EX(arginfo_optinalSuffix, 0, 0, 0)
1934: ZEND_ARG_INFO(0, suffix)
1935: ZEND_END_ARG_INFO()
1936:
1937: ZEND_BEGIN_ARG_INFO(arginfo_splfileinfo_void, 0)
1938: ZEND_END_ARG_INFO()
1939:
1940: /* the method table */
1941: /* each method can have its own parameters and visibility */
1942: static const zend_function_entry spl_SplFileInfo_functions[] = {
1943: SPL_ME(SplFileInfo, __construct, arginfo_info___construct, ZEND_ACC_PUBLIC)
1944: SPL_ME(SplFileInfo, getPath, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1945: SPL_ME(SplFileInfo, getFilename, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1946: SPL_ME(SplFileInfo, getExtension, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1947: SPL_ME(SplFileInfo, getBasename, arginfo_optinalSuffix, ZEND_ACC_PUBLIC)
1948: SPL_ME(SplFileInfo, getPathname, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1949: SPL_ME(SplFileInfo, getPerms, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1950: SPL_ME(SplFileInfo, getInode, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1951: SPL_ME(SplFileInfo, getSize, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1952: SPL_ME(SplFileInfo, getOwner, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1953: SPL_ME(SplFileInfo, getGroup, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1954: SPL_ME(SplFileInfo, getATime, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1955: SPL_ME(SplFileInfo, getMTime, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1956: SPL_ME(SplFileInfo, getCTime, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1957: SPL_ME(SplFileInfo, getType, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1958: SPL_ME(SplFileInfo, isWritable, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1959: SPL_ME(SplFileInfo, isReadable, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1960: SPL_ME(SplFileInfo, isExecutable, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1961: SPL_ME(SplFileInfo, isFile, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1962: SPL_ME(SplFileInfo, isDir, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1963: SPL_ME(SplFileInfo, isLink, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1964: SPL_ME(SplFileInfo, getLinkTarget, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1965: #if (!defined(__BEOS__) && !defined(NETWARE) && HAVE_REALPATH) || defined(ZTS)
1966: SPL_ME(SplFileInfo, getRealPath, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1967: #endif
1968: SPL_ME(SplFileInfo, getFileInfo, arginfo_info_optinalFileClass, ZEND_ACC_PUBLIC)
1969: SPL_ME(SplFileInfo, getPathInfo, arginfo_info_optinalFileClass, ZEND_ACC_PUBLIC)
1970: SPL_ME(SplFileInfo, openFile, arginfo_info_openFile, ZEND_ACC_PUBLIC)
1971: SPL_ME(SplFileInfo, setFileClass, arginfo_info_optinalFileClass, ZEND_ACC_PUBLIC)
1972: SPL_ME(SplFileInfo, setInfoClass, arginfo_info_optinalFileClass, ZEND_ACC_PUBLIC)
1973: SPL_ME(SplFileInfo, _bad_state_ex, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
1974: SPL_MA(SplFileInfo, __toString, SplFileInfo, getPathname, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1975: PHP_FE_END
1976: };
1977:
1978: ZEND_BEGIN_ARG_INFO(arginfo_dir___construct, 0)
1979: ZEND_ARG_INFO(0, path)
1980: ZEND_END_ARG_INFO()
1981:
1982: ZEND_BEGIN_ARG_INFO(arginfo_dir_it_seek, 0)
1983: ZEND_ARG_INFO(0, position)
1984: ZEND_END_ARG_INFO();
1985:
1986: /* the method table */
1987: /* each method can have its own parameters and visibility */
1988: static const zend_function_entry spl_DirectoryIterator_functions[] = {
1989: SPL_ME(DirectoryIterator, __construct, arginfo_dir___construct, ZEND_ACC_PUBLIC)
1990: SPL_ME(DirectoryIterator, getFilename, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1991: SPL_ME(DirectoryIterator, getExtension, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1992: SPL_ME(DirectoryIterator, getBasename, arginfo_optinalSuffix, ZEND_ACC_PUBLIC)
1993: SPL_ME(DirectoryIterator, isDot, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1994: SPL_ME(DirectoryIterator, rewind, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1995: SPL_ME(DirectoryIterator, valid, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1996: SPL_ME(DirectoryIterator, key, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1997: SPL_ME(DirectoryIterator, current, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1998: SPL_ME(DirectoryIterator, next, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
1999: SPL_ME(DirectoryIterator, seek, arginfo_dir_it_seek, ZEND_ACC_PUBLIC)
2000: SPL_MA(DirectoryIterator, __toString, DirectoryIterator, getFilename, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2001: PHP_FE_END
2002: };
2003:
2004: ZEND_BEGIN_ARG_INFO_EX(arginfo_r_dir___construct, 0, 0, 1)
2005: ZEND_ARG_INFO(0, path)
2006: ZEND_ARG_INFO(0, flags)
2007: ZEND_END_ARG_INFO()
2008:
2009: ZEND_BEGIN_ARG_INFO_EX(arginfo_r_dir_hasChildren, 0, 0, 0)
2010: ZEND_ARG_INFO(0, allow_links)
2011: ZEND_END_ARG_INFO()
2012:
2013: ZEND_BEGIN_ARG_INFO_EX(arginfo_r_dir_setFlags, 0, 0, 0)
2014: ZEND_ARG_INFO(0, flags)
2015: ZEND_END_ARG_INFO()
2016:
2017: static const zend_function_entry spl_FilesystemIterator_functions[] = {
2018: SPL_ME(FilesystemIterator, __construct, arginfo_r_dir___construct, ZEND_ACC_PUBLIC)
2019: SPL_ME(FilesystemIterator, rewind, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2020: SPL_ME(DirectoryIterator, next, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2021: SPL_ME(FilesystemIterator, key, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2022: SPL_ME(FilesystemIterator, current, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2023: SPL_ME(FilesystemIterator, getFlags, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2024: SPL_ME(FilesystemIterator, setFlags, arginfo_r_dir_setFlags, ZEND_ACC_PUBLIC)
2025: PHP_FE_END
2026: };
2027:
2028: static const zend_function_entry spl_RecursiveDirectoryIterator_functions[] = {
2029: SPL_ME(RecursiveDirectoryIterator, __construct, arginfo_r_dir___construct, ZEND_ACC_PUBLIC)
2030: SPL_ME(RecursiveDirectoryIterator, hasChildren, arginfo_r_dir_hasChildren, ZEND_ACC_PUBLIC)
2031: SPL_ME(RecursiveDirectoryIterator, getChildren, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2032: SPL_ME(RecursiveDirectoryIterator, getSubPath, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2033: SPL_ME(RecursiveDirectoryIterator, getSubPathname,arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2034: PHP_FE_END
2035: };
2036:
2037: #ifdef HAVE_GLOB
2038: static const zend_function_entry spl_GlobIterator_functions[] = {
2039: SPL_ME(GlobIterator, __construct, arginfo_r_dir___construct, ZEND_ACC_PUBLIC)
2040: SPL_ME(GlobIterator, count, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2041: PHP_FE_END
2042: };
2043: #endif
2044: /* }}} */
2045:
2046: static int spl_filesystem_file_read(spl_filesystem_object *intern, int silent TSRMLS_DC) /* {{{ */
2047: {
2048: char *buf;
2049: size_t line_len = 0;
2050: long line_add = (intern->u.file.current_line || intern->u.file.current_zval) ? 1 : 0;
2051:
2052: spl_filesystem_file_free_line(intern TSRMLS_CC);
2053:
2054: if (php_stream_eof(intern->u.file.stream)) {
2055: if (!silent) {
2056: zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Cannot read from file %s", intern->file_name);
2057: }
2058: return FAILURE;
2059: }
2060:
2061: if (intern->u.file.max_line_len > 0) {
2062: buf = safe_emalloc((intern->u.file.max_line_len + 1), sizeof(char), 0);
2063: if (php_stream_get_line(intern->u.file.stream, buf, intern->u.file.max_line_len, &line_len) == NULL) {
2064: efree(buf);
2065: buf = NULL;
2066: } else {
2067: buf[line_len] = '\0';
2068: }
2069: } else {
2070: buf = php_stream_get_line(intern->u.file.stream, NULL, 0, &line_len);
2071: }
2072:
2073: if (!buf) {
2074: intern->u.file.current_line = estrdup("");
2075: intern->u.file.current_line_len = 0;
2076: } else {
2077: if (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_DROP_NEW_LINE)) {
2078: line_len = strcspn(buf, "\r\n");
2079: buf[line_len] = '\0';
2080: }
2081:
2082: intern->u.file.current_line = buf;
2083: intern->u.file.current_line_len = line_len;
2084: }
2085: intern->u.file.current_line_num += line_add;
2086:
2087: return SUCCESS;
2088: } /* }}} */
2089:
2090: static int spl_filesystem_file_call(spl_filesystem_object *intern, zend_function *func_ptr, int pass_num_args, zval *return_value, zval *arg2 TSRMLS_DC) /* {{{ */
2091: {
2092: zend_fcall_info fci;
2093: zend_fcall_info_cache fcic;
2094: zval z_fname;
2095: zval * zresource_ptr = &intern->u.file.zresource, *retval;
2096: int result;
2097: int num_args = pass_num_args + (arg2 ? 2 : 1);
2098:
2099: zval ***params = (zval***)safe_emalloc(num_args, sizeof(zval**), 0);
2100:
2101: params[0] = &zresource_ptr;
2102:
2103: if (arg2) {
2104: params[1] = &arg2;
2105: }
2106:
2107: zend_get_parameters_array_ex(pass_num_args, params+(arg2 ? 2 : 1));
2108:
2109: ZVAL_STRING(&z_fname, func_ptr->common.function_name, 0);
2110:
2111: fci.size = sizeof(fci);
2112: fci.function_table = EG(function_table);
2113: fci.object_ptr = NULL;
2114: fci.function_name = &z_fname;
2115: fci.retval_ptr_ptr = &retval;
2116: fci.param_count = num_args;
2117: fci.params = params;
2118: fci.no_separation = 1;
2119: fci.symbol_table = NULL;
2120:
2121: fcic.initialized = 1;
2122: fcic.function_handler = func_ptr;
2123: fcic.calling_scope = NULL;
2124: fcic.called_scope = NULL;
2125: fcic.object_ptr = NULL;
2126:
2127: result = zend_call_function(&fci, &fcic TSRMLS_CC);
2128:
2129: if (result == FAILURE) {
2130: RETVAL_FALSE;
2131: } else {
2132: ZVAL_ZVAL(return_value, retval, 1, 1);
2133: }
2134:
2135: efree(params);
2136: return result;
2137: } /* }}} */
2138:
2139: #define FileFunctionCall(func_name, pass_num_args, arg2) /* {{{ */ \
2140: { \
2141: zend_function *func_ptr; \
2142: int ret; \
2143: ret = zend_hash_find(EG(function_table), #func_name, sizeof(#func_name), (void **) &func_ptr); \
2144: if (ret != SUCCESS) { \
2145: zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Internal error, function '%s' not found. Please report", #func_name); \
2146: return; \
2147: } \
2148: spl_filesystem_file_call(intern, func_ptr, pass_num_args, return_value, arg2 TSRMLS_CC); \
2149: } /* }}} */
2150:
2151: static int spl_filesystem_file_read_csv(spl_filesystem_object *intern, char delimiter, char enclosure, char escape, zval *return_value TSRMLS_DC) /* {{{ */
2152: {
2153: int ret = SUCCESS;
2154:
2155: do {
2156: ret = spl_filesystem_file_read(intern, 1 TSRMLS_CC);
2157: } while (ret == SUCCESS && !intern->u.file.current_line_len && SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_SKIP_EMPTY));
2158:
2159: if (ret == SUCCESS) {
2160: size_t buf_len = intern->u.file.current_line_len;
2161: char *buf = estrndup(intern->u.file.current_line, buf_len);
2162:
2163: if (intern->u.file.current_zval) {
2164: zval_ptr_dtor(&intern->u.file.current_zval);
2165: }
2166: ALLOC_INIT_ZVAL(intern->u.file.current_zval);
2167:
2168: php_fgetcsv(intern->u.file.stream, delimiter, enclosure, escape, buf_len, buf, intern->u.file.current_zval TSRMLS_CC);
2169: if (return_value) {
2170: if (Z_TYPE_P(return_value) != IS_NULL) {
2171: zval_dtor(return_value);
2172: ZVAL_NULL(return_value);
2173: }
2174: ZVAL_ZVAL(return_value, intern->u.file.current_zval, 1, 0);
2175: }
2176: }
2177: return ret;
2178: }
2179: /* }}} */
2180:
2181: static int spl_filesystem_file_read_line_ex(zval * this_ptr, spl_filesystem_object *intern, int silent TSRMLS_DC) /* {{{ */
2182: {
2183: zval *retval = NULL;
2184:
2185: /* 1) use fgetcsv? 2) overloaded call the function, 3) do it directly */
2186: if (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_CSV) || intern->u.file.func_getCurr->common.scope != spl_ce_SplFileObject) {
2187: if (php_stream_eof(intern->u.file.stream)) {
2188: if (!silent) {
2189: zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Cannot read from file %s", intern->file_name);
2190: }
2191: return FAILURE;
2192: }
2193: if (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_CSV)) {
2194: return spl_filesystem_file_read_csv(intern, intern->u.file.delimiter, intern->u.file.enclosure, intern->u.file.escape, NULL TSRMLS_CC);
2195: } else {
2196: zend_call_method_with_0_params(&this_ptr, Z_OBJCE_P(getThis()), &intern->u.file.func_getCurr, "getCurrentLine", &retval);
2197: }
2198: if (retval) {
2199: if (intern->u.file.current_line || intern->u.file.current_zval) {
2200: intern->u.file.current_line_num++;
2201: }
2202: spl_filesystem_file_free_line(intern TSRMLS_CC);
2203: if (Z_TYPE_P(retval) == IS_STRING) {
2204: intern->u.file.current_line = estrndup(Z_STRVAL_P(retval), Z_STRLEN_P(retval));
2205: intern->u.file.current_line_len = Z_STRLEN_P(retval);
2206: } else {
2207: MAKE_STD_ZVAL(intern->u.file.current_zval);
2208: ZVAL_ZVAL(intern->u.file.current_zval, retval, 1, 0);
2209: }
2210: zval_ptr_dtor(&retval);
2211: return SUCCESS;
2212: } else {
2213: return FAILURE;
2214: }
2215: } else {
2216: return spl_filesystem_file_read(intern, silent TSRMLS_CC);
2217: }
2218: } /* }}} */
2219:
2220: static int spl_filesystem_file_is_empty_line(spl_filesystem_object *intern TSRMLS_DC) /* {{{ */
2221: {
2222: if (intern->u.file.current_line) {
2223: return intern->u.file.current_line_len == 0;
2224: } else if (intern->u.file.current_zval) {
2225: switch(Z_TYPE_P(intern->u.file.current_zval)) {
2226: case IS_STRING:
2227: return Z_STRLEN_P(intern->u.file.current_zval) == 0;
2228: case IS_ARRAY:
2229: if (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_CSV)
2230: && zend_hash_num_elements(Z_ARRVAL_P(intern->u.file.current_zval)) == 1) {
2231: zval ** first = Z_ARRVAL_P(intern->u.file.current_zval)->pListHead->pData;
2232:
2233: return Z_TYPE_PP(first) == IS_STRING && Z_STRLEN_PP(first) == 0;
2234: }
2235: return zend_hash_num_elements(Z_ARRVAL_P(intern->u.file.current_zval)) == 0;
2236: case IS_NULL:
2237: return 1;
2238: default:
2239: return 0;
2240: }
2241: } else {
2242: return 1;
2243: }
2244: }
2245: /* }}} */
2246:
2247: static int spl_filesystem_file_read_line(zval * this_ptr, spl_filesystem_object *intern, int silent TSRMLS_DC) /* {{{ */
2248: {
2249: int ret = spl_filesystem_file_read_line_ex(this_ptr, intern, silent TSRMLS_CC);
2250:
2251: while (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_SKIP_EMPTY) && ret == SUCCESS && spl_filesystem_file_is_empty_line(intern TSRMLS_CC)) {
2252: spl_filesystem_file_free_line(intern TSRMLS_CC);
2253: ret = spl_filesystem_file_read_line_ex(this_ptr, intern, silent TSRMLS_CC);
2254: }
2255:
2256: return ret;
2257: }
2258: /* }}} */
2259:
2260: static void spl_filesystem_file_rewind(zval * this_ptr, spl_filesystem_object *intern TSRMLS_DC) /* {{{ */
2261: {
2262: if (-1 == php_stream_rewind(intern->u.file.stream)) {
2263: zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Cannot rewind file %s", intern->file_name);
2264: } else {
2265: spl_filesystem_file_free_line(intern TSRMLS_CC);
2266: intern->u.file.current_line_num = 0;
2267: }
2268: if (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_AHEAD)) {
2269: spl_filesystem_file_read_line(this_ptr, intern, 1 TSRMLS_CC);
2270: }
2271: } /* }}} */
2272:
2273: /* {{{ proto void SplFileObject::__construct(string filename [, string mode = 'r' [, bool use_include_path [, resource context]]]])
2274: Construct a new file object */
2275: SPL_METHOD(SplFileObject, __construct)
2276: {
2277: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
2278: zend_bool use_include_path = 0;
2279: char *p1, *p2;
2280: char *tmp_path;
2281: int tmp_path_len;
2282: zend_error_handling error_handling;
2283:
2284: zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling TSRMLS_CC);
2285:
2286: intern->u.file.open_mode = NULL;
2287: intern->u.file.open_mode_len = 0;
2288:
1.1.1.2 misho 2289: if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|sbr",
1.1 misho 2290: &intern->file_name, &intern->file_name_len,
2291: &intern->u.file.open_mode, &intern->u.file.open_mode_len,
2292: &use_include_path, &intern->u.file.zcontext) == FAILURE) {
2293: intern->u.file.open_mode = NULL;
2294: intern->file_name = NULL;
2295: zend_restore_error_handling(&error_handling TSRMLS_CC);
2296: return;
2297: }
2298:
2299: if (intern->u.file.open_mode == NULL) {
2300: intern->u.file.open_mode = "r";
2301: intern->u.file.open_mode_len = 1;
2302: }
1.1.1.2 misho 2303:
1.1 misho 2304: if (spl_filesystem_file_open(intern, use_include_path, 0 TSRMLS_CC) == SUCCESS) {
2305: tmp_path_len = strlen(intern->u.file.stream->orig_path);
2306:
2307: if (tmp_path_len > 1 && IS_SLASH_AT(intern->u.file.stream->orig_path, tmp_path_len-1)) {
2308: tmp_path_len--;
2309: }
2310:
2311: tmp_path = estrndup(intern->u.file.stream->orig_path, tmp_path_len);
2312:
2313: p1 = strrchr(tmp_path, '/');
2314: #if defined(PHP_WIN32) || defined(NETWARE)
2315: p2 = strrchr(tmp_path, '\\');
2316: #else
2317: p2 = 0;
2318: #endif
2319: if (p1 || p2) {
2320: intern->_path_len = (p1 > p2 ? p1 : p2) - tmp_path;
2321: } else {
2322: intern->_path_len = 0;
2323: }
2324:
2325: efree(tmp_path);
2326:
2327: intern->_path = estrndup(intern->u.file.stream->orig_path, intern->_path_len);
2328: }
2329:
2330: zend_restore_error_handling(&error_handling TSRMLS_CC);
2331:
2332: } /* }}} */
2333:
2334: /* {{{ proto void SplTempFileObject::__construct([int max_memory])
2335: Construct a new temp file object */
2336: SPL_METHOD(SplTempFileObject, __construct)
2337: {
2338: long max_memory = PHP_STREAM_MAX_MEM;
2339: char tmp_fname[48];
2340: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
2341: zend_error_handling error_handling;
2342:
2343: zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling TSRMLS_CC);
2344:
2345: if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &max_memory) == FAILURE) {
2346: zend_restore_error_handling(&error_handling TSRMLS_CC);
2347: return;
2348: }
2349:
2350: if (max_memory < 0) {
2351: intern->file_name = "php://memory";
2352: intern->file_name_len = 12;
2353: } else if (ZEND_NUM_ARGS()) {
2354: intern->file_name_len = slprintf(tmp_fname, sizeof(tmp_fname), "php://temp/maxmemory:%ld", max_memory);
2355: intern->file_name = tmp_fname;
2356: } else {
2357: intern->file_name = "php://temp";
2358: intern->file_name_len = 10;
2359: }
2360: intern->u.file.open_mode = "wb";
2361: intern->u.file.open_mode_len = 1;
2362: intern->u.file.zcontext = NULL;
2363:
2364: if (spl_filesystem_file_open(intern, 0, 0 TSRMLS_CC) == SUCCESS) {
2365: intern->_path_len = 0;
2366: intern->_path = estrndup("", 0);
2367: }
2368: zend_restore_error_handling(&error_handling TSRMLS_CC);
2369: } /* }}} */
2370:
2371: /* {{{ proto void SplFileObject::rewind()
2372: Rewind the file and read the first line */
2373: SPL_METHOD(SplFileObject, rewind)
2374: {
2375: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
2376:
2377: if (zend_parse_parameters_none() == FAILURE) {
2378: return;
2379: }
2380:
2381: spl_filesystem_file_rewind(getThis(), intern TSRMLS_CC);
2382: } /* }}} */
2383:
2384: /* {{{ proto void SplFileObject::eof()
2385: Return whether end of file is reached */
2386: SPL_METHOD(SplFileObject, eof)
2387: {
2388: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
2389:
2390: if (zend_parse_parameters_none() == FAILURE) {
2391: return;
2392: }
2393:
2394: RETURN_BOOL(php_stream_eof(intern->u.file.stream));
2395: } /* }}} */
2396:
2397: /* {{{ proto void SplFileObject::valid()
2398: Return !eof() */
2399: SPL_METHOD(SplFileObject, valid)
2400: {
2401: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
2402:
2403: if (zend_parse_parameters_none() == FAILURE) {
2404: return;
2405: }
2406:
2407: if (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_AHEAD)) {
2408: RETURN_BOOL(intern->u.file.current_line || intern->u.file.current_zval);
2409: } else {
2410: RETVAL_BOOL(!php_stream_eof(intern->u.file.stream));
2411: }
2412: } /* }}} */
2413:
2414: /* {{{ proto string SplFileObject::fgets()
2415: Rturn next line from file */
2416: SPL_METHOD(SplFileObject, fgets)
2417: {
2418: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
2419:
2420: if (zend_parse_parameters_none() == FAILURE) {
2421: return;
2422: }
2423:
2424: if (spl_filesystem_file_read(intern, 0 TSRMLS_CC) == FAILURE) {
2425: RETURN_FALSE;
2426: }
2427: RETURN_STRINGL(intern->u.file.current_line, intern->u.file.current_line_len, 1);
2428: } /* }}} */
2429:
2430: /* {{{ proto string SplFileObject::current()
2431: Return current line from file */
2432: SPL_METHOD(SplFileObject, current)
2433: {
2434: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
2435:
2436: if (zend_parse_parameters_none() == FAILURE) {
2437: return;
2438: }
2439:
2440: if (!intern->u.file.current_line && !intern->u.file.current_zval) {
2441: spl_filesystem_file_read_line(getThis(), intern, 1 TSRMLS_CC);
2442: }
2443: if (intern->u.file.current_line && (!SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_CSV) || !intern->u.file.current_zval)) {
2444: RETURN_STRINGL(intern->u.file.current_line, intern->u.file.current_line_len, 1);
2445: } else if (intern->u.file.current_zval) {
2446: RETURN_ZVAL(intern->u.file.current_zval, 1, 0);
2447: }
2448: RETURN_FALSE;
2449: } /* }}} */
2450:
2451: /* {{{ proto int SplFileObject::key()
2452: Return line number */
2453: SPL_METHOD(SplFileObject, key)
2454: {
2455: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
2456:
2457: if (zend_parse_parameters_none() == FAILURE) {
2458: return;
2459: }
2460:
2461: /* Do not read the next line to support correct counting with fgetc()
2462: if (!intern->current_line) {
2463: spl_filesystem_file_read_line(getThis(), intern, 1 TSRMLS_CC);
2464: } */
2465: RETURN_LONG(intern->u.file.current_line_num);
2466: } /* }}} */
2467:
2468: /* {{{ proto void SplFileObject::next()
2469: Read next line */
2470: SPL_METHOD(SplFileObject, next)
2471: {
2472: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
2473:
2474: if (zend_parse_parameters_none() == FAILURE) {
2475: return;
2476: }
2477:
2478: spl_filesystem_file_free_line(intern TSRMLS_CC);
2479: if (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_AHEAD)) {
2480: spl_filesystem_file_read_line(getThis(), intern, 1 TSRMLS_CC);
2481: }
2482: intern->u.file.current_line_num++;
2483: } /* }}} */
2484:
2485: /* {{{ proto void SplFileObject::setFlags(int flags)
2486: Set file handling flags */
2487: SPL_METHOD(SplFileObject, setFlags)
2488: {
2489: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
2490:
1.1.1.2 misho 2491: if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &intern->flags) == FAILURE) {
2492: return;
2493: }
1.1 misho 2494: } /* }}} */
2495:
2496: /* {{{ proto int SplFileObject::getFlags()
2497: Get file handling flags */
2498: SPL_METHOD(SplFileObject, getFlags)
2499: {
2500: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
2501:
2502: if (zend_parse_parameters_none() == FAILURE) {
2503: return;
2504: }
2505:
2506: RETURN_LONG(intern->flags & SPL_FILE_OBJECT_MASK);
2507: } /* }}} */
2508:
2509: /* {{{ proto void SplFileObject::setMaxLineLen(int max_len)
2510: Set maximum line length */
2511: SPL_METHOD(SplFileObject, setMaxLineLen)
2512: {
2513: long max_len;
2514:
2515: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
2516:
2517: if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &max_len) == FAILURE) {
2518: return;
2519: }
2520:
2521: if (max_len < 0) {
2522: zend_throw_exception_ex(spl_ce_DomainException, 0 TSRMLS_CC, "Maximum line length must be greater than or equal zero");
2523: return;
2524: }
2525:
2526: intern->u.file.max_line_len = max_len;
2527: } /* }}} */
2528:
2529: /* {{{ proto int SplFileObject::getMaxLineLen()
2530: Get maximum line length */
2531: SPL_METHOD(SplFileObject, getMaxLineLen)
2532: {
2533: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
2534:
2535: if (zend_parse_parameters_none() == FAILURE) {
2536: return;
2537: }
2538:
2539: RETURN_LONG((long)intern->u.file.max_line_len);
2540: } /* }}} */
2541:
2542: /* {{{ proto bool SplFileObject::hasChildren()
2543: Return false */
2544: SPL_METHOD(SplFileObject, hasChildren)
2545: {
2546: if (zend_parse_parameters_none() == FAILURE) {
2547: return;
2548: }
2549:
2550: RETURN_FALSE;
2551: } /* }}} */
2552:
2553: /* {{{ proto bool SplFileObject::getChildren()
2554: Read NULL */
2555: SPL_METHOD(SplFileObject, getChildren)
2556: {
2557: if (zend_parse_parameters_none() == FAILURE) {
2558: return;
2559: }
2560: /* return NULL */
2561: } /* }}} */
2562:
2563: /* {{{ FileFunction */
2564: #define FileFunction(func_name) \
2565: SPL_METHOD(SplFileObject, func_name) \
2566: { \
2567: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); \
2568: FileFunctionCall(func_name, ZEND_NUM_ARGS(), NULL); \
2569: }
2570: /* }}} */
2571:
2572: /* {{{ proto array SplFileObject::fgetcsv([string delimiter [, string enclosure [, escape = '\\']]])
2573: Return current line as csv */
2574: SPL_METHOD(SplFileObject, fgetcsv)
2575: {
2576: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
2577: char delimiter = intern->u.file.delimiter, enclosure = intern->u.file.enclosure, escape = intern->u.file.escape;
2578: char *delim = NULL, *enclo = NULL, *esc = NULL;
2579: int d_len = 0, e_len = 0, esc_len = 0;
2580:
2581: if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sss", &delim, &d_len, &enclo, &e_len, &esc, &esc_len) == SUCCESS) {
2582: switch(ZEND_NUM_ARGS())
2583: {
2584: case 3:
2585: if (esc_len != 1) {
2586: php_error_docref(NULL TSRMLS_CC, E_WARNING, "escape must be a character");
2587: RETURN_FALSE;
2588: }
2589: escape = esc[0];
2590: /* no break */
2591: case 2:
2592: if (e_len != 1) {
2593: php_error_docref(NULL TSRMLS_CC, E_WARNING, "enclosure must be a character");
2594: RETURN_FALSE;
2595: }
2596: enclosure = enclo[0];
2597: /* no break */
2598: case 1:
2599: if (d_len != 1) {
2600: php_error_docref(NULL TSRMLS_CC, E_WARNING, "delimiter must be a character");
2601: RETURN_FALSE;
2602: }
2603: delimiter = delim[0];
2604: /* no break */
2605: case 0:
2606: break;
2607: }
2608: spl_filesystem_file_read_csv(intern, delimiter, enclosure, escape, return_value TSRMLS_CC);
2609: }
2610: }
2611: /* }}} */
2612:
1.1.1.2 misho 2613: /* {{{ proto int SplFileObject::fputcsv(array fields, [string delimiter [, string enclosure]])
2614: Output a field array as a CSV line */
2615: SPL_METHOD(SplFileObject, fputcsv)
2616: {
2617: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
2618: char delimiter = intern->u.file.delimiter, enclosure = intern->u.file.enclosure, escape = intern->u.file.escape;
2619: char *delim = NULL, *enclo = NULL;
2620: int d_len = 0, e_len = 0, ret;
2621: zval *fields = NULL;
2622:
2623: if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|ss", &fields, &delim, &d_len, &enclo, &e_len) == SUCCESS) {
2624: switch(ZEND_NUM_ARGS())
2625: {
2626: case 3:
2627: if (e_len != 1) {
2628: php_error_docref(NULL TSRMLS_CC, E_WARNING, "enclosure must be a character");
2629: RETURN_FALSE;
2630: }
2631: enclosure = enclo[0];
2632: /* no break */
2633: case 2:
2634: if (d_len != 1) {
2635: php_error_docref(NULL TSRMLS_CC, E_WARNING, "delimiter must be a character");
2636: RETURN_FALSE;
2637: }
2638: delimiter = delim[0];
2639: /* no break */
2640: case 1:
2641: case 0:
2642: break;
2643: }
2644: ret = php_fputcsv(intern->u.file.stream, fields, delimiter, enclosure, escape TSRMLS_CC);
2645: RETURN_LONG(ret);
2646: }
2647: }
2648: /* }}} */
2649:
1.1 misho 2650: /* {{{ proto void SplFileObject::setCsvControl([string delimiter = ',' [, string enclosure = '"' [, string escape = '\\']]])
2651: Set the delimiter and enclosure character used in fgetcsv */
2652: SPL_METHOD(SplFileObject, setCsvControl)
2653: {
2654: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
2655: char delimiter = ',', enclosure = '"', escape='\\';
2656: char *delim = NULL, *enclo = NULL, *esc = NULL;
2657: int d_len = 0, e_len = 0, esc_len = 0;
2658:
2659: if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sss", &delim, &d_len, &enclo, &e_len, &esc, &esc_len) == SUCCESS) {
2660: switch(ZEND_NUM_ARGS())
2661: {
2662: case 3:
2663: if (esc_len != 1) {
2664: php_error_docref(NULL TSRMLS_CC, E_WARNING, "escape must be a character");
2665: RETURN_FALSE;
2666: }
2667: escape = esc[0];
2668: /* no break */
2669: case 2:
2670: if (e_len != 1) {
2671: php_error_docref(NULL TSRMLS_CC, E_WARNING, "enclosure must be a character");
2672: RETURN_FALSE;
2673: }
2674: enclosure = enclo[0];
2675: /* no break */
2676: case 1:
2677: if (d_len != 1) {
2678: php_error_docref(NULL TSRMLS_CC, E_WARNING, "delimiter must be a character");
2679: RETURN_FALSE;
2680: }
2681: delimiter = delim[0];
2682: /* no break */
2683: case 0:
2684: break;
2685: }
2686: intern->u.file.delimiter = delimiter;
2687: intern->u.file.enclosure = enclosure;
2688: intern->u.file.escape = escape;
2689: }
2690: }
2691: /* }}} */
2692:
2693: /* {{{ proto array SplFileObject::getCsvControl()
2694: Get the delimiter and enclosure character used in fgetcsv */
2695: SPL_METHOD(SplFileObject, getCsvControl)
2696: {
2697: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
2698: char delimiter[2], enclosure[2];
2699:
2700: array_init(return_value);
2701:
2702: delimiter[0] = intern->u.file.delimiter;
2703: delimiter[1] = '\0';
2704: enclosure[0] = intern->u.file.enclosure;
2705: enclosure[1] = '\0';
2706:
2707: add_next_index_string(return_value, delimiter, 1);
2708: add_next_index_string(return_value, enclosure, 1);
2709: }
2710: /* }}} */
2711:
2712: /* {{{ proto bool SplFileObject::flock(int operation [, int &wouldblock])
2713: Portable file locking */
2714: FileFunction(flock)
2715: /* }}} */
2716:
2717: /* {{{ proto bool SplFileObject::fflush()
2718: Flush the file */
2719: SPL_METHOD(SplFileObject, fflush)
2720: {
2721: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
2722:
2723: RETURN_BOOL(!php_stream_flush(intern->u.file.stream));
2724: } /* }}} */
2725:
2726: /* {{{ proto int SplFileObject::ftell()
2727: Return current file position */
2728: SPL_METHOD(SplFileObject, ftell)
2729: {
2730: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
2731: long ret = php_stream_tell(intern->u.file.stream);
2732:
2733: if (ret == -1) {
2734: RETURN_FALSE;
2735: } else {
2736: RETURN_LONG(ret);
2737: }
2738: } /* }}} */
2739:
2740: /* {{{ proto int SplFileObject::fseek(int pos [, int whence = SEEK_SET])
2741: Return current file position */
2742: SPL_METHOD(SplFileObject, fseek)
2743: {
2744: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
2745: long pos, whence = SEEK_SET;
2746:
2747: if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &pos, &whence) == FAILURE) {
2748: return;
2749: }
2750:
2751: spl_filesystem_file_free_line(intern TSRMLS_CC);
2752: RETURN_LONG(php_stream_seek(intern->u.file.stream, pos, whence));
2753: } /* }}} */
2754:
2755: /* {{{ proto int SplFileObject::fgetc()
2756: Get a character form the file */
2757: SPL_METHOD(SplFileObject, fgetc)
2758: {
2759: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
2760: char buf[2];
2761: int result;
2762:
2763: spl_filesystem_file_free_line(intern TSRMLS_CC);
2764:
2765: result = php_stream_getc(intern->u.file.stream);
2766:
2767: if (result == EOF) {
2768: RETVAL_FALSE;
2769: } else {
2770: if (result == '\n') {
2771: intern->u.file.current_line_num++;
2772: }
2773: buf[0] = result;
2774: buf[1] = '\0';
2775:
2776: RETURN_STRINGL(buf, 1, 1);
2777: }
2778: } /* }}} */
2779:
2780: /* {{{ proto string SplFileObject::fgetss([string allowable_tags])
2781: Get a line from file pointer and strip HTML tags */
2782: SPL_METHOD(SplFileObject, fgetss)
2783: {
2784: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
2785: zval *arg2 = NULL;
2786: MAKE_STD_ZVAL(arg2);
2787:
2788: if (intern->u.file.max_line_len > 0) {
2789: ZVAL_LONG(arg2, intern->u.file.max_line_len);
2790: } else {
2791: ZVAL_LONG(arg2, 1024);
2792: }
2793:
2794: spl_filesystem_file_free_line(intern TSRMLS_CC);
2795: intern->u.file.current_line_num++;
2796:
2797: FileFunctionCall(fgetss, ZEND_NUM_ARGS(), arg2);
2798:
2799: zval_ptr_dtor(&arg2);
2800: } /* }}} */
2801:
2802: /* {{{ proto int SplFileObject::fpassthru()
2803: Output all remaining data from a file pointer */
2804: SPL_METHOD(SplFileObject, fpassthru)
2805: {
2806: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
2807:
2808: RETURN_LONG(php_stream_passthru(intern->u.file.stream));
2809: } /* }}} */
2810:
2811: /* {{{ proto bool SplFileObject::fscanf(string format [, string ...])
2812: Implements a mostly ANSI compatible fscanf() */
2813: SPL_METHOD(SplFileObject, fscanf)
2814: {
2815: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
2816:
2817: spl_filesystem_file_free_line(intern TSRMLS_CC);
2818: intern->u.file.current_line_num++;
2819:
2820: FileFunctionCall(fscanf, ZEND_NUM_ARGS(), NULL);
2821: }
2822: /* }}} */
2823:
2824: /* {{{ proto mixed SplFileObject::fwrite(string str [, int length])
2825: Binary-safe file write */
2826: SPL_METHOD(SplFileObject, fwrite)
2827: {
2828: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
2829: char *str;
2830: int str_len;
2831: long length = 0;
2832:
2833: if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &str_len, &length) == FAILURE) {
2834: return;
2835: }
2836:
2837: if (ZEND_NUM_ARGS() > 1) {
2838: str_len = MAX(0, MIN(length, str_len));
2839: }
2840: if (!str_len) {
2841: RETURN_LONG(0);
2842: }
2843:
2844: RETURN_LONG(php_stream_write(intern->u.file.stream, str, str_len));
2845: } /* }}} */
2846:
2847: /* {{{ proto bool SplFileObject::fstat()
2848: Stat() on a filehandle */
2849: FileFunction(fstat)
2850: /* }}} */
2851:
2852: /* {{{ proto bool SplFileObject::ftruncate(int size)
2853: Truncate file to 'size' length */
2854: SPL_METHOD(SplFileObject, ftruncate)
2855: {
2856: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
2857: long size;
2858:
2859: if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &size) == FAILURE) {
2860: return;
2861: }
2862:
2863: if (!php_stream_truncate_supported(intern->u.file.stream)) {
2864: zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Can't truncate file %s", intern->file_name);
2865: RETURN_FALSE;
2866: }
2867:
2868: RETURN_BOOL(0 == php_stream_truncate_set_size(intern->u.file.stream, size));
2869: } /* }}} */
2870:
2871: /* {{{ proto void SplFileObject::seek(int line_pos)
2872: Seek to specified line */
2873: SPL_METHOD(SplFileObject, seek)
2874: {
2875: spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
2876: long line_pos;
2877:
2878: if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &line_pos) == FAILURE) {
2879: return;
2880: }
2881: if (line_pos < 0) {
2882: zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Can't seek file %s to negative line %ld", intern->file_name, line_pos);
2883: RETURN_FALSE;
2884: }
2885:
2886: spl_filesystem_file_rewind(getThis(), intern TSRMLS_CC);
2887:
2888: while(intern->u.file.current_line_num < line_pos) {
2889: if (spl_filesystem_file_read_line(getThis(), intern, 1 TSRMLS_CC) == FAILURE) {
2890: break;
2891: }
2892: }
2893: } /* }}} */
2894:
2895: /* {{{ Function/Class/Method definitions */
2896: ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object___construct, 0, 0, 1)
2897: ZEND_ARG_INFO(0, file_name)
2898: ZEND_ARG_INFO(0, open_mode)
2899: ZEND_ARG_INFO(0, use_include_path)
2900: ZEND_ARG_INFO(0, context)
2901: ZEND_END_ARG_INFO()
2902:
2903: ZEND_BEGIN_ARG_INFO(arginfo_file_object_setFlags, 0)
2904: ZEND_ARG_INFO(0, flags)
2905: ZEND_END_ARG_INFO()
2906:
2907: ZEND_BEGIN_ARG_INFO(arginfo_file_object_setMaxLineLen, 0)
2908: ZEND_ARG_INFO(0, max_len)
2909: ZEND_END_ARG_INFO()
2910:
2911: ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fgetcsv, 0, 0, 0)
2912: ZEND_ARG_INFO(0, delimiter)
2913: ZEND_ARG_INFO(0, enclosure)
1.1.1.2 misho 2914: ZEND_ARG_INFO(0, escape)
2915: ZEND_END_ARG_INFO()
2916:
2917: ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fputcsv, 0, 0, 1)
2918: ZEND_ARG_INFO(0, fields)
2919: ZEND_ARG_INFO(0, delimiter)
2920: ZEND_ARG_INFO(0, enclosure)
1.1 misho 2921: ZEND_END_ARG_INFO()
2922:
2923: ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_flock, 0, 0, 1)
2924: ZEND_ARG_INFO(0, operation)
2925: ZEND_ARG_INFO(1, wouldblock)
2926: ZEND_END_ARG_INFO()
2927:
2928: ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fseek, 0, 0, 1)
2929: ZEND_ARG_INFO(0, pos)
2930: ZEND_ARG_INFO(0, whence)
2931: ZEND_END_ARG_INFO()
2932:
2933: ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fgetss, 0, 0, 0)
2934: ZEND_ARG_INFO(0, allowable_tags)
2935: ZEND_END_ARG_INFO()
2936:
1.1.1.2 misho 2937: ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fscanf, 1, 0, 1)
1.1 misho 2938: ZEND_ARG_INFO(0, format)
2939: ZEND_END_ARG_INFO()
2940:
2941: ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fwrite, 0, 0, 1)
2942: ZEND_ARG_INFO(0, str)
2943: ZEND_ARG_INFO(0, length)
2944: ZEND_END_ARG_INFO()
2945:
2946: ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_ftruncate, 0, 0, 1)
2947: ZEND_ARG_INFO(0, size)
2948: ZEND_END_ARG_INFO()
2949:
2950: ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_seek, 0, 0, 1)
2951: ZEND_ARG_INFO(0, line_pos)
2952: ZEND_END_ARG_INFO()
2953:
2954: static const zend_function_entry spl_SplFileObject_functions[] = {
2955: SPL_ME(SplFileObject, __construct, arginfo_file_object___construct, ZEND_ACC_PUBLIC)
2956: SPL_ME(SplFileObject, rewind, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2957: SPL_ME(SplFileObject, eof, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2958: SPL_ME(SplFileObject, valid, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2959: SPL_ME(SplFileObject, fgets, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2960: SPL_ME(SplFileObject, fgetcsv, arginfo_file_object_fgetcsv, ZEND_ACC_PUBLIC)
1.1.1.2 misho 2961: SPL_ME(SplFileObject, fputcsv, arginfo_file_object_fputcsv, ZEND_ACC_PUBLIC)
1.1 misho 2962: SPL_ME(SplFileObject, setCsvControl, arginfo_file_object_fgetcsv, ZEND_ACC_PUBLIC)
2963: SPL_ME(SplFileObject, getCsvControl, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2964: SPL_ME(SplFileObject, flock, arginfo_file_object_flock, ZEND_ACC_PUBLIC)
2965: SPL_ME(SplFileObject, fflush, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2966: SPL_ME(SplFileObject, ftell, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2967: SPL_ME(SplFileObject, fseek, arginfo_file_object_fseek, ZEND_ACC_PUBLIC)
2968: SPL_ME(SplFileObject, fgetc, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2969: SPL_ME(SplFileObject, fpassthru, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2970: SPL_ME(SplFileObject, fgetss, arginfo_file_object_fgetss, ZEND_ACC_PUBLIC)
2971: SPL_ME(SplFileObject, fscanf, arginfo_file_object_fscanf, ZEND_ACC_PUBLIC)
2972: SPL_ME(SplFileObject, fwrite, arginfo_file_object_fwrite, ZEND_ACC_PUBLIC)
2973: SPL_ME(SplFileObject, fstat, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2974: SPL_ME(SplFileObject, ftruncate, arginfo_file_object_ftruncate, ZEND_ACC_PUBLIC)
2975: SPL_ME(SplFileObject, current, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2976: SPL_ME(SplFileObject, key, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2977: SPL_ME(SplFileObject, next, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2978: SPL_ME(SplFileObject, setFlags, arginfo_file_object_setFlags, ZEND_ACC_PUBLIC)
2979: SPL_ME(SplFileObject, getFlags, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2980: SPL_ME(SplFileObject, setMaxLineLen, arginfo_file_object_setMaxLineLen, ZEND_ACC_PUBLIC)
2981: SPL_ME(SplFileObject, getMaxLineLen, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2982: SPL_ME(SplFileObject, hasChildren, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2983: SPL_ME(SplFileObject, getChildren, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2984: SPL_ME(SplFileObject, seek, arginfo_file_object_seek, ZEND_ACC_PUBLIC)
2985: /* mappings */
2986: SPL_MA(SplFileObject, getCurrentLine, SplFileObject, fgets, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2987: SPL_MA(SplFileObject, __toString, SplFileObject, current, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
2988: PHP_FE_END
2989: };
2990:
2991: ZEND_BEGIN_ARG_INFO_EX(arginfo_temp_file_object___construct, 0, 0, 0)
2992: ZEND_ARG_INFO(0, max_memory)
2993: ZEND_END_ARG_INFO()
2994:
2995: static const zend_function_entry spl_SplTempFileObject_functions[] = {
2996: SPL_ME(SplTempFileObject, __construct, arginfo_temp_file_object___construct, ZEND_ACC_PUBLIC)
2997: PHP_FE_END
2998: };
2999: /* }}} */
3000:
3001: /* {{{ PHP_MINIT_FUNCTION(spl_directory)
3002: */
3003: PHP_MINIT_FUNCTION(spl_directory)
3004: {
3005: REGISTER_SPL_STD_CLASS_EX(SplFileInfo, spl_filesystem_object_new, spl_SplFileInfo_functions);
3006: memcpy(&spl_filesystem_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
3007: spl_filesystem_object_handlers.clone_obj = spl_filesystem_object_clone;
3008: spl_filesystem_object_handlers.cast_object = spl_filesystem_object_cast;
3009: spl_filesystem_object_handlers.get_debug_info = spl_filesystem_object_get_debug_info;
3010: spl_ce_SplFileInfo->serialize = zend_class_serialize_deny;
3011: spl_ce_SplFileInfo->unserialize = zend_class_unserialize_deny;
3012:
3013: REGISTER_SPL_SUB_CLASS_EX(DirectoryIterator, SplFileInfo, spl_filesystem_object_new, spl_DirectoryIterator_functions);
3014: zend_class_implements(spl_ce_DirectoryIterator TSRMLS_CC, 1, zend_ce_iterator);
3015: REGISTER_SPL_IMPLEMENTS(DirectoryIterator, SeekableIterator);
3016:
3017: spl_ce_DirectoryIterator->get_iterator = spl_filesystem_dir_get_iterator;
3018:
3019: REGISTER_SPL_SUB_CLASS_EX(FilesystemIterator, DirectoryIterator, spl_filesystem_object_new, spl_FilesystemIterator_functions);
3020:
3021: REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, "CURRENT_MODE_MASK", SPL_FILE_DIR_CURRENT_MODE_MASK);
3022: REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, "CURRENT_AS_PATHNAME", SPL_FILE_DIR_CURRENT_AS_PATHNAME);
3023: REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, "CURRENT_AS_FILEINFO", SPL_FILE_DIR_CURRENT_AS_FILEINFO);
3024: REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, "CURRENT_AS_SELF", SPL_FILE_DIR_CURRENT_AS_SELF);
3025: REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, "KEY_MODE_MASK", SPL_FILE_DIR_KEY_MODE_MASK);
3026: REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, "KEY_AS_PATHNAME", SPL_FILE_DIR_KEY_AS_PATHNAME);
3027: REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, "FOLLOW_SYMLINKS", SPL_FILE_DIR_FOLLOW_SYMLINKS);
3028: REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, "KEY_AS_FILENAME", SPL_FILE_DIR_KEY_AS_FILENAME);
3029: REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, "NEW_CURRENT_AND_KEY", SPL_FILE_DIR_KEY_AS_FILENAME|SPL_FILE_DIR_CURRENT_AS_FILEINFO);
1.1.1.2 misho 3030: REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, "OTHER_MODE_MASK", SPL_FILE_DIR_OTHERS_MASK);
1.1 misho 3031: REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, "SKIP_DOTS", SPL_FILE_DIR_SKIPDOTS);
3032: REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, "UNIX_PATHS", SPL_FILE_DIR_UNIXPATHS);
3033:
3034: spl_ce_FilesystemIterator->get_iterator = spl_filesystem_tree_get_iterator;
3035:
3036: REGISTER_SPL_SUB_CLASS_EX(RecursiveDirectoryIterator, FilesystemIterator, spl_filesystem_object_new, spl_RecursiveDirectoryIterator_functions);
3037: REGISTER_SPL_IMPLEMENTS(RecursiveDirectoryIterator, RecursiveIterator);
3038:
3039: memcpy(&spl_filesystem_object_check_handlers, &spl_filesystem_object_handlers, sizeof(zend_object_handlers));
3040: spl_filesystem_object_check_handlers.get_method = spl_filesystem_object_get_method_check;
3041:
3042: #ifdef HAVE_GLOB
3043: REGISTER_SPL_SUB_CLASS_EX(GlobIterator, FilesystemIterator, spl_filesystem_object_new_check, spl_GlobIterator_functions);
3044: REGISTER_SPL_IMPLEMENTS(GlobIterator, Countable);
3045: #endif
3046:
3047: REGISTER_SPL_SUB_CLASS_EX(SplFileObject, SplFileInfo, spl_filesystem_object_new_check, spl_SplFileObject_functions);
3048: REGISTER_SPL_IMPLEMENTS(SplFileObject, RecursiveIterator);
3049: REGISTER_SPL_IMPLEMENTS(SplFileObject, SeekableIterator);
3050:
3051: REGISTER_SPL_CLASS_CONST_LONG(SplFileObject, "DROP_NEW_LINE", SPL_FILE_OBJECT_DROP_NEW_LINE);
3052: REGISTER_SPL_CLASS_CONST_LONG(SplFileObject, "READ_AHEAD", SPL_FILE_OBJECT_READ_AHEAD);
3053: REGISTER_SPL_CLASS_CONST_LONG(SplFileObject, "SKIP_EMPTY", SPL_FILE_OBJECT_SKIP_EMPTY);
3054: REGISTER_SPL_CLASS_CONST_LONG(SplFileObject, "READ_CSV", SPL_FILE_OBJECT_READ_CSV);
3055:
3056: REGISTER_SPL_SUB_CLASS_EX(SplTempFileObject, SplFileObject, spl_filesystem_object_new_check, spl_SplTempFileObject_functions);
3057: return SUCCESS;
3058: }
3059: /* }}} */
3060:
3061: /*
3062: * Local variables:
3063: * tab-width: 4
3064: * c-basic-offset: 4
3065: * End:
3066: * vim600: noet sw=4 ts=4 fdm=marker
3067: * vim<600: noet sw=4 ts=4
3068: */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>