mmap failed always - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

mmap failed always

Dear all:

I want to do framebuffer programming, with following program, I always get error while calling mmap. After checking with manual, I still can't solve it. Can Someone help me to see what's wrong?

[color=Blue]The error message on console is:[/color]

[color=Red]Error number is 22
mmap: Invalid argument[/color]

[color=Blue]The program part is:[/color]


struct fb_var_screeninfo vinfo;

#define handle_error(msg)
do { perror(msg); exit(EXIT_FAILURE); } while (0)

int main(void) {
int fbfd,fbsize,i;
unsigned char *fbbuf;

printf("Failed to open /dev/fb0
printf("Success to open /dev/fb0
printf("The fbfd is %d

printf("Failed to get vscreen info ioctl
printf("X resolution %d
printf("Y resolution %d
printf("Bit by pixed %d

fbsize = vinfo.xres*vinfo.yres*vinfo.bits_per_pixel/8;

printf("frame size is %d bytes
fbbuf = mmap(NULL,fbsize,PROT_READ|PROT_WRITE, MAP_SHARED, fbfd,0);

if(fbbuf ==MAP_FAILED){
printf("Error number is %d

Sign In or Register to comment.