blob: 5bab4426cf3ed46aafb36708bb2e1eb2fb5d2493 [file] [log] [blame]
Christopher Wileya59f7b92013-02-26 15:07:02 -08001// 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
12namespace shill {
13
14namespace {
15
16static base::LazyInstance<FileIO> g_file_io =
17 LAZY_INSTANCE_INITIALIZER;
18
19} // namespace
20
21FileIO::FileIO() {}
22
23FileIO::~FileIO() {}
24
25// static
26FileIO *FileIO::GetInstance() {
27 return g_file_io.Pointer();
28}
29
30ssize_t FileIO::Write(int fd, const void *buf, size_t count) {
31 return HANDLE_EINTR(write(fd, buf, count));
32}
33
34ssize_t FileIO::Read(int fd, void *buf, size_t count) {
35 return HANDLE_EINTR(read(fd, buf, count));
36}
37
38int FileIO::Close(int fd) {
39 return HANDLE_EINTR(close(fd));
40}
41
42int 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