Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / APG / Shared_Memory / Mem_Map.cpp
blob3813f7268a3733e3e0e2022e0ab9992da40a5a1a
1 #include "ace/OS_NS_fcntl.h"
2 #include "ace/OS_NS_string.h"
3 #include "ace/Mem_Map.h"
4 #include "ace/Log_Msg.h"
6 // Listing 1 code/ch17
7 int ACE_TMAIN (int, ACE_TCHAR *argv[])
9 ACE_HANDLE srcHandle = ACE_OS::open (argv[1], O_RDONLY);
10 ACE_ASSERT(srcHandle != ACE_INVALID_HANDLE);
12 ACE_Mem_Map srcMap (srcHandle, static_cast<size_t> (-1), PROT_READ, ACE_MAP_PRIVATE);
13 ACE_ASSERT(srcMap.addr () != 0);
15 ACE_Mem_Map destMap (argv[2],
16 srcMap.size (),
17 O_RDWR | O_CREAT,
18 ACE_DEFAULT_FILE_PERMS,
19 PROT_RDWR,
20 ACE_MAP_SHARED);
21 ACE_ASSERT(destMap.addr () != 0);
23 ACE_OS::memcpy (destMap.addr (),
24 srcMap.addr (),
25 srcMap.size ());
26 destMap.sync ();
28 srcMap.close ();
29 destMap.close ();
30 return 0;
32 // Listing 1