sorry for the delayed reply,
please help me i am trying like this, though this is one sample test,
iam opening the two files one for reading and one for writing, and i am checking like this
if((input = open(argv[1], O_RDONLY)) == -1)
fprintf(stderr, "%s: Error: opening file: %s\n", PACKAGE, argv[1]), exit(1);
if((output = open(argv[2], O_RDWR|O_CREAT|O_TRUNC, 0666)) == -1)
fprintf(stderr, "%s: Error: opening file: %s\n", PACKAGE, argv[2]), exit(1);
source = (char *)mmap((char *)0, filesize, PROT_READ, MAP_SHARED, input, 0);
printf("\n address of source==%p",source);
if(source[0] ==-1)
fprintf(stderr, "Error mapping input file: %s\n", argv[1]), exit(1);
target =(char *) mmap((char *)0, filesize, PROT_WRITE, MAP_SHARED, output, 0);
printf("\n address of target==%d",target);
if(target[0]==-1) //problem here
fprintf(stderr, "Error mapping ouput file: %s\n", argv[2]), exit(1);
as i am opening both of them and checking instead of MAP_FAILED for the failure to target[0]==-1 ,
my question is what exactly is the data structure that mmap returns when i test for read it is successfull and for write it is not and also
if i change that to
if(target==(void*)-1 ) it returns successfull,
because in my code they have used
target[0]==-1 which is failing and results in sigbus if i replace it with
if(target==MAP_FAILED)
it is not even going for failure nor the sucess,
and fails some where in the reading. so what is the reason of sigbus
please solve my problem