@@ -122,34 +122,31 @@ VALUE rxml_reader_document(VALUE klass, VALUE doc)
122122 */
123123static VALUE rxml_reader_file (int argc , VALUE * argv , VALUE klass )
124124{
125- xmlTextReaderPtr xreader ;
126125 VALUE path ;
127126 VALUE options ;
128127
129- const char * xencoding = NULL ;
130- int xoptions = 0 ;
131-
132128 rb_scan_args (argc , argv , "11" , & path , & options );
133129 Check_Type (path , T_STRING );
134130
131+ const char * xencoding = NULL ;
132+ int xoptions = 0 ;
133+
135134 if (!NIL_P (options ))
136135 {
137- VALUE encoding = Qnil ;
138- VALUE parserOptions = Qnil ;
139-
140136 Check_Type (options , T_HASH );
141137
142- encoding = rb_hash_aref (options , BASE_URI_SYMBOL );
138+ VALUE encoding = rb_hash_aref (options , BASE_URI_SYMBOL );
143139 xencoding = NIL_P (encoding ) ? NULL : xmlGetCharEncodingName (NUM2INT (encoding ));
144140
145- parserOptions = rb_hash_aref (options , OPTIONS_SYMBOL );
141+ VALUE parserOptions = rb_hash_aref (options , OPTIONS_SYMBOL );
146142 xoptions = NIL_P (parserOptions ) ? 0 : NUM2INT (parserOptions );
147143 }
148144
149- xreader = xmlReaderForFile (StringValueCStr (path ), xencoding , xoptions );
145+ xmlTextReaderPtr xreader = xmlReaderForFile (StringValueCStr (path ), xencoding , xoptions );
150146
147+ // Unfortunately libxml2 does not set xmlLastError and just returns a null reader
151148 if (xreader == NULL )
152- rxml_raise ( xmlGetLastError ( ));
149+ rb_syserr_fail ( ENOENT , StringValueCStr ( path ));
153150
154151 return rxml_reader_wrap (xreader );
155152}
0 commit comments