fixing 20 VS waring msg
[reactos.git] / reactos / tools / rdel.c
1 /* $Id$
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 #ifdef __WIN32__
14 # include <io.h>
15 #endif
16 #include <sys/types.h>
17 #include <sys/stat.h>
18
19 void
20 convertPath (char * pathToConvert)
21 {
22 while (*pathToConvert != 0)
23 {
24 if (*pathToConvert == '\\')
25 {
26 *pathToConvert = '/';
27 }
28 pathToConvert++;
29 }
30 }
31
32 #if 0
33 void
34 getDirectory (const char *filename, char * directorySpec)
35 {
36 int lengthOfDirectory;
37
38 if (strrchr (filename, '/') != 0)
39 {
40 lengthOfDirectory = strrchr (filename, '/') - filename;
41 strncpy (directorySpec, filename, lengthOfDirectory);
42 directorySpec [lengthOfDirectory] = '\0';
43 }
44 else
45 {
46 strcpy (directorySpec, ".");
47 }
48 }
49 #endif
50
51 void
52 getFilename (const char *filename, char * fileSpec)
53 {
54 if (strrchr (filename, '/') != 0)
55 {
56 strcpy (fileSpec, strrchr (filename, '/') + 1);
57 }
58 else
59 {
60 strcpy (fileSpec, filename);
61 }
62 }
63
64 int
65 main (int argc, char* argv[])
66 {
67 int justPrint = 0;
68 int idx;
69 int returnCode;
70
71 for (idx = 1; idx < argc; idx++)
72 {
73 convertPath (argv [idx]);
74
75 if (justPrint)
76 {
77 printf ("delete %s\n", argv [idx]);
78 }
79 else
80 {
81 #ifdef __WIN32__
82 _chmod (argv [idx], _S_IREAD | _S_IWRITE);
83 #else
84 chmod (argv [idx], 0666);
85 #endif
86 returnCode = remove (argv [idx]);
87 if (returnCode != 0 && errno != ENOENT)
88 {
89 /* Continue even if there is errors */
90 #if 0
91 printf ("Unlink of %s failed. Unlink returned %d.\n",
92 argv [idx],
93 returnCode);
94 return returnCode;
95 #endif
96 }
97 }
98 }
99
100 return 0;
101 }