Home | History | Annotate | Download | only in shill
      1 //
      2 // Copyright (C) 2013 The Android Open Source Project
      3 //
      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
      7 //
      8 //      http://www.apache.org/licenses/LICENSE-2.0
      9 //
     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.
     15 //
     16 
     17 #include "shill/file_io.h"
     18 
     19 #include <fcntl.h>
     20 #include <unistd.h>
     21 
     22 #include <base/posix/eintr_wrapper.h>
     23 
     24 namespace shill {
     25 
     26 namespace {
     27 
     28 base::LazyInstance<FileIO> g_file_io = LAZY_INSTANCE_INITIALIZER;
     29 
     30 }  // namespace
     31 
     32 FileIO::FileIO() {}
     33 
     34 FileIO::~FileIO() {}
     35 
     36 // static
     37 FileIO* FileIO::GetInstance() {
     38   return g_file_io.Pointer();
     39 }
     40 
     41 ssize_t FileIO::Write(int fd, const void* buf, size_t count) {
     42   return HANDLE_EINTR(write(fd, buf, count));
     43 }
     44 
     45 ssize_t FileIO::Read(int fd, void* buf, size_t count) {
     46   return HANDLE_EINTR(read(fd, buf, count));
     47 }
     48 
     49 int FileIO::Close(int fd) {
     50   return IGNORE_EINTR(close(fd));
     51 }
     52 
     53 int FileIO::SetFdNonBlocking(int fd) {
     54   const int flags = HANDLE_EINTR(fcntl(fd, F_GETFL)) | O_NONBLOCK;
     55   return HANDLE_EINTR(fcntl(fd, F_SETFL,  flags));
     56 }
     57 
     58 }  // namespace shill
     59