开发者

Problems with File I/o when porting old 'C' libraries from 32-bit to 64-bit

I h开发者_开发百科ave really old 'c' code that uses read to read a binary file. Here is a sample:

uint MyReadFunc(int _FileHandle, char *DstBuf, uint BufLen)
{  
    return (read( _FileHandle, DstBuf, BufLen));
}

For 64bit OS - char * will be 64 bits but the BufLen is only 32 bits and the returned value are only 32 bits.

Its not an option to change this to .NET - I have .NET versions, but I need this old library converted also.

Can someone please tell me what I need to use to do File i/o on 64 bit OS (using 'C' code)


Use size_t, not uint.


It looks like you're conflating two things: size of a pointer and the extent of the memory it points to.


I'm not sure about char* being 64-bits - the pointer itself will be 64-bit, yes, but the actual value is still a character array, unless I'm missing something? (I'm not a brilliant C programmer.)

The length argument to read() is size_t, not int, which on a 64-bit system should be 64-bit not 32. Also the return value is a ssize_t, not int, which will also be 64-bit so you should be covered if you just change your function definition to return ssize_t, and take size_t instead of the ints.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜