简单问题。。mmap: No such device
#include <stdlib.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <stdio.h>
int main(void)
{
int *p = NULL;
int fd = ("1.txt", O_RDWR);
//printf("fd = %d\n", fd);
if(fd < 0)
{
perror("open file");
exit(1);
}
p = mmap(NULL, 6, PROT_WRITE, MAP_SHARED, fd, 0);
if(p == MAP_FAILED)
{
puts("test1");
perror("mmap");
exit(1);
}
close(fd);
p[0] = 0x30313233;
munmap(p, 6);
return 0;
}
------解决方案--------------------int fd = ("1.txt", O_RDWR);????
------解决方案--------------------应该是int fd = open("1.txt", O_RDWR);