Christopher Wiley | a59f7b9 | 2013-02-26 15:07:02 -0800 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "shill/file_io.h" |
| 6 | |
| 7 | #include <fcntl.h> |
| 8 | #include <unistd.h> |
| 9 | |
| 10 | #include <base/posix/eintr_wrapper.h> |
| 11 | |
| 12 | namespace shill { |
| 13 | |
| 14 | namespace { |
| 15 | |
| 16 | static base::LazyInstance<FileIO> g_file_io = |
| 17 | LAZY_INSTANCE_INITIALIZER; |
| 18 | |
| 19 | } // namespace |
| 20 | |
| 21 | FileIO::FileIO() {} |
| 22 | |
| 23 | FileIO::~FileIO() {} |
| 24 | |
| 25 | // static |
| 26 | FileIO *FileIO::GetInstance() { |
| 27 | return g_file_io.Pointer(); |
| 28 | } |
| 29 | |
| 30 | ssize_t FileIO::Write(int fd, const void *buf, size_t count) { |
| 31 | return HANDLE_EINTR(write(fd, buf, count)); |
| 32 | } |
| 33 | |
| 34 | ssize_t FileIO::Read(int fd, void *buf, size_t count) { |
| 35 | return HANDLE_EINTR(read(fd, buf, count)); |
| 36 | } |
| 37 | |
| 38 | int FileIO::Close(int fd) { |
| 39 | return HANDLE_EINTR(close(fd)); |
| 40 | } |
| 41 | |
| 42 | int FileIO::SetFdNonBlocking(int fd) { |
| 43 | const int flags = HANDLE_EINTR(fcntl(fd, F_GETFL)) | O_NONBLOCK; |
| 44 | return HANDLE_EINTR(fcntl(fd, F_SETFL, flags)); |
| 45 | } |
| 46 | |
| 47 | } // namespace shill |