From a6aa048be01aecd5b1ea43f71afaf3b2c74ef429 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 15 Oct 2024 23:41:18 +0300 Subject: [PATCH] userspace: Implement `env` as an executable --- userspace/programs/CMakeLists.txt | 1 + userspace/programs/env/CMakeLists.txt | 9 +++++++++ userspace/programs/env/main.cpp | 13 +++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 userspace/programs/env/CMakeLists.txt create mode 100644 userspace/programs/env/main.cpp diff --git a/userspace/programs/CMakeLists.txt b/userspace/programs/CMakeLists.txt index a66a8a7b..7f1a7b61 100644 --- a/userspace/programs/CMakeLists.txt +++ b/userspace/programs/CMakeLists.txt @@ -8,6 +8,7 @@ set(USERSPACE_PROGRAMS dhcp-client DynamicLoader echo + env getopt http-server id diff --git a/userspace/programs/env/CMakeLists.txt b/userspace/programs/env/CMakeLists.txt new file mode 100644 index 00000000..39f69fa7 --- /dev/null +++ b/userspace/programs/env/CMakeLists.txt @@ -0,0 +1,9 @@ +set(SOURCES + main.cpp +) + +add_executable(env ${SOURCES}) +banan_link_library(env ban) +banan_link_library(env libc) + +install(TARGETS env OPTIONAL) diff --git a/userspace/programs/env/main.cpp b/userspace/programs/env/main.cpp new file mode 100644 index 00000000..0adaf42b --- /dev/null +++ b/userspace/programs/env/main.cpp @@ -0,0 +1,13 @@ +#include + +extern char** environ; + +int main() +{ + if (!environ) + return 0; + char** current = environ; + while (*current) + printf("%s\n", *current++); + return 0; +}