MCPcopy Create free account
hub / github.com/acl-dev/acl / main

Function main

lib_acl_cpp/samples/mmap/main.cpp:31–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29}
30
31int main(int argc, char* argv[])
32{
33 acl::string action("get");
34 bool unuse = false;
35 int ch;
36
37 while ((ch = getopt(argc, argv, "hf:n:uo:")) > 0)
38 {
39 switch (ch)
40 {
41 case 'h':
42 usage(argv[0]);
43 return 0;
44 case 'f':
45 __fpath = optarg;
46 break;
47 case 'n':
48 __max = atol(optarg);
49 break;
50 case 'u':
51 unuse = true;
52 break;
53 case 'o':
54 action = optarg;
55 break;
56 default:
57 break;
58 }
59 }
60
61 int fd = open(__fpath.c_str(), O_RDWR | O_CREAT, 0600);
62 if (fd == -1)
63 {
64 printf("open %s error\r\n", __fpath.c_str());
65 return 1;
66 }
67
68 char* ptr = (char*) mmap(NULL, __max, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
69 if (ptr == NULL)
70 {
71 printf("mmap error %s\r\n", acl::last_serror());
72 return 1;
73 }
74
75 printf("file size: %ld\r\n", __max);
76 lseek(fd, __max, SEEK_SET);
77 write(fd, "x", 1);
78 close(fd);
79 char* ptr_saved = ptr;
80
81 printf("action: %s\r\n", action.c_str());
82
83 if (action == "get")
84 {
85 for (off_t i = 0; i < __max; i++)
86 {
87 ch = *ptr++;
88 if (i % 9999999 == 0)

Callers

nothing calls this directly

Calls 9

openFunction · 0.85
acl_pthread_createFunction · 0.85
usageFunction · 0.70
getoptFunction · 0.50
last_serrorFunction · 0.50
writeFunction · 0.50
closeFunction · 0.50
sleepFunction · 0.50
c_strMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…