I usually get ERROR_FILE_NOT_FOUND
when I try to open a file that's not there, but now fopen()
fails and GetLastError()
returns ERROR_PATH_NOT_FOUND
.
So what is the difference between ERROR_FILE_NOT_FOUND
and ERROR_PATH_NOT_FOUND
?
I usually get ERROR_FILE_NOT_FOUND
when I try to open a file that's not there, but now fopen()
fails and GetLastError()
returns ERROR_PATH_NOT_FOUND
.
So what is the difference between ERROR_FILE_NOT_FOUND
and ERROR_PATH_NOT_FOUND
?
In WinError.h
, ERROR_FILE_NOT_FOUND
has the descriptive text "The system cannot find the file specified." and ERROR_PATH_NOT_FOUND
has the descriptive text "The system cannot find the path specified."
This doesn't particularly clarify matters.
Usually, however, "file not found" refers to the case where the file itself cannot be found and "path not found" refers to the case where a component of the path (one of the directory names specified) cannot be found.
Actually, the canonical meaning could be deduced from the names of the error codes.
The specific meaning, as it is with all "generic" error codes, highly depends on the implementation of the function that is said to "produce" this error. For an even worse example in this respect, consider the error ERROR_INVALID_DATA
- only the documentation of the function could tell what should be ment by it.
This brings us to the point that fopen
does not even (officially) return or set those error codes. fopen
is part of the CRT library and is thus documented to use the error reporting mechanism thereof: errno
.
Looking at the implementation of fopen
in the CRT source code, you can see (ultimately, it is quite a callstack of internal helper functions), that fopen
in the end calls (not surprisingly) the CreateFile
Win32 API. It then carefully maps the errors potentially returned by CreateFile
to errno-like errors (using the internal _dosmaperr()
function, if you still want to follow in the CRT sources). This maps both ERROR_FILE_NOT_FOUND
and ERROR_PATH_NOT_FOUND
to the errno ENOENT
.
So in the context of fopen
the distinction is best considered meaningless as it is an implementation detail of fopen
.
ERROR_PATH_NOT_FOUND
means, that the container directory does not exist.
ERROR_FILE_NOT_FOUND
means, the container directory exists, and it does not contain the named file.
© 2022 - 2024 — McMap. All rights reserved.