apps: Add mkdir, chown and chmod
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-04-08 14:47:58 +02:00
parent 46ee0eb937
commit 3867a29a10
Signed by: apio
GPG Key ID: B8A7D06E42258954
4 changed files with 73 additions and 12 deletions

View File

@ -3,26 +3,18 @@ function(luna_app SOURCE_FILE APP_NAME)
target_compile_options(${APP_NAME} PRIVATE -Os ${COMMON_FLAGS} -Wno-write-strings) target_compile_options(${APP_NAME} PRIVATE -Os ${COMMON_FLAGS} -Wno-write-strings)
add_dependencies(${APP_NAME} libc) add_dependencies(${APP_NAME} libc)
target_include_directories(${APP_NAME} PRIVATE ${LUNA_BASE}/usr/include) target_include_directories(${APP_NAME} PRIVATE ${LUNA_BASE}/usr/include)
target_link_libraries(${APP_NAME} PRIVATE os)
install(TARGETS ${APP_NAME} DESTINATION ${LUNA_ROOT}/initrd/bin) install(TARGETS ${APP_NAME} DESTINATION ${LUNA_ROOT}/initrd/bin)
endfunction() endfunction()
luna_app(init.cpp init) luna_app(init.cpp init)
luna_app(env.cpp env) luna_app(env.cpp env)
luna_app(su.cpp su) luna_app(su.cpp su)
target_link_libraries(su PRIVATE os)
luna_app(sh.cpp sh) luna_app(sh.cpp sh)
target_link_libraries(sh PRIVATE os)
luna_app(cat.cpp cat) luna_app(cat.cpp cat)
target_link_libraries(cat PRIVATE os)
luna_app(date.cpp date) luna_app(date.cpp date)
target_link_libraries(date PRIVATE os)
luna_app(edit.cpp edit) luna_app(edit.cpp edit)
target_link_libraries(edit PRIVATE os)
luna_app(ls.cpp ls) luna_app(ls.cpp ls)
target_link_libraries(ls PRIVATE os) luna_app(chown.cpp chown)
luna_app(chmod.cpp chmod)
luna_app(mkdir.cpp mkdir)

23
apps/chmod.cpp Normal file
View File

@ -0,0 +1,23 @@
#include <os/ArgumentParser.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char** argv)
{
StringView mode_string;
StringView path;
os::ArgumentParser parser;
parser.add_positional_argument(mode_string, "mode"_sv, true);
parser.add_positional_argument(path, "path"_sv, true);
parser.parse(argc, argv);
mode_t mode = (mode_t)strtoul(mode_string.chars(), NULL, 8);
if (chmod(path.chars(), mode) < 0)
{
perror("chmod");
return 1;
}
}

23
apps/chown.cpp Normal file
View File

@ -0,0 +1,23 @@
#include <os/ArgumentParser.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char** argv)
{
StringView user;
StringView path;
os::ArgumentParser parser;
parser.add_positional_argument(user, "user"_sv, true);
parser.add_positional_argument(path, "path"_sv, true);
parser.parse(argc, argv);
u32 id = (u32)strtoul(user.chars(), NULL, 0);
if (chown(path.chars(), id, id) < 0)
{
perror("chown");
return 1;
}
}

23
apps/mkdir.cpp Normal file
View File

@ -0,0 +1,23 @@
#include <os/ArgumentParser.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
int main(int argc, char** argv)
{
StringView path;
StringView mode_string;
os::ArgumentParser parser;
parser.add_positional_argument(path, "path"_sv, true);
parser.add_positional_argument(mode_string, "mode"_sv, "755"_sv);
parser.parse(argc, argv);
mode_t mode = (mode_t)strtoul(mode_string.chars(), NULL, 8);
if (mkdir(path.chars(), mode) < 0)
{
perror("mkdir");
return 1;
}
}