1 /* 2 * Copyright 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "VtsDriverFileUtil.h" 18 19 #include <fstream> 20 #include <iostream> 21 #include <sstream> 22 23 using namespace std; 24 25 namespace android { 26 namespace vts { 27 ReadFile(const string & file_path)28string ReadFile(const string& file_path) { 29 ifstream ifs(file_path); 30 string content((istreambuf_iterator<char>(ifs)), 31 (istreambuf_iterator<char>())); 32 return content; 33 } 34 GetDirFromFilePath(const string & str)35string GetDirFromFilePath(const string& str) { 36 size_t found = str.find_last_of("/\\"); 37 if (found == string::npos) { 38 return "."; 39 } 40 41 return str.substr(0, found); 42 } 43 44 } // namespace vts 45 } // 46