24
24
PHPAPI zend_class_entry * zend_ce_filesystem ;
25
25
PHPAPI zend_class_entry * zend_ce_network ;
26
26
PHPAPI zend_class_entry * zend_ce_filesystem_error ;
27
+ PHPAPI zend_class_entry * zend_ce_file_not_found ;
28
+ PHPAPI zend_class_entry * zend_ce_not_directory ;
27
29
PHPAPI zend_class_entry * zend_ce_insufficient_permissions ;
28
30
PHPAPI zend_class_entry * zend_ce_temporary_failure ;
29
31
@@ -42,6 +44,14 @@ PHP_MINIT_FUNCTION(io_exceptions) {
42
44
zend_ce_filesystem_error = zend_register_internal_class_ex (& ce , zend_ce_exception );
43
45
zend_class_implements (zend_ce_filesystem_error , 1 , zend_ce_filesystem );
44
46
47
+ INIT_CLASS_ENTRY (ce , "FileNotFound" , class_FileNotFound_methods );
48
+ zend_ce_file_not_found = zend_register_internal_class_ex (& ce , zend_ce_exception );
49
+ zend_class_implements (zend_ce_file_not_found , 1 , zend_ce_filesystem );
50
+
51
+ INIT_CLASS_ENTRY (ce , "NotDirectory" , class_FileNotFound_methods );
52
+ zend_ce_not_directory = zend_register_internal_class_ex (& ce , zend_ce_exception );
53
+ zend_class_implements (zend_ce_not_directory , 1 , zend_ce_filesystem );
54
+
45
55
INIT_CLASS_ENTRY (ce , "InsufficientPermissions" , class_InsufficientPermissions_methods );
46
56
zend_ce_insufficient_permissions = zend_register_internal_class_ex (& ce , zend_ce_exception );
47
57
zend_class_implements (zend_ce_insufficient_permissions , 1 , zend_ce_filesystem );
@@ -52,3 +62,20 @@ PHP_MINIT_FUNCTION(io_exceptions) {
52
62
53
63
return SUCCESS ;
54
64
}
65
+
66
+ PHPAPI void handle_io_error (int error , const char * path ) {
67
+ if (path == NULL ) {
68
+ path = "[unknown]" ;
69
+ }
70
+ switch (error ) {
71
+ case ENOENT :
72
+ php_exception_or_warning_docref (NULL , zend_ce_file_not_found , "File not found: \"%s\"" , path );
73
+ break ;
74
+ case ENOTDIR :
75
+ php_exception_or_warning_docref (NULL , zend_ce_not_directory , "\"%s\" is not a directory" , path );
76
+ break ;
77
+ default :
78
+ php_exception_or_warning_docref (NULL , zend_ce_filesystem_error , "%s (path: \"%s\", errno %d)" , strerror (errno ), path , errno );
79
+ break ;
80
+ }
81
+ }
0 commit comments