forked from Bananymous/banan-os
Userspace: implement basic rm command
This commit is contained in:
parent
74bfb930f2
commit
126edea119
|
@ -16,6 +16,7 @@ set(USERSPACE_PROJECTS
|
|||
mkdir
|
||||
mmap-shared-test
|
||||
poweroff
|
||||
rm
|
||||
Shell
|
||||
snake
|
||||
stat
|
||||
|
|
|
@ -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
|
||||
)
|
|
@ -0,0 +1,22 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
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;
|
||||
}
|
Loading…
Reference in New Issue