Remy Porter's CodeSOD column recounts a bug hunt by a developer named Greta, who works with an old Pascal development setup. Her program kept reporting that files did not exist, even though they clearly did. Tracing the fault led into the standard system library shipped with Borland's Delphi and Kylix cross-platform runtime, originally copyrighted 1995 to 2001.
The library's FileExists function does not check file presence directly. Instead it calls FileAge, which uses the Windows API function FindFirstFile to locate the file and then FileTimeToDosDateTime to convert the file's last-write time into a DOS-style date and time value. If that conversion succeeds, FileAge returns the encoded timestamp. If anything fails along the way, FileAge returns -1, and FileExists then reports the file as absent whenever FileAge returns -1.
The actual bug: FileTimeToDosDateTime returns a boolean success flag and sets a Windows error code on failure, but the Delphi library code never checks that flag or the error code. Some process on Greta's system was writing files without setting a last-write timestamp. With no valid timestamp to convert, FileTimeToDosDateTime failed silently, FileAge returned -1, and FileExists wrongly concluded the file did not exist, even though it was sitting right there on disk.




Comments
No comments yet — be the first.
Open the discussion
No account or password needed — just enter your e-mail and we’ll send you a one-time sign-in link. First time here? You’re set up automatically.
Your rating will be applied automatically after you sign in.
Check your inbox
We’ve sent a sign-in link to …. Open it on this device — this tab will sign you in automatically.
Nothing arrived? Check your spam folder — and mark the mail as "Not spam" so it lands in your inbox next time.