In my program I am opening a file as follows:
the open succeeds, and gives me a valid file number.Code:std::string filename = "somefile"; struct stat st; stat(filename.c_str(), &st); int fd = open(filename.c_str(), O_RDONLY);
I then attempt to memory-map the file using mmap() as follows:
I then check the return value of mmap() and find that it is equal to MAP_FAILED. I print the return value of strerror(errno) to stdout and it says "Bad file descriptor."Code:unsigned char* buf = (unsigned char*)mmap(NULL, st.st_size, PROT_READ, fd, MAP_PRIVATE | MAP_POPULATE, 0);
the file is exactly 51200000 bytes long (an integer multiple of the 4096 byte page size), and I'm not asking it to map to a specific or non-aligned memory address.
not sure what I'm doing wrong here, but I just can't seem to make this work.
system is OpenSuse 10.3 x86 kernel version 220.127.116.11-31-default
2GB of system memory + 4GB swap
GCC version 4.2.1