Skip to content

[libc] Add FILENO related macros to unistd.h. #124688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2025
Merged

[libc] Add FILENO related macros to unistd.h. #124688

merged 1 commit into from
Jan 28, 2025

Conversation

c8ef
Copy link
Contributor

@c8ef c8ef commented Jan 28, 2025

Closes #124637.

This is necessary to build LLVM with LLVM-libc and align the behavior with other libc implementations.
ref: https://man7.org/linux/man-pages/man3/stdin.3.html

@c8ef c8ef changed the title Draft [libc] Add FILENO related macros to unistd.h. Jan 28, 2025
@c8ef c8ef marked this pull request as ready for review January 28, 2025 03:58
@llvmbot llvmbot added the libc label Jan 28, 2025
@c8ef c8ef requested a review from nickdesaulniers January 28, 2025 03:58
@llvmbot
Copy link
Member

llvmbot commented Jan 28, 2025

@llvm/pr-subscribers-libc

Author: None (c8ef)

Changes

Closes #124637.

This is necessary to build LLVM with LLVM-libc and align the behavior with other libc implementations.
ref: https://man7.org/linux/man-pages/man3/stdin.3.html


Full diff: https://github.com/llvm/llvm-project/pull/124688.diff

1 Files Affected:

  • (modified) libc/include/llvm-libc-macros/unistd-macros.h (+4)
diff --git a/libc/include/llvm-libc-macros/unistd-macros.h b/libc/include/llvm-libc-macros/unistd-macros.h
index 4f27f075fcc61b..e09dada04a19d4 100644
--- a/libc/include/llvm-libc-macros/unistd-macros.h
+++ b/libc/include/llvm-libc-macros/unistd-macros.h
@@ -5,4 +5,8 @@
 #include "linux/unistd-macros.h"
 #endif
 
+#define STDIN_FILENO 0
+#define STDOUT_FILENO 1
+#define STDERR_FILENO 2
+
 #endif // LLVM_LIBC_MACROS_UNISTD_MACROS_H

Copy link
Member

@RossComputerGuy RossComputerGuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@nickdesaulniers nickdesaulniers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch.

A better source to cite rather than the man page is POSIX itself, which mandates these symbolic constants have these specific values.

https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/unistd.h.html

@c8ef
Copy link
Contributor Author

c8ef commented Jan 28, 2025

A better source to cite rather than the man page is POSIX itself, which mandates these symbolic constants have these specific values.

https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/unistd.h.html

Got it, thanks for your advice!

@c8ef c8ef merged commit 6489125 into llvm:main Jan 28, 2025
18 checks passed
@c8ef c8ef deleted the FILENO branch January 28, 2025 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[libc][unistd] provide STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO
4 participants