read() api call maximum byte count on XP

When I ran some code using read() that worked fine on Windows 7 and up on XP, I got a -1 return code with errno set to EINVAL when I called it with a requested byte count of 170,769,911.

I had thought the the limit was INT_MAX(2GB-1) but clearly not on XP! I worked around the problem by setting a maximum request length of USHRT_MAX (65535) and iterating.

What is the actual real limit on XP? I can't quite believe it's as small as 64k-1!

Thanks
David
 
Are you referring to std::istream::read()? What programming language are you using?

If you are referring to std::istream::read(), I have no idea what's going on.
 
Nothing so complex: the regular C api call:

int read(int fh, void* buffer, unsigned int length)

for reading files.
 
To answer my own question! I wrote a crude binary search to determine the actual limit.

When the file is on a local disk, then subject to memory availability (you try a malloc of 2GB under XP!!), then INT_MAX is (most likely) the limit - I couldn't reach that value!

However the number is much lower when you are reading from a mapped network drive (in this case connecting to Host disk when running in a VM under VMWare). In that case the limit would appear to be 67,076,032 (0x3FF7FC0) bytes.

I don't know quite why it would be that value, but likely it's a restriction in NETBIOS.

David
 
You poor guy! Using malloc?! Switch to C++ and you can use new. It's much easier. ;) Also, you can use std::fstream for reading files. It doesn't require a file size.

Just my opinion, do whatever you want. :D
 
That was just a for example - actually I do use new and shared_ptr/unique_ptr a lot, just that the code I hit that problem with was OLD code so I "went with the flow" when writing the test case!

It turns out that this MS web-page documents the limit (though not with great precision):
https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-writefile
and it fails to mention that those limits also apply to read operations!

PS Love the sig-line quote about C++ and blowing your leg off!
 
Last edited:
Good for you for using C++!

Actually, good for you for being versatile and programming in a variety of languages.

PS Love the sig-line quote about C++ and blowing your leg off!

I found it somewhere and thought it was fitting, and Bjarne Stroustrup claims on his website that he actually did say it, so there it is.
 
Back
Top