|
I have the following code:
FILE *fp = stdin;
if ((fp = fopen(argv[optind], "rb")) == NULL) {
printf("Cannot open file %s\n", argv[optind]);
return 2;
}
It executes correctly and the correct file is accessed.
I added the following to get the file size:
SizeLow = GetFileSize(_fileno(fp), & SizeHigh);
if ((SizeLow == 0xFFFFFFFF) && ((Error = GetLastError()) != NO_ERROR)) {
printf("Cannot read file size for %s, error %d\n", argv[optind], Error);
help();
return 2;
}
if (binary && (SizeHigh > 0x70000000)) {
printf("File too big for Binary Mode\n");
help();
return 2;
}
__asm {
mov eax,SizeLow
mov edx,SizeHigh
cmp binary,TRUE
jnz Bytes
shld edx,eax,3
shl eax,3
Bytes:
mov DWORD PTR totalc,eax
mov DWORD PTR totalc+4,edx
}
When I execute I get the following:
ent.exe f:\tst1.tst >ent1.txt
Cannot read file size for f:\tst1.tst, error 6
What am I doing wrong with the the GetFileSize call?
In case you are wondering, this is a modification to John Walker's ENT to speed up execution for huge files.
Dave.
|
|
|
|
|
GetFileSize() expects a file HANDLE but you are passing a file descriptor returned by _fileno() . This is indicated by the error code 6 ERROR_INVALID_HANDLE .
See A Handy Guide To Handling Handles[^] for the differences and how to convert between the various file handle types.
|
|
|
|
|
Jochen,
Thank you for the excellent reference. Just what I needed.
Dave.
|
|
|
|
|
Jochen,
With this line, everything works correctly:
SizeLow = GetFileSize(_get_osfhandle(_fileno(fp)), & SizeHigh);
Thanks for the pointer.
Dave.
|
|
|
|