Create rm command

This commit is contained in:
Baptiste Wicht 2014-02-25 21:03:31 +01:00
parent 6d7fa31aaa
commit 0fe826a9a0
5 changed files with 53 additions and 2 deletions

3
.gitignore vendored
View File

@ -27,5 +27,6 @@ programs/pwd/pwd
programs/which/which
programs/readelf/readelf
programs/touch/touch
programs/cd/cd
programs/mkdir/mkdir
programs/rm/rm
programs/dist/

View File

@ -1,6 +1,6 @@
.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

Binary file not shown.

15
programs/rm/Makefile Normal file
View 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
View 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);
}