701

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?

S.S. Anne
  • 15,171
  • 8
  • 38
  • 76
mingchaoyan
  • 8,096
  • 3
  • 23
  • 31

4 Answers4

1098

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.

mikemaccana
  • 110,530
  • 99
  • 389
  • 494
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • 59
    "can actually be used for more than files/directories." -- except when you want to have your code merged into Linux: https://lkml.org/lkml/2012/12/23/75 – Armen Michaeli Mar 03 '17 at 13:37
  • 16
    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? – Brady Dowling Apr 07 '17 at 21:48
  • 78
    @BradyDowling Because C compilers at the dawn of time didn't support more than 8 characters in symbols. – Some programmer dude Apr 08 '17 at 05:11
  • 21
    @Someprogrammerdude’s comment explained most of my questions (qualms) about C naming conventions. – Jackson Dec 22 '17 at 00:39
  • 10
    This answer claims it can be used “for more.” What are those other things specifically? – Jackson Dec 22 '17 at 00:41
  • 8
    @Jackson such as for `command not found` in node's [child_process](https://nodejs.org/docs/latest-v10.x/api/child_process.html). \*cries\*. – dwelle Nov 15 '18 at 21:56
  • 1
    @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. – Ruslan Mar 18 '19 at 05:51
  • 4
    @Jackson: `AF_ALG` sockets will return `ENOENT` from `bind()` if you attempt to bind an algorithm that doesn't exist. – caf Sep 02 '19 at 04:33
  • 1
    @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. – Guido Flohr Dec 19 '19 at 07:26
  • 4
    @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. – caf Dec 19 '19 at 13:46
  • 2
    @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. – Guido Flohr Dec 20 '19 at 10:42
  • 1
    so we're stuck with problems from the past instead of evolving... – dawn Nov 24 '20 at 20:33
145

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.

Roland Illig
  • 40,703
  • 10
  • 88
  • 121
  • 43
    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. – Guido Flohr May 02 '17 at 09:23
  • 9
    In any case, it's safe to say that "ent" stands for the same thing in `ENOENT` as it does in `struct dirent`. – Steve Summit Feb 05 '21 at 19:11
7

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

Dror
  • 2,370
  • 1
  • 18
  • 13
  • 4
    Link is broken -- now requires authentication – jack Jun 11 '21 at 20:59
  • 5
    Sigh. Here's an alternative link https://www.ibm.com/docs/en/zos/2.3.0?topic=files-errnoh-symbolic-constants-errno. If hat breaks, this should always work https://duckduckgo.com/?t=ffsb&q=errno.h&ia=web :-) – Dror Jun 12 '21 at 21:03
0

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.

jian
  • 4,119
  • 1
  • 17
  • 32