ChatGPT解决这个技术问题 Extra ChatGPT

Why does ENOENT mean "No such file or directory"?

What does the ENT mean in ENOENT?

Shouldn't the error:

No such file or directory

just be named by ENOFILE?

Is there any story or reason?


3
3 revs, 2 users 50%

It's an abbreviation of Error NO ENTry (or Error NO ENTity), and can actually be used for more than files/directories.

It's abbreviated because C compilers at the dawn of time didn't support more than 8 characters in symbols.


"can actually be used for more than files/directories." -- except when you want to have your code merged into Linux: lkml.org/lkml/2012/12/23/75
Seems like it would be more valuable to users if the error was explicit rather than saving 8 characters of space. Any idea why this might be the case?
@BradyDowling Because C compilers at the dawn of time didn't support more than 8 characters in symbols.
@Someprogrammerdude’s comment explained most of my questions (qualms) about C naming conventions.
This answer claims it can be used “for more.” What are those other things specifically?
R
Roland Illig

It's simply “No such directory entry”. Since directory entries can be directories or files (or symlinks, or sockets, or pipes, or devices), the name ENOFILE would have been too narrow in its meaning.


Symlinks, sockets, pipes, and devices are all files, and so are directories. ENOFILE would be just as wide or narrow in its meaning as ENOENT.
In any case, it's safe to say that "ent" stands for the same thing in ENOENT as it does in struct dirent.
D
Dror

For a full list of all the codes and a better description of what each one means see errno.h This is an include file that is part of the C standard library and the comments clarify what the error is about. In this case:

#define ENOENT 2 /* No such file or directory */


Link is broken -- now requires authentication
Sigh. Here's an alternative link ibm.com/docs/en/zos/…. If hat breaks, this should always work duckduckgo.com/?t=ffsb&q=errno.h&ia=web :-)