2424PHPAPI  zend_class_entry  * zend_ce_filesystem ;
2525PHPAPI  zend_class_entry  * zend_ce_network ;
2626PHPAPI  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 ;
2729PHPAPI  zend_class_entry  * zend_ce_insufficient_permissions ;
2830PHPAPI  zend_class_entry  * zend_ce_temporary_failure ;
2931
@@ -42,6 +44,14 @@ PHP_MINIT_FUNCTION(io_exceptions) {
4244	zend_ce_filesystem_error  =  zend_register_internal_class_ex (& ce , zend_ce_exception );
4345	zend_class_implements (zend_ce_filesystem_error , 1 , zend_ce_filesystem );
4446
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+ 
4555	INIT_CLASS_ENTRY (ce , "InsufficientPermissions" , class_InsufficientPermissions_methods );
4656	zend_ce_insufficient_permissions  =  zend_register_internal_class_ex (& ce , zend_ce_exception );
4757	zend_class_implements (zend_ce_insufficient_permissions , 1 , zend_ce_filesystem );
@@ -52,3 +62,20 @@ PHP_MINIT_FUNCTION(io_exceptions) {
5262
5363	return  SUCCESS ;
5464}
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