mirror of
https://github.com/Noratrieb/libuwuc.git
synced 2026-01-14 11:45:05 +01:00
fix getenv
This commit is contained in:
parent
9464ea4829
commit
de90913d46
6 changed files with 25 additions and 92 deletions
61
flake.lock
generated
61
flake.lock
generated
|
|
@ -1,61 +0,0 @@
|
|||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1694529238,
|
||||
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1695830400,
|
||||
"narHash": "sha256-gToZXQVr0G/1WriO83olnqrLSHF2Jb8BPcmCt497ro0=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "8a86b98f0ba1c405358f1b71ff8b5e1d317f5db2",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
24
flake.nix
24
flake.nix
|
|
@ -1,24 +0,0 @@
|
|||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
|
||||
outputs = { nixpkgs, flake-utils, ... }: flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
in
|
||||
{
|
||||
devShells.default = pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
rustup
|
||||
];
|
||||
shellHook = ''
|
||||
export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin
|
||||
export PATH=$PATH:''${RUSTUP_HOME:-~/.rustup}/toolchains/$RUSTC_VERSION-x86_64-unknown-linux-gnu/bin/
|
||||
'';
|
||||
packages = (with pkgs; [
|
||||
]);
|
||||
};
|
||||
});
|
||||
}
|
||||
10
shell.nix
Normal file
10
shell.nix
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{ pkgs ? import <nixpkgs> { } }: pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
rustup
|
||||
];
|
||||
shellHook = ''
|
||||
export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin
|
||||
'';
|
||||
packages = (with pkgs; [
|
||||
]);
|
||||
}
|
||||
17
src/env.rs
17
src/env.rs
|
|
@ -1,8 +1,4 @@
|
|||
use core::{
|
||||
ffi::{c_char, CStr},
|
||||
iter,
|
||||
ptr::NonNull,
|
||||
};
|
||||
use core::{ffi::CStr, ptr::NonNull};
|
||||
|
||||
use crate::{println, utils::SharedThinCstr};
|
||||
|
||||
|
|
@ -67,6 +63,7 @@ pub fn getenv(name: SharedThinCstr) -> Option<SharedThinCstr> {
|
|||
fn getenv_inner(mut envp: EnvP, name: SharedThinCstr) -> Option<SharedThinCstr> {
|
||||
let mut eq_idx = 0;
|
||||
envp.find(|env| {
|
||||
println!("trying {env:?}");
|
||||
// Find ENV
|
||||
// EN=x
|
||||
// ENV=x <- this one
|
||||
|
|
@ -84,6 +81,9 @@ fn getenv_inner(mut envp: EnvP, name: SharedThinCstr) -> Option<SharedThinCstr>
|
|||
if name.is_none() || env == Some(b'=') {
|
||||
return false;
|
||||
}
|
||||
if name != env {
|
||||
return false;
|
||||
}
|
||||
eq_idx += 1;
|
||||
}
|
||||
})
|
||||
|
|
@ -154,4 +154,11 @@ mod tests {
|
|||
assert_eq!(super::getenv_inner(envp, cstr("LONG_NAME\0")), None);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn getenv_same_length() {
|
||||
with_envp(&["OWO=a", "UWU=b"], |envp| {
|
||||
assert_eq!(super::getenv_inner(envp, cstr("UWU\0")), Some(cstr("b\0")));
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ impl core::fmt::Write for Printer {
|
|||
unsafe {
|
||||
while s.len() > 0 {
|
||||
let result =
|
||||
syscall::syscall!(syscall::SYS_WRITE, STDIN, s.as_ptr(), s.len()) as i64;
|
||||
syscall::syscall!(syscall::SYS_WRITE, STDOUT, s.as_ptr(), s.len()) as i64;
|
||||
if result < 0 {
|
||||
return Err(core::fmt::Error);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ pub(crate) unsafe extern "C" fn start(argc: u64, argv: *const *const c_char, rsp
|
|||
fn main(argc: c_int, argv: *const *const c_char) -> c_int;
|
||||
}
|
||||
|
||||
// crate::env::debug_env();
|
||||
crate::env::debug_env();
|
||||
|
||||
let result = main(argc as i32, argv);
|
||||
|
||||
|
|
@ -23,6 +23,7 @@ pub(crate) unsafe extern "C" fn start(argc: u64, argv: *const *const c_char, rsp
|
|||
pub fn exit(code: u64) -> ! {
|
||||
unsafe {
|
||||
crate::sys::syscall::syscall!(crate::sys::syscall::SYS_EXIT, code);
|
||||
crate::sys::helpers::trap!();
|
||||
core::hint::unreachable_unchecked()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue