Reputation: 91
I need to map a file and then get it's byte value (from the mapped region).
I've map the file, like so:
void* kd_test_mmapw( int d, int size )
{
void *a = NULL;
a = mmap( NULL, size, PROT_READ, MAP_SHARED, d, 0 );
if( a == MAP_FAILED )
{
perror( "mmap failed" );
abort();
}
return a;
}
But I have no idea how to get the byte value
Upvotes: 0
Views: 1574
Reputation: 2654
a
is a pointer to the first byte of you mapped region. You can consider your pointer as a pointer to an array of bytes.
If you want to access the 1234
bytes, just use:
char *asChar = (char*)a;
char myByte = asChar[1233];
Upvotes: 2