diff --git a/flake.lock b/flake.lock deleted file mode 100644 index 57ae821..0000000 --- a/flake.lock +++ /dev/null @@ -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 -} diff --git a/flake.nix b/flake.nix deleted file mode 100644 index 7544475..0000000 --- a/flake.nix +++ /dev/null @@ -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; [ - ]); - }; - }); -} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..6fa913e --- /dev/null +++ b/shell.nix @@ -0,0 +1,10 @@ +{ pkgs ? import { } }: pkgs.mkShell { + buildInputs = with pkgs; [ + rustup + ]; + shellHook = '' + export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin + ''; + packages = (with pkgs; [ + ]); +} diff --git a/src/env.rs b/src/env.rs index d99753a..805d9a6 100644 --- a/src/env.rs +++ b/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 { fn getenv_inner(mut envp: EnvP, name: SharedThinCstr) -> Option { 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 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"))); + }) + } } diff --git a/src/io/mod.rs b/src/io/mod.rs index 4b89862..1db3bd4 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -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); } diff --git a/src/start.rs b/src/start.rs index 1acf981..e87eca7 100644 --- a/src/start.rs +++ b/src/start.rs @@ -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() } }