From 126edea1192189702cf93b743f5facbd02884142 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Wed, 25 Oct 2023 21:45:27 +0300 Subject: [PATCH] Userspace: implement basic rm command --- userspace/CMakeLists.txt | 1 + userspace/rm/CMakeLists.txt | 17 +++++++++++++++++ userspace/rm/main.cpp | 22 ++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 userspace/rm/CMakeLists.txt create mode 100644 userspace/rm/main.cpp diff --git a/userspace/CMakeLists.txt b/userspace/CMakeLists.txt index a1b64e04..9874d570 100644 --- a/userspace/CMakeLists.txt +++ b/userspace/CMakeLists.txt @@ -16,6 +16,7 @@ set(USERSPACE_PROJECTS mkdir mmap-shared-test poweroff + rm Shell snake stat diff --git a/userspace/rm/CMakeLists.txt b/userspace/rm/CMakeLists.txt new file mode 100644 index 00000000..672839c7 --- /dev/null +++ b/userspace/rm/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.26) + +project(rm CXX) + +set(SOURCES + main.cpp +) + +add_executable(rm ${SOURCES}) +target_compile_options(rm PUBLIC -O2 -g) +target_link_libraries(rm PUBLIC libc) + +add_custom_target(rm-install + COMMAND sudo cp ${CMAKE_CURRENT_BINARY_DIR}/rm ${BANAN_BIN}/ + DEPENDS rm + USES_TERMINAL +) diff --git a/userspace/rm/main.cpp b/userspace/rm/main.cpp new file mode 100644 index 00000000..42896b6c --- /dev/null +++ b/userspace/rm/main.cpp @@ -0,0 +1,22 @@ +#include +#include + +int main(int argc, char** argv) +{ + if (argc <= 1) + { + fprintf(stderr, "Missing operand\n"); + return 1; + } + + int ret = 0; + for (int i = 1; i < argc; i++) + { + if (unlink(argv[i]) == -1) + { + perror(argv[i]); + ret = 1; + } + } + return ret; +}