|
-
December 1st, 2010, 04:52 AM
#10
Re: ReadFile
Igor, I tried your suggestion and it works fine - as long as 'handle' is within the range of low-level (POSIX style) handle numbers. Here's the code from libTIFF:-
Code:
static tsize_t
_tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size)
{
DWORD dwSizeRead;
if (!ReadFile(fd, buf, size, &dwSizeRead, NULL))
return(0);
return ((tsize_t) dwSizeRead);
}
If the file was opened by libTIFF itself, 'fd' will already be a valid WinOS file handle (a long). In my case however, it can also be opened by libgdk_pixbuf in which case, it'll be a low-level, POSIX style handle (an int). For obvious reasons, the above function can't tell one from the other.
Assuming that the values would never overlap (which may or may not be a safe assumption) I could get around this problem by testing to see if 'fd' was already within the range of known WinOS values or alternatively, if it was in the range of low-level values.
At first, I hoped that a simple numerical test would suffice. But when I tried your code this morning, the value returned by _get_osfhandle() was worryingly close the the value I passed in. Can you think of any other way I could test the validity of 'fd'?
Last edited by John E; December 1st, 2010 at 05:10 AM.
"A problem well stated is a problem half solved.” - Charles F. Kettering
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|