Why does ENOENT mean "No such file or directory"?
Asked Answered
L

4

721

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?

Leatherneck answered 11/11, 2013 at 9:25 Comment(0)
C
1132

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.

Catchword answered 11/11, 2013 at 9:25 Comment(10)
"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/75Degradable
@Someprogrammerdude’s comment explained most of my questions (qualms) about C naming conventions.Tracheitis
This answer claims it can be used “for more.” What are those other things specifically?Tracheitis
@Jackson such as for command not found in node's child_process. *cries*.Spindlelegs
@amn well, if you get such a code from a syscall not working with files or directories, you'd be confused by what strerror gives you.Tallulah
@Jackson: AF_ALG sockets will return ENOENT from bind() if you attempt to bind an algorithm that doesn't exist.Bourn
@caf: bind() binds to a socket, not to an algorithm, and ENOENT is returned, when a component of a socket pathname does not exist. Actually, whatever ENOENT is returned for, it always refers to a file.Nosy
@GuidoFlohr: No, bind() binds a socket to an address. In the case of AF_ALG sockets, the address (sockaddr_alg) specifies an algorithm type and name, and ENOENT is returned for unknown algorithm names. These algorithm names do not refer to files.Bourn
@caf: Okay, got it. But it's Linux specific and it could be argued that ENOENT is the wrong error code for this particular case, exactly because it has nothing to with a directory entry and it may cause confusing error messages.Nosy
so we're stuck with problems from the past instead of evolving...Uneasy
A
147

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.

Aragats answered 11/11, 2013 at 9:28 Comment(2)
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.Nosy
In any case, it's safe to say that "ent" stands for the same thing in ENOENT as it does in struct dirent.Haplo
K
9

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 */

Kinswoman answered 28/4, 2021 at 1:8 Comment(2)
Link is broken -- now requires authenticationExcess
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 :-)Kinswoman
F
1

In linux(Ubuntu)

File: /usr/include/asm-generic/errno-base.h
6: #define  ENOENT       2  /* No such file or directory */
7: 

https://man7.org/linux/man-pages/man3/errno.3.html

errno 2

return:

ENOENT 2 No such file or directory

open group: https://pubs.opengroup.org/onlinepubs/009604599/functions/xsh_chap02_03.html

[ENOENT]
No such file or directory. A component of a specified pathname does not exist, or the pathname is an empty string.

Glibc:
https://www.gnu.org/software/libc/manual/html_node/Error-Codes.html

Macro: int ENOENT

"No such file or directory." This is a “file doesn’t exist” error for ordinary files that are referenced in contexts where they are

expected to already exist.

Fasciation answered 12/1, 2023 at 7:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.