-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathb2a.cc
42 lines (38 loc) · 948 Bytes
/
b2a.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <unistd.h>
#include <stdlib.h>
using namespace std;
int main(int argc, char **argv)
{
int fd;
if ((fd = open(argv[1], O_RDONLY)) < 0){
perror("cant openfile ");
exit(errno);
}
long flen = lseek(fd, 0, SEEK_END);
int *ary;
#ifndef SGI
ary = (int *) mmap((char *)NULL, flen,
(PROT_WRITE|PROT_READ),
MAP_PRIVATE, fd, 0);
#else
ary = (int *) mmap((char *)NULL, flen,
(PROT_WRITE|PROT_READ),
(MAP_FILE|MAP_VARIABLE|MAP_PRIVATE), fd, 0);
#endif
if (ary == (int *)-1){
perror("MMAP ERROR");
exit(errno);
}
for (int i=0; i < flen/sizeof(int); i++)
cout << " " << ary[i];
cout << endl;
munmap((caddr_t)ary, flen);
close(fd);
}