ReactOS  0.4.14-dev-991-g696cdc6
rrmdir.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  * Casper S. Hornstrup (chorns@users.sourceforge.net)
5  * PURPOSE: Platform independent remove directory command
6  */
7 
8 #include <dirent.h>
9 #include <errno.h>
10 #include <limits.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include <stdlib.h>
14 #include <unistd.h>
15 
16 void
17 convertPath (char * pathToConvert)
18 {
19  while (*pathToConvert != 0)
20  {
21  if (*pathToConvert == '\\')
22  {
23  *pathToConvert = '/';
24  }
25  pathToConvert++;
26  }
27 }
28 
29 void
30 getDirectory (const char *filename, char * directorySpec)
31 {
32  int lengthOfDirectory;
33 
34  if (strrchr (filename, '/') != 0)
35  {
36  lengthOfDirectory = strrchr (filename, '/') - filename;
37  strncpy (directorySpec, filename, lengthOfDirectory);
38  directorySpec [lengthOfDirectory] = '\0';
39  }
40  else
41  {
42  strcpy (directorySpec, ".");
43  }
44 }
45 
46 void
47 getFilename (const char *filename, char * fileSpec)
48 {
49  if (strrchr (filename, '/') != 0)
50  {
51  strcpy (fileSpec, strrchr (filename, '/') + 1);
52  }
53  else
54  {
55  strcpy (fileSpec, filename);
56  }
57 }
58 
59 int
60 main (int argc, char* argv[])
61 {
62  int justPrint = 0;
63  int idx;
64  int returnCode;
65 
66  for (idx = 1; idx < argc; idx++)
67  {
68  convertPath (argv [idx]);
69 
70  if (justPrint)
71  {
72  printf ("remove %s\n", argv [idx]);
73  }
74  else
75  {
76  returnCode = rmdir (argv [idx]);
77  if (returnCode != 0 && errno != ENOENT)
78  {
79  /* Continue even if there is errors */
80 #if 0
81  printf ("Rmdir of %s failed. Rmdir returned %d.\n",
82  argv [idx],
83  returnCode);
84  return returnCode;
85 #endif
86  }
87  }
88  }
89 
90  return 0;
91 }
92 
93 
static int argc
Definition: ServiceArgs.c:12
void getFilename(const char *filename, char *fileSpec)
Definition: rrmdir.c:47
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
void convertPath(char *pathToConvert)
Definition: rrmdir.c:17
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
void getDirectory(const char *filename, char *directorySpec)
Definition: rrmdir.c:30
unsigned int idx
Definition: utils.c:41
int main(int argc, char *argv[])
Definition: rrmdir.c:60
Definition: arc.h:46
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define rmdir
Definition: syshdrs.h:70
#define printf
Definition: config.h:203