xref: /reactos/boot/freeldr/tools/rdel.c (revision 8a978a17)
1 /*
2  * COPYRIGHT:             See COPYING in the top level directory
3  * PROGRAMMER:            Rex Jolliff (rex@lvcablemodem.com)
4  * PURPOSE:               Platform independent delete command
5  */
6 
7 #include <dirent.h>
8 #include <errno.h>
9 #include <limits.h>
10 #include <stdio.h>
11 #include <string.h>
12 #include <stdlib.h>
13 
14 void
15 convertPath (char * pathToConvert)
16 {
17   while (*pathToConvert != 0)
18   {
19     if (*pathToConvert == '\\')
20     {
21       *pathToConvert = '/';
22     }
23     pathToConvert++;
24   }
25 }
26 
27 void
28 getDirectory (const char *filename, char * directorySpec)
29 {
30   int  lengthOfDirectory;
31 
32   if (strrchr (filename, '/') != 0)
33   {
34     lengthOfDirectory = strrchr (filename, '/') - filename;
35     strncpy (directorySpec, filename, lengthOfDirectory);
36     directorySpec [lengthOfDirectory] = '\0';
37   }
38   else
39   {
40     strcpy (directorySpec, ".");
41   }
42 }
43 
44 void
45 getFilename (const char *filename, char * fileSpec)
46 {
47   if (strrchr (filename, '/') != 0)
48   {
49     strcpy (fileSpec, strrchr (filename, '/') + 1);
50   }
51   else
52   {
53     strcpy (fileSpec, filename);
54   }
55 }
56 
57 int
58 main (int argc, char* argv[])
59 {
60   int  justPrint = 0;
61   int  idx;
62   int  returnCode;
63 
64   for (idx = 1; idx < argc; idx++)
65   {
66     convertPath (argv [idx]);
67 
68     if (justPrint)
69     {
70       printf ("delete %s\n", argv [idx]);
71     }
72     else
73     {
74       returnCode = remove (argv [idx]);
75       if (returnCode != 0 && errno != ENOENT)
76       {
77       /* Continue even if there is errors */
78 #if 0
79         printf ("Unlink of %s failed.  Unlink returned %d.\n",
80                 argv [idx],
81                 returnCode);
82         return  returnCode;
83 #endif
84       }
85     }
86   }
87 
88   return  0;
89 }
90 
91 
92