mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-13 06:29:47 -04:00
Create rm command
This commit is contained in:
parent
6d7fa31aaa
commit
0fe826a9a0
3
.gitignore
vendored
3
.gitignore
vendored
@ -27,5 +27,6 @@ programs/pwd/pwd
|
|||||||
programs/which/which
|
programs/which/which
|
||||||
programs/readelf/readelf
|
programs/readelf/readelf
|
||||||
programs/touch/touch
|
programs/touch/touch
|
||||||
programs/cd/cd
|
programs/mkdir/mkdir
|
||||||
|
programs/rm/rm
|
||||||
programs/dist/
|
programs/dist/
|
@ -1,6 +1,6 @@
|
|||||||
.PHONY: dist default clean force_look
|
.PHONY: dist default clean force_look
|
||||||
|
|
||||||
PROGRAMS=one hello long loop longone longtwo keyboard tsh cpuid shutdown reboot args stat cat which readelf touch mkdir
|
PROGRAMS=one hello long loop longone longtwo keyboard tsh cpuid shutdown reboot args stat cat which readelf touch mkdir rm
|
||||||
|
|
||||||
default: dist
|
default: dist
|
||||||
|
|
||||||
|
Binary file not shown.
15
programs/rm/Makefile
Normal file
15
programs/rm/Makefile
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
.PHONY: default clean
|
||||||
|
|
||||||
|
default: rm
|
||||||
|
|
||||||
|
include ../../cpp.mk
|
||||||
|
|
||||||
|
%.cpp.o: src/%.cpp
|
||||||
|
$(CC) -c $< -o $@ $(PROGRAM_FLAGS)
|
||||||
|
|
||||||
|
rm: main.cpp.o
|
||||||
|
$(CC) -o rm main.cpp.o $(PROGRAM_LINK_FLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *.cpp.o
|
||||||
|
rm -rf rm
|
35
programs/rm/src/main.cpp
Normal file
35
programs/rm/src/main.cpp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
//=======================================================================
|
||||||
|
// Copyright Baptiste Wicht 2013-2014.
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
//=======================================================================
|
||||||
|
|
||||||
|
#include <file.hpp>
|
||||||
|
#include <system.hpp>
|
||||||
|
#include <errors.hpp>
|
||||||
|
#include <print.hpp>
|
||||||
|
#include <flags.hpp>
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]){
|
||||||
|
if(argc == 1){
|
||||||
|
print_line("Usage: rm file_path");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto fd = open(argv[1]);
|
||||||
|
|
||||||
|
if(fd.valid()){
|
||||||
|
auto result = rm(argv[1]);
|
||||||
|
|
||||||
|
if(result < 0){
|
||||||
|
printf("rm: error: %s\n", std::error_message(-result));
|
||||||
|
}
|
||||||
|
|
||||||
|
close(*fd);
|
||||||
|
} else {
|
||||||
|
printf("rm: error: %s\n", std::error_message(fd.error()));
|
||||||
|
}
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user