GIT.Harvie.CZ
/
mirrors
/
Programs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
extra yield
[mirrors/Programs.git]
/
c
/
mmap
/
mmap.c
diff --git
a/c/mmap/mmap.c
b/c/mmap/mmap.c
index b2b19209693adcb955bb53bebd1d1ce3135be2c6..69d566699550aa2df3c71b147e987316dc95262e 100644
(file)
--- a/
c/mmap/mmap.c
+++ b/
c/mmap/mmap.c
@@
-1,28
+1,26
@@
+//#define _GNU_SOURCE
+
#include <stdio.h>
#include <stdio.h>
-#include <fcntl.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
#include <sys/types.h>
#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
-unsigned char *fmmap(FILE *fd) {
- struct stat sb;
-
- if(!fd) perror("");
- fd = fileno(fd);
- fstat((int)fd, &sb);
- return mmap(0, sb.st_size, PROT_READ, MAP_PRIVATE, (int)fd, 0);
-}
+#define MEM_PATH "hello.bin"
+#define MEM_SIZE 1048576
int main() {
int main() {
- FILE *fd;
- unsigned char *mm;
-
- fd = fopen("mmap.c", "r");
- mm = fmmap(fd);
+ int fd;
+ fd = open(MEM_PATH, O_RDWR | O_SYNC | O_CREAT | O_CLOEXEC, S_IRUSR | S_IWUSR);
+ ftruncate(fd, MEM_SIZE);
- perror("Status");
- puts(mm);
+ void *mem;
+ mem = mmap(NULL, MEM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED , fd, 0);
+ close(fd);
- //munmap(mm, 10);
- fclose(fd);
+ char hello[] = "Hello!";
+ memcpy(mem, hello, sizeof(hello));
+ msync(mem, sizeof(hello), MS_SYNC);
}
}
This page took
0.117279 seconds
and
4
git commands to generate.