% cat getcwd.c #include <assert.h> #include <errno.h> #include <unistd.h> #include <stdio.h> int main() { char buf[3]; assert(getcwd(buf, sizeof(buf)) == NULL); if (errno != ERANGE) { perror("getcwd"); } return 0; } % pwd | wc -c 29 % /compat/linux/bin/cc getcwd.c -o getcwd % ./getcwd getcwd: Cannot allocate memory On the Linux side getcwd is clearly documented to return ERANGE and at least Mono actually expects it: https://github.com/mono/mono/blob/da11592cbea4269971f4b1f9624769a85cc10660/mono/eglib/gfile-posix.c#L175. This is mostly relevant for FNA/MonoGame applications.
https://reviews.freebsd.org/D29217
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=0dfbdd9fc269f0438ffcc31632d35234a90584ad commit 0dfbdd9fc269f0438ffcc31632d35234a90584ad Author: Edward Tomasz Napierala <trasz@FreeBSD.org> AuthorDate: 2021-03-12 15:31:37 +0000 Commit: Edward Tomasz Napierala <trasz@FreeBSD.org> CommitDate: 2021-03-12 15:31:45 +0000 linux(4): make getcwd(2) return ERANGE instead of ENOMEM For native FreeBSD binaries, the return value from __getcwd(2) doesn't really matter, as the libc wrapper takes over and returns the proper errno. PR: kern/254120 Reported By: Alex S <iwtcex@gmail.com> Reviewed By: kib Sponsored By: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D29217 sys/compat/linux/linux_getcwd.c | 2 ++ 1 file changed, 2 insertions(+)
A commit in branch stable/13 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=ab1a91d95872e59db3d476be4fefb0b58df3afc4 commit ab1a91d95872e59db3d476be4fefb0b58df3afc4 Author: Edward Tomasz Napierala <trasz@FreeBSD.org> AuthorDate: 2021-03-12 15:31:37 +0000 Commit: Edward Tomasz Napierala <trasz@FreeBSD.org> CommitDate: 2021-03-15 13:00:17 +0000 linux(4): make getcwd(2) return ERANGE instead of ENOMEM For native FreeBSD binaries, the return value from __getcwd(2) doesn't really matter, as the libc wrapper takes over and returns the proper errno. PR: kern/254120 Reported By: Alex S <iwtcex@gmail.com> Reviewed By: kib Sponsored By: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D29217 (cherry picked from commit 0dfbdd9fc269f0438ffcc31632d35234a90584ad) sys/compat/linux/linux_getcwd.c | 2 ++ 1 file changed, 2 insertions(+)
A commit in branch releng/13.0 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=56dd03e0f2b17e703ba8daad8bc9ab21a761a461 commit 56dd03e0f2b17e703ba8daad8bc9ab21a761a461 Author: Edward Tomasz Napierala <trasz@FreeBSD.org> AuthorDate: 2021-03-12 15:31:37 +0000 Commit: Edward Tomasz Napierala <trasz@FreeBSD.org> CommitDate: 2021-03-16 18:37:57 +0000 linux(4): make getcwd(2) return ERANGE instead of ENOMEM For native FreeBSD binaries, the return value from __getcwd(2) doesn't really matter, as the libc wrapper takes over and returns the proper errno. Approved by: re (gjb) PR: kern/254120 Reported By: Alex S <iwtcex@gmail.com> Reviewed By: kib Sponsored By: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D29217 (cherry picked from commit 0dfbdd9fc269f0438ffcc31632d35234a90584ad) (cherry picked from commit ab1a91d95872e59db3d476be4fefb0b58df3afc4) sys/compat/linux/linux_getcwd.c | 2 ++ 1 file changed, 2 insertions(+)