Unix: Add _PATH_BSHELL and _PATH_DEFPATH where available - #5449
Open
asder8215 wants to merge 1 commit into
Open
Conversation
Collaborator
asder8215
force-pushed
the
unix_paths_constants
branch
from
August 31, 2026 01:15
436cb4f to
03110d3
Compare
Collaborator
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
_PATH_BSHELL and _PATH_DEFPATH constants to multiple unix platforms_PATH_BSHELL and _PATH_DEFPATH where available
tgross35
requested changes
Aug 31, 2026
Member
There was a problem hiding this comment.
You'll need to use byte arrays to meet the MSRV. Add a function to
Lines 69 to 140 in b6d2732
fn cstr(bytes: &[u8]) -> *const c_char that asserts there's a single nul at the end and does the cast, with a FIXME(msrv) comment.
Comment on lines
+4115
to
+4116
| /// Default search path | ||
| const _PATH_DEFPATH: *const c_char = c"/usr/bin:/bin".as_ptr(); |
Member
There was a problem hiding this comment.
Drop the doc comments, libc expects you to read the manpages
Comment on lines
+1500
to
+1515
| // include/paths.h (Bionics libc paths.h: https://android.googlesource.com/platform/bionic/+/refs/heads/main/libc/include/paths.h, | ||
| #[cfg(not(any(target_env = "musl", target_os = "android")))] | ||
| /// Default search path on glibc/uclibc Linux | ||
| pub const _PATH_DEFPATH: *const c_char = c"/usr/bin:/bin".as_ptr(); | ||
| #[cfg(all(target_env = "musl", not(target_os = "android")))] | ||
| /// Default search path on musl Linux platforms | ||
| pub const _PATH_DEFPATH: *const c_char = c"/usr/local/bin:/bin:/usr/bin".as_ptr(); | ||
| #[cfg(target_os = "android")] | ||
| /// Default search path on Android/Bionics libc | ||
| pub const _PATH_DEFPATH: *const c_char = c"/product/bin:/apex/com.android.runtime/bin:/apex/com.android.art/bin:/apex/com.android.virt/bin:/system_ext/bin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin".as_ptr(); | ||
| /// Default shell path on Linux platforms (except Android) | ||
| #[cfg(not(target_os = "android"))] | ||
| pub const _PATH_BSHELL: *const c_char = c"/bin/sh".as_ptr(); | ||
| /// Default shell path on Android | ||
| #[cfg(target_os = "android")] | ||
| pub const _PATH_BSHELL: *const c_char = c"/system/bin/sh".as_ptr(); |
Member
There was a problem hiding this comment.
Simplify this by using if cfg!(...) { ... } else { ... } rather than #[cfg]
| pub const _PATH_DEFPATH: *const c_char = c"/usr/local/bin:/bin:/usr/bin".as_ptr(); | ||
| #[cfg(target_os = "android")] | ||
| /// Default search path on Android/Bionics libc | ||
| pub const _PATH_DEFPATH: *const c_char = c"/product/bin:/apex/com.android.runtime/bin:/apex/com.android.art/bin:/apex/com.android.virt/bin:/system_ext/bin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin".as_ptr(); |
Collaborator
|
Reminder, once the PR becomes ready for a review, use |
Member
|
Two other things:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds
_PATH_BSHELLand_PATH_DEFPATHconstants frominclude/paths.hon multiple unix-based platforms (a couple platforms only have_PATH_BSHELL). The reason for why we need these macros could be seen from this Zulip chat #t-libs/crates > Including <paths.h> macros into libc? @ 💬 and PR.The following are sources to each platform's
paths.h:From BSD:
_PATH_BSHELLand_PATH_DEFPATH_PATH_BSHELLand_PATH_DEFPATH_PATH_BSHELLand_PATH_DEFPATH(verified same values on version 11+)_PATH_BSHELLand_PATH_DEFPATH_PATH_BSHELLand_PATH_DEFPATHFrom Linux:
_PATH_BSHELLand_PATH_DEFPATH_PATH_BSHELLand_PATH_DEFPATH_PATH_BSHELLand_PATH_DEFPATH_PATH_BSHELLand_PATH_DEFPATH_PATH_BSHELLand_PATH_DEFPATHpaths.hfile containing_PATH_BSHELLand_PATH_DEFPATHvaluesMiscellaneous Platforms:
_PATH_BSHELLand_PATH_DEFPATH_PATH_BSHELLand_PATH_DEFPATHin paths.h (wouldn't hurt to confirm this though in terminal)_PATH_BSHELLand_PATH_DEFPATH_PATH_BSHELL_PATH_BSHELLPlatforms I'm unsure if they have
_PATH_BSHELL/_PATH_DEFPATH:_PATH_BSHELL.include/paths.hfile.include/paths.hfile.Would be helpful if someone could go on terminal and print out
_PATH_BSHELLand see if that produces results?Other questions I have are:
_PATH_DEFPATHconcatenates theRESCUEDIRmacro in front of its string literal if it exists, should we also have that in our_PATH_DEFPATHmacro? I wasn't sure (I also don't know what the value ofRESCUEDIRis), and I was advised by Jonas to reach out to @he32 and @0323pin since they're experienced with NetBSD.This is also my first time contributing to libc. I've read through the
CONTRIBUTING.mdfile and hopefully I got everything done correctly. I know the md file also mentions about reorganization effort for moving from the hierarchial structure to the source-mapped structure insrc/new. If you want me to restructure the constants I'm introducing tosrc/new, I can try for that; I may need more clarity on how that process works.cc @joboet
@rustbot label stable-nominated