【发布时间】:2014-02-03 05:21:57
【问题描述】:
我在 c 中弄乱了 mmap,遇到了一个非常奇怪的错误。当我运行以下代码块时 (which is sample code from this website)
/* The file descriptor. */
int fd;
/* Information about the file. */
struct stat s;
int status;
size_t size;
/* The file name to open. */
const char * file_name = "myfile.txt";
/* The memory-mapped thing itself. */
const void * mapped;
int i;
/* Open the file for reading. */
fd = open ("myfile.txt", O_RDONLY);
check (fd < 0, "open %s failed: %s", file_name, strerror (errno));
/* Get the size of the file. */
status = fstat (fd, & s);
check (status < 0, "stat %s failed: %s", file_name, strerror (errno));
size = s.st_size;
/* Memory-map the file. */
mapped = mmap (0, size, PROT_READ, MAP_SHARED, fd, 0);
check (mapped == MAP_FAILED, "mmap %s failed: %s",
file_name, strerror (errno));
我收到一个无效参数错误。
我的研究使我得出结论,这是一个抵消问题,但我完全不知道我能做些什么来解决它。任何建议将不胜感激。
谢谢
【问题讨论】:
-
你试过用
MAP_PRIVATE代替MAP_SHARED吗? -
我试过了,错误依旧存在
标签: c