| 29 | } |
| 30 | |
| 31 | int 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) |
nothing calls this directly
no test coverage detected
searching dependent graphs…