File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -38,8 +38,25 @@ pub unsafe fn environ() -> *mut *const *const c_char {
3838 unsafe { libc:: _NSGetEnviron ( ) as * mut * const * const c_char }
3939}
4040
41+ // On FreeBSD, environ comes from CRT rather than libc
42+ #[ cfg( target_os = "freebsd" ) ]
43+ pub unsafe fn environ ( ) -> * mut * const * const c_char {
44+ use crate :: sync:: LazyLock ;
45+
46+ struct Environ ( * mut * const * const c_char ) ;
47+ unsafe impl Send for Environ { }
48+ unsafe impl Sync for Environ { }
49+
50+ static ENVIRON : LazyLock < Environ > = LazyLock :: new ( || {
51+ Environ ( unsafe {
52+ libc:: dlsym ( libc:: RTLD_DEFAULT , c"environ" . as_ptr ( ) ) as * mut * const * const c_char
53+ } )
54+ } ) ;
55+ ENVIRON . 0
56+ }
57+
4158// Use the `environ` static which is part of POSIX.
42- #[ cfg( not( target_vendor = "apple" ) ) ]
59+ #[ cfg( not( any ( target_os = "freebsd" , target_vendor = "apple" ) ) ) ]
4360pub unsafe fn environ ( ) -> * mut * const * const c_char {
4461 unsafe extern "C" {
4562 static mut environ: * const * const c_char ;
You can’t perform that action at this time.
0 commit comments