2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <sys/types.h>
27 int PathOps::write(const std::string &path, const std::string &buf)
29 std::string p = mBasePath + path;
30 int fd = ::open(p.c_str(), O_WRONLY);
34 int ret = ::write(fd, buf.c_str(), buf.size());
40 int PathOps::write(const std::string &path, unsigned int data)
42 std::ostringstream os;
44 return PathOps::write(path, os.str());
47 int PathOps::read(const std::string &path, char *buf, int len)
49 std::string p = mBasePath + path;
50 int fd = ::open(p.c_str(), O_RDONLY);
54 int ret = ::read(fd, buf, len);
60 int PathOps::read(const std::string &path, std::string &buf)
62 std::string p = mBasePath + path;
63 /* Using fstream for reading stuff into std::string */
64 std::ifstream f(p.c_str(), std::fstream::in);
77 bool PathOps::exists(const std::string &path)
80 return (bool) (stat((mBasePath + path).c_str(), &s) == 0);
83 bool PathOps::exists()
85 return PathOps::exists("");