apps: Add mkdir, chown and chmod
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
46ee0eb937
commit
3867a29a10
@ -3,26 +3,18 @@ function(luna_app SOURCE_FILE APP_NAME)
|
||||
target_compile_options(${APP_NAME} PRIVATE -Os ${COMMON_FLAGS} -Wno-write-strings)
|
||||
add_dependencies(${APP_NAME} libc)
|
||||
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)
|
||||
endfunction()
|
||||
|
||||
luna_app(init.cpp init)
|
||||
luna_app(env.cpp env)
|
||||
|
||||
luna_app(su.cpp su)
|
||||
target_link_libraries(su PRIVATE os)
|
||||
|
||||
luna_app(sh.cpp sh)
|
||||
target_link_libraries(sh PRIVATE os)
|
||||
|
||||
luna_app(cat.cpp cat)
|
||||
target_link_libraries(cat PRIVATE os)
|
||||
|
||||
luna_app(date.cpp date)
|
||||
target_link_libraries(date PRIVATE os)
|
||||
|
||||
luna_app(edit.cpp edit)
|
||||
target_link_libraries(edit PRIVATE os)
|
||||
|
||||
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
23
apps/chmod.cpp
Normal 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
23
apps/chown.cpp
Normal 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
23
apps/mkdir.cpp
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user