Kernel/LibC/Userspace: Implement mkdir and creat
Touch now uses creat insteadd of open with O_CREAT flag
This commit is contained in:
17
userspace/mkdir/CMakeLists.txt
Normal file
17
userspace/mkdir/CMakeLists.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(mkdir CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(mkdir ${SOURCES})
|
||||
target_compile_options(mkdir PUBLIC -O2 -g)
|
||||
target_link_libraries(mkdir PUBLIC libc)
|
||||
|
||||
add_custom_target(mkdir-install
|
||||
COMMAND sudo cp ${CMAKE_CURRENT_BINARY_DIR}/mkdir ${BANAN_BIN}/
|
||||
DEPENDS mkdir
|
||||
USES_TERMINAL
|
||||
)
|
||||
23
userspace/mkdir/main.cpp
Normal file
23
userspace/mkdir/main.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.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 (mkdir(argv[i], 0755) == -1)
|
||||
{
|
||||
perror("mkdir");
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user