add new bits to the compiler.h file
[newos.git] / apps / rm / main.c
blob3258feca7cb7ad955dd32c77bcfd59e6ae93dfbf
1 /*
2 rm: remove util.
3 Parameters: Filenames
4 exit : 1 when deleting one of the files failed
5 */
7 #include <sys/syscalls.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <unistd.h>
13 #define RMS_OK 0
14 #define RMS_FILE_IS_DIR 1
16 static int do_delete(const char *name)
18 struct file_stat stat;
19 int err = _kern_rstat(name,&stat);
21 if(err<0) return err;
23 if(stat.type == STREAM_TYPE_DIR) return RMS_FILE_IS_DIR;
25 return unlink(name);
28 int main(int argc,char *argv[])
30 int cnt;
31 const char *name;
32 int err;
33 const char *err_text;
34 int ret = 0;
36 if(argc <= 1){
38 printf("rm: Missing arguments\n");
39 ret = 1;
43 for(cnt=1;cnt<argc;cnt++){
44 name = argv[cnt];
45 err = do_delete(name);
47 if(err != 0){
48 ret = 1;
49 if(err == 1) {
50 err_text = "File is a directory";
51 } else {
52 err_text = strerror(err);
54 printf("rm: %s \n",err_text);
58 return ret;