Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / examples / Mem_Map / file-reverse / file-reverse.cpp
blob7e02c1fd31207ab45ac1e9a2f2dc8b8c4f99dae7
1 // Print a file in reverse by using the ACE memory mapped file
2 // wrapper. It is SO easy to do compared with alternatives!
4 #include "ace/OS_main.h"
5 #include "ace/Mem_Map.h"
6 #include "ace/Log_Msg.h"
7 #include "ace/Truncate.h"
10 static void
11 putline (const char *s)
13 while (putchar (*s++) != '\n')
14 continue;
17 static void
18 print_array_in_reverse (char *array,
19 int size)
21 if (size <= 0)
22 return;
24 size--;
26 if (array[size] == '\0')
27 array[size] = '\n';
29 while (--size >= 0)
30 if (array[size] == '\n')
31 putline (array + size + 1);
33 putline (array);
36 int
37 ACE_TMAIN (int argc, ACE_TCHAR **argv)
39 ACE_LOG_MSG->open (argv[0]);
41 if (argc != 2)
42 ACE_ERROR_RETURN ((LM_ERROR,
43 "usage: %n file\n"),
44 -1);
46 ACE_Mem_Map mmap;
48 if (mmap.map (argv[1], static_cast<size_t> (-1), O_RDWR) == -1)
49 ACE_ERROR_RETURN ((LM_ERROR,
50 "%n: %p\n",
51 "mmap"),
52 -1);
54 print_array_in_reverse ((char *) mmap.addr (),
55 ACE_Utils::truncate_cast<int> (mmap.size ()));
56 return 0;