1*aed3e508SAndroid Build Coastguard Worker // Copyright 2014 The ChromiumOS Authors 2*aed3e508SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be 3*aed3e508SAndroid Build Coastguard Worker // found in the LICENSE file. 4*aed3e508SAndroid Build Coastguard Worker 5*aed3e508SAndroid Build Coastguard Worker #ifndef GESTURES_FILE_UTIL_H_ 6*aed3e508SAndroid Build Coastguard Worker #define GESTURES_FILE_UTIL_H_ 7*aed3e508SAndroid Build Coastguard Worker 8*aed3e508SAndroid Build Coastguard Worker #include <string> 9*aed3e508SAndroid Build Coastguard Worker 10*aed3e508SAndroid Build Coastguard Worker namespace gestures { 11*aed3e508SAndroid Build Coastguard Worker 12*aed3e508SAndroid Build Coastguard Worker // Reads the file at |path| into |contents| and returns true on success. 13*aed3e508SAndroid Build Coastguard Worker // |contents| may be nullptr, in which case this function is useful for its 14*aed3e508SAndroid Build Coastguard Worker // side effect of priming the disk cache (could be used for unit tests). 15*aed3e508SAndroid Build Coastguard Worker // The function returns false and the string pointed to by |contents| is 16*aed3e508SAndroid Build Coastguard Worker // cleared when |path| does not exist or if it contains path traversal 17*aed3e508SAndroid Build Coastguard Worker // components ('..'). 18*aed3e508SAndroid Build Coastguard Worker bool ReadFileToString(const char* path, std::string* contents); 19*aed3e508SAndroid Build Coastguard Worker 20*aed3e508SAndroid Build Coastguard Worker // Writes the given buffer into the file, overwriting any data that was 21*aed3e508SAndroid Build Coastguard Worker // previously there. Returns the number of bytes written, or -1 on error. 22*aed3e508SAndroid Build Coastguard Worker int WriteFile(const char* filename, const char* data, int size); 23*aed3e508SAndroid Build Coastguard Worker 24*aed3e508SAndroid Build Coastguard Worker } // namespace gestures 25*aed3e508SAndroid Build Coastguard Worker 26*aed3e508SAndroid Build Coastguard Worker #endif // GESTURES_UTIL_H_ 27