Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added class & functions for memory mapped files
- Loading branch information
Showing
6 changed files
with
214 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
grive: an GPL program to sync a local directory with Google Drive | ||
Copyright (C) 2012 Wan Wai Ho | ||
This program is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License | ||
as published by the Free Software Foundation version 2 | ||
of the License. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
#include "MemMap.hh" | ||
#include "StdioFile.hh" | ||
|
||
namespace gr { | ||
|
||
MemMap::MemMap( StdioFile& file, off_t offset, std::size_t length ) : | ||
m_addr ( file.Map( offset, length ) ), | ||
m_length( length ) | ||
{ | ||
} | ||
|
||
MemMap::~MemMap() | ||
{ | ||
StdioFile::UnMap( m_addr, m_length ) ; | ||
} | ||
|
||
void* MemMap::Addr() const | ||
{ | ||
return m_addr ; | ||
} | ||
|
||
std::size_t MemMap::Length() const | ||
{ | ||
return m_length ; | ||
} | ||
|
||
} // end of namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
grive: an GPL program to sync a local directory with Google Drive | ||
Copyright (C) 2012 Wan Wai Ho | ||
This program is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License | ||
as published by the Free Software Foundation version 2 | ||
of the License. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "Exception.hh" | ||
#include "Types.hh" | ||
#include <cstddef> | ||
|
||
namespace gr { | ||
|
||
class StdioFile ; | ||
|
||
class MemMap | ||
{ | ||
public : | ||
struct Error : virtual Exception {} ; | ||
|
||
public : | ||
MemMap( StdioFile& file, off_t offset, std::size_t length ) ; | ||
~MemMap() ; | ||
|
||
void* Addr() const ; | ||
std::size_t Length() const ; | ||
|
||
private : | ||
void *m_addr ; | ||
std::size_t m_length ; | ||
} ; | ||
|
||
} // end of namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
grive: an GPL program to sync a local directory with Google Drive | ||
Copyright (C) 2012 Wan Wai Ho | ||
This program is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License | ||
as published by the Free Software Foundation version 2 | ||
of the License. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <sys/types.h> | ||
|
||
// import types into the Grive namespace | ||
namespace gr | ||
{ | ||
using ::off_t ; | ||
|
||
// should use boost/cstdint | ||
typedef unsigned long long u64_t ; | ||
} |