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