36
operation to write the modified data to the file on the storage device. Listing 3-2 shows
the equivalent operations on Windows. We walk through and highlight the key steps in
both code samples.
Listing 3-1. mmap_example.c – Memory-mapped file on Linux example
50 #include
51 #include
52 #include
53 #include
54 #include
55 #include
56 #include
57 #include
58 #include
59
60 int
61 main(int argc, char *argv[])
62 {
63
int fd;
64
struct stat stbuf;
65
char *pmaddr;
66
67
if (argc != 2) {
68
fprintf(stderr, "Usage: %s filename\n",
69
argv[0]);
70
exit(1);
71
}
72
73
if ((fd = open(argv[1], O_RDWR)) < 0)
74
err(1, "open %s", argv[1]);
75
76
if (fstat(fd, &stbuf) < 0)
77
err(1, "stat %s", argv[1]);
78
79
/*
Chapter 3 Operating SyStem SuppOrt fOr perSiStent memOry
Précédent

- 65/457

Suivant