ReactOS 0.4.15-dev-8102-g108db8f
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
16void
17convertPath (char * pathToConvert)
18{
19 while (*pathToConvert != 0)
20 {
21 if (*pathToConvert == '\\')
22 {
23 *pathToConvert = '/';
24 }
25 pathToConvert++;
26 }
27}
28
29void
30getDirectory (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
46void
47getFilename (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
59int
60main (int argc, char* argv[])
61{
62 int justPrint = 0;
63 int idx;
64 int returnCode;
65
66 for (idx = 1; idx < argc; idx++)
67 {
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
#define ENOENT
Definition: acclib.h:79
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
unsigned int idx
Definition: utils.c:41
int main()
Definition: test.c:6
#define printf
Definition: freeldr.h:97
const char * filename
Definition: ioapi.h:137
#define argv
Definition: mplay32.c:18
#define rmdir
Definition: syshdrs.h:70
void convertPath(char *pathToConvert)
Definition: rrmdir.c:17
void getDirectory(const char *filename, char *directorySpec)
Definition: rrmdir.c:30
void getFilename(const char *filename, char *fileSpec)
Definition: rrmdir.c:47
#define errno
Definition: errno.h:18
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)