繁体   English   中英

使用mmap会导致无效的参数错误

[英]Use of mmap causes invalid argument error

我在c中弄混了mmap,遇到了一个非常奇怪的错误。 当我运行以下代码块( 这是此网站的示例代码 )时

/* 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));

我收到一个无效的参数错误。

我的研究使我得出结论,这是一个抵消性的问题,但是我完全无法解决该问题。 任何建议将不胜感激。

谢谢

我决定尝试在另一台机器上运行此代码,并且效果很好,这似乎是机器端的问题,而不是代码中的问题。 至少现在我知道代码没有坏了:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM