This behavior can be seen with the following example program:
$ cat main.c
#include <dirent.h>
#include <err.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
int
main(int argc, char *argv[argc+1])
{
DIR *d;
if (argc < 2)
errx(EXIT_FAILURE, "argc < 2");
d = opendir(argv[1]);
if (d == NULL)
err(EXIT_FAILURE, "opendir");
closedir(d);
exit(EXIT_SUCCESS);
}
$ cc -Wall -Wextra main.c
$ ./a.out $(printf '%0999d')
a.out: opendir: File name too long
Signed-off-by: Collin Funk <collin.funk1@gmail.com>
Message-ID: <
4266061219d7406c0aa737f8d52108fea7e0f7fb.
1760689006.git.collin.funk1@gmail.com>
[jwilk: simpler reproducer]
Cc: Jakub Wilk <jwilk@jwilk.net>
[alx: Fix style in the reproducer program]
Signed-off-by: Alejandro Colomar <alx@kernel.org>
.B EMFILE
The per-process limit on the number of open file descriptors has been reached.
.TP
+.B ENAMETOOLONG
+.I name
+was too long.
+.TP
.B ENFILE
The system-wide limit on the total number of open files has been reached.
.TP