You should be checking just data == -1
(or, even better, MAP_FAILED
) and not *data == -1
(dereferencing via *
is wrong here).
The reason your code fails is because the first byte of every JPEG file is FF
in hex or -1 in signed decimal.
For more detail on JPEG, Google for "JPEG file format." For example, search for "SOI" on this page.