1c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// 2c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// Copyright (C) 2013 The Android Open Source Project 3c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// 4c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// Licensed under the Apache License, Version 2.0 (the "License"); 5c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// you may not use this file except in compliance with the License. 6c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// You may obtain a copy of the License at 7c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// 8c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// http://www.apache.org/licenses/LICENSE-2.0 9c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// 10c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// Unless required by applicable law or agreed to in writing, software 11c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// distributed under the License is distributed on an "AS IS" BASIS, 12c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// See the License for the specific language governing permissions and 14c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// limitations under the License. 15c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// 16a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley 17a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley#include "shill/file_io.h" 18a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley 19a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley#include <fcntl.h> 20a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley#include <unistd.h> 21a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley 22a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley#include <base/posix/eintr_wrapper.h> 23a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley 24a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wileynamespace shill { 25a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley 26a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wileynamespace { 27a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley 28be0849f4474f6e97496550187bc4256bf0a91d2bBen Chanbase::LazyInstance<FileIO> g_file_io = LAZY_INSTANCE_INITIALIZER; 29a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley 30a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley} // namespace 31a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley 32a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher WileyFileIO::FileIO() {} 33a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley 34a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher WileyFileIO::~FileIO() {} 35a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley 36a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley// static 378ae18741780300de3126826b72593391f2d00313Paul StewartFileIO* FileIO::GetInstance() { 38a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley return g_file_io.Pointer(); 39a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley} 40a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley 418ae18741780300de3126826b72593391f2d00313Paul Stewartssize_t FileIO::Write(int fd, const void* buf, size_t count) { 42a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley return HANDLE_EINTR(write(fd, buf, count)); 43a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley} 44a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley 458ae18741780300de3126826b72593391f2d00313Paul Stewartssize_t FileIO::Read(int fd, void* buf, size_t count) { 46a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley return HANDLE_EINTR(read(fd, buf, count)); 47a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley} 48a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley 49a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wileyint FileIO::Close(int fd) { 502dd351c3121f1257aed9b3a4bda70e32da5df913Mike Frysinger return IGNORE_EINTR(close(fd)); 51a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley} 52a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley 53a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wileyint FileIO::SetFdNonBlocking(int fd) { 54a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley const int flags = HANDLE_EINTR(fcntl(fd, F_GETFL)) | O_NONBLOCK; 55a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley return HANDLE_EINTR(fcntl(fd, F_SETFL, flags)); 56a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley} 57a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley 58a59f7b9badec5b693661a56f7d7e45feabcaf26eChristopher Wiley} // namespace shill 59