diff --git a/userspace/CMakeLists.txt b/userspace/CMakeLists.txt index 7acbbd8105..df44666714 100644 --- a/userspace/CMakeLists.txt +++ b/userspace/CMakeLists.txt @@ -14,6 +14,7 @@ set(USERSPACE_PROJECTS test touch u8sum + whoami yes ) diff --git a/userspace/whoami/CMakeLists.txt b/userspace/whoami/CMakeLists.txt new file mode 100644 index 0000000000..392d1c3aab --- /dev/null +++ b/userspace/whoami/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.26) + +project(whoami CXX) + +set(SOURCES + main.cpp +) + +add_executable(whoami ${SOURCES}) +target_compile_options(whoami PUBLIC -O2 -g) +target_link_libraries(whoami PUBLIC libc ban) + +add_custom_target(whoami-install + COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/whoami ${BANAN_BIN}/ + DEPENDS whoami +) diff --git a/userspace/whoami/main.cpp b/userspace/whoami/main.cpp new file mode 100644 index 0000000000..a042c569c7 --- /dev/null +++ b/userspace/whoami/main.cpp @@ -0,0 +1,16 @@ +#include +#include +#include + +int main() +{ + auto* pw = getpwuid(geteuid()); + if (pw == nullptr) + { + printf("unknown user %d\n", geteuid()); + return 1; + } + printf("%s\n", pw->pw_name); + endpwent(); + return 0; +}