xref: /aoo4110/main/xml2cmp/source/xcd/filebuff.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "filebuff.hxx"
25 
26 #include <string.h>
27 #include <fstream>
28 #include <ctype.h>
29 
30 
31 bool
LoadXmlFile(Buffer & o_rBuffer,const char * i_sXmlFilePath)32 LoadXmlFile( Buffer & 			o_rBuffer,
33 			 const char *		i_sXmlFilePath )
34 {
35 	std::ifstream aXmlFile;
36 
37 	aXmlFile.open(i_sXmlFilePath, std::ios::in
38 #if defined(WNT) || defined(OS2)
39 										  | std::ios::binary
40 #endif // WNT
41 	);
42 
43 	if (! aXmlFile)
44 		return false;
45 
46 	// Prepare buffer:
47 	aXmlFile.seekg(0, std::ios::end);
48 	unsigned long nBufferSize = (unsigned long) aXmlFile.tellg();
49 	o_rBuffer.SetSize(nBufferSize + 1);
50 	o_rBuffer.Data()[nBufferSize] = '\0';
51 	aXmlFile.seekg(0);
52 
53     // Read file:
54 	aXmlFile.read(o_rBuffer.Data(), (int) nBufferSize);
55 	const bool ret = !aXmlFile.fail();
56 	aXmlFile.close();
57 	return ret;
58 }
59 
60