diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2023-02-10 16:02:19 +0100 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2023-02-10 16:02:19 +0100 |
| commit | f5a76d8eaba565e2a532faf659efe2848d605163 (patch) | |
| tree | 33889081d5f98e6c3e771f597086658e0aeaec05 /core | |
| parent | 55c86c04d3abfa597f9dc27ddc14159193f51ceb (diff) | |
add rm (using rmdir and unlink syscalls)
Diffstat (limited to 'core')
| -rw-r--r-- | core/rm.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/core/rm.c b/core/rm.c new file mode 100644 index 0000000..a9ea996 --- /dev/null +++ b/core/rm.c @@ -0,0 +1,25 @@ +#include "../lib/sys/rmdir.h" +#include "../lib/sys/unlink.h" +#include "../lib/sys/stat.h" +#include "../lib/sys/errno.h" +#include "../lib/io/io.h" + +int main(int argc, char **argv) +{ + stat_t st; + int err; + for (int i = 1; i < argc; ++i) { + if ((err = stat(argv[i], &st)) < 0) { + wff(STDERR_FD, "rm: %s %s\n", argv[i], errstr[-err]); + continue; + } + + if (st.mode & S_IFREG) { + unlink(argv[i]); + } else if (st.mode & S_IFDIR) { + rmdir(argv[i]); + } else { + wff(STDERR_FD, "rm %s not of type 'regular file' or 'directory'\n", argv[i]); + } + } +} |