I stored a filesize in a binary file and I am able to get this filesize into a char[8]
buffer. I would like to convert this char[]
into an off_t
type in order to be able to pass it as an argument of truncate(const char *path, off_t length)
.
I tried this naive approach and it seems to work most of the time, but it fails sometimes and gives me a weird sequence of bits.
off_t pchar_2_off_t(char* str, size_t size)
{
off_t ret = 0;
size_t i;
for (i = 0; i < size; ++i)
{
ret <<= 8;
ret |= str[i];
}
return ret;
}