ReactOS  0.4.14-dev-991-g696cdc6
rdel.c
Go to the documentation of this file.
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 
static int argc
Definition: ServiceArgs.c:12
void getFilename(const char *filename, char *fileSpec)
Definition: rdel.c:45
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
int errno
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
#define argv
Definition: mplay32.c:18
const char * filename
Definition: ioapi.h:135
unsigned int idx
Definition: utils.c:41
void convertPath(char *pathToConvert)
Definition: rdel.c:15
int main(int argc, char *argv[])
Definition: rdel.c:58
void getDirectory(const char *filename, char *directorySpec)
Definition: rdel.c:28
Definition: arc.h:46
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
int remove
Definition: msacm.c:1365
#define printf
Definition: config.h:203