"Fossies" - the Fresh Open Source Software Archive

Member "muscle/winsupport/Win32FileHandleDataIO.cpp" (8 Jun 2019, 2326 Bytes) of package /linux/privat/muscle7.30.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Win32FileHandleDataIO.cpp" see the Fossies "Dox" file reference documentation.

    1 /* This file is Copyright 2000-2013 Meyer Sound Laboratories Inc.  See the included LICENSE.txt file for details. */
    2 
    3 #if defined(WIN32)
    4 #include "winsupport/Win32FileHandleDataIO.h"
    5 
    6 namespace muscle {
    7 
    8 Win32FileHandleDataIO ::
    9 Win32FileHandleDataIO(::HANDLE handle) : _handle(handle)
   10 {
   11    // empty
   12 }
   13 
   14 Win32FileHandleDataIO ::
   15 ~Win32FileHandleDataIO() 
   16 {
   17    if (_handle != INVALID_HANDLE_VALUE) CloseHandle(_handle);
   18 }
   19 
   20 int32 Win32FileHandleDataIO :: Read(void * buffer, uint32 size)  
   21 {
   22    if (_handle != INVALID_HANDLE_VALUE)
   23    {
   24       DWORD readCount=0;
   25       return ReadFile(_handle, buffer, size, &readCount, 0) ? readCount : -1;
   26    }
   27    else return -1;
   28 }
   29 
   30 int32 Win32FileHandleDataIO :: Write(const void * buffer, uint32 size)
   31 {
   32    if (_handle != INVALID_HANDLE_VALUE) 
   33    {
   34       DWORD writeCount;
   35       return WriteFile(_handle, buffer, size, &writeCount, 0) ? writeCount : -1;
   36    }
   37    else return -1;
   38 }
   39 
   40 void Win32FileHandleDataIO :: FlushOutput()
   41 {
   42    // empty
   43 }
   44 
   45 status_t Win32FileHandleDataIO :: SetBlockingIOEnabled(bool blocking)
   46 {
   47    return ((_handle != INVALID_HANDLE_VALUE)&&(blocking==false)) ? B_NO_ERROR : B_ERROR;
   48 }
   49 
   50 void Win32FileHandleDataIO :: Shutdown()
   51 {
   52    if (_handle != INVALID_HANDLE_VALUE) 
   53    {
   54       CloseHandle(_handle);
   55       _handle = INVALID_HANDLE_VALUE;
   56    }
   57 }
   58 
   59 status_t Win32FileHandleDataIO :: Seek(int64 offset, int whence)
   60 {
   61    if (_handle != INVALID_HANDLE_VALUE)
   62    {
   63       switch(whence)
   64       {
   65          case IO_SEEK_SET: whence = FILE_BEGIN;   break;
   66          case IO_SEEK_CUR: whence = FILE_CURRENT; break;
   67          case IO_SEEK_END: whence = FILE_END;     break;
   68          default:          return B_ERROR;
   69       }
   70 
   71       LARGE_INTEGER newPosition;    newPosition.QuadPart    = 0;
   72       LARGE_INTEGER distanceToMove; distanceToMove.QuadPart = offset;
   73       return SetFilePointerEx(_handle, distanceToMove, &newPosition, whence) ? B_NO_ERROR : B_ERROR;
   74    }
   75    return B_ERROR;
   76 }
   77 
   78 int64 Win32FileHandleDataIO :: GetPosition() const
   79 {
   80    if (_handle != INVALID_HANDLE_VALUE)
   81    {
   82       LARGE_INTEGER newPosition;    newPosition.QuadPart    = 0;
   83       LARGE_INTEGER distanceToMove; distanceToMove.QuadPart = 0;
   84       return SetFilePointerEx(_handle, distanceToMove, &newPosition, FILE_CURRENT) ? newPosition.QuadPart : -1;
   85    }
   86    return -1;
   87 }
   88 
   89 } // end namespace muscle
   90 
   91 #endif