ReactOS 0.4.16-dev-338-g34e76ad
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
14void
15convertPath (char * pathToConvert)
16{
17 while (*pathToConvert != 0)
18 {
19 if (*pathToConvert == '\\')
20 {
21 *pathToConvert = '/';
22 }
23 pathToConvert++;
24 }
25}
26
27void
28getDirectory (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
44void
45getFilename (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
57int
58main (int argc, char* argv[])
59{
60 int justPrint = 0;
61 int idx;
62 int returnCode;
63
64 for (idx = 1; idx < argc; idx++)
65 {
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
#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
int remove
Definition: msacm.c:1366
void convertPath(char *pathToConvert)
Definition: rdel.c:15
void getDirectory(const char *filename, char *directorySpec)
Definition: rdel.c:28
void getFilename(const char *filename, char *fileSpec)
Definition: rdel.c:45
#define errno
Definition: errno.h:18
_CRT_RESTORE_GCC_WARNINGS _CRT_DISABLE_GCC_WARNINGS _Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)