Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F1506183
unix.rs
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
unix.rs
View Options
use
std
::
ffi
::{
CStr
,
OsString
};
use
std
::
os
::
unix
::
prelude
::
OsStringExt
;
pub
struct
Vars
{
inner
:
std
::
vec
::
IntoIter
<
OsString
>
,
}
impl
Iterator
for
Vars
{
type
Item
=
String
;
fn
next
(
&
mut
self
)
->
Option
<
String
>
{
self
.
inner
.
next
().
map
(
|
var
|
var
.
into_string
().
unwrap
())
}
fn
size_hint
(
&
self
)
->
(
usize
,
Option
<
usize
>
)
{
self
.
inner
.
size_hint
()
}
}
#[cfg(target_os =
"macos"
)]
unsafe
fn
environ
()
->
*
mut
*
const
*
const
libc
::
c_char
{
libc
::
_NSGetEnviron
()
as
*
mut
*
const
*
const
libc
::
c_char
}
#[cfg(not(target_os =
"macos"
))]
unsafe
fn
environ
()
->
*
mut
*
const
*
const
libc
::
c_char
{
extern
"C"
{
static
mut
environ
:
*
const
*
const
libc
::
c_char
;
}
std
::
ptr
::
addr_of_mut
!
(
environ
)
}
pub
fn
env
()
->
Vec
<
String
>
{
unsafe
{
let
mut
environ
=
*
environ
();
let
mut
result
=
Vec
::
new
();
if
!
environ
.
is_null
()
{
while
!
(
*
environ
).
is_null
()
{
if
let
Some
(
key_value
)
=
parse
(
CStr
::
from_ptr
(
*
environ
).
to_bytes
())
{
result
.
push
(
key_value
);
}
environ
=
environ
.
add
(
1
);
}
}
return
Vars
{
inner
:
result
.
into_iter
()
}.
collect
();
}
fn
parse
(
input
:
&
[
u8
])
->
Option
<
OsString
>
{
if
input
.
is_empty
()
{
return
None
;
}
Some
(
OsString
::
from_vec
(
input
.
to_vec
()))
}
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Sun, Jul 13, 2:06 PM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
344429
Default Alt Text
unix.rs (1 KB)
Attached To
Mode
rPMC Process Management Controller
Attached
Detach File
Event Timeline
Log In to Comment