2012-12-09 16:44:45 +00:00
|
|
|
/*
|
2002-06-13 00:39:49 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROGRAMMER: Rex Jolliff (rex@lvcablemodem.com)
|
2016-11-12 20:53:49 +00:00
|
|
|
* PURPOSE: Platform independent delete command
|
2002-06-13 00:39:49 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2007-10-19 23:21:45 +00:00
|
|
|
void
|
2002-06-13 00:39:49 +00:00
|
|
|
convertPath (char * pathToConvert)
|
|
|
|
{
|
|
|
|
while (*pathToConvert != 0)
|
|
|
|
{
|
|
|
|
if (*pathToConvert == '\\')
|
|
|
|
{
|
|
|
|
*pathToConvert = '/';
|
|
|
|
}
|
|
|
|
pathToConvert++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
getDirectory (const char *filename, char * directorySpec)
|
|
|
|
{
|
|
|
|
int lengthOfDirectory;
|
|
|
|
|
|
|
|
if (strrchr (filename, '/') != 0)
|
|
|
|
{
|
|
|
|
lengthOfDirectory = strrchr (filename, '/') - filename;
|
|
|
|
strncpy (directorySpec, filename, lengthOfDirectory);
|
|
|
|
directorySpec [lengthOfDirectory] = '\0';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strcpy (directorySpec, ".");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
getFilename (const char *filename, char * fileSpec)
|
|
|
|
{
|
|
|
|
if (strrchr (filename, '/') != 0)
|
|
|
|
{
|
|
|
|
strcpy (fileSpec, strrchr (filename, '/') + 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strcpy (fileSpec, filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-19 23:21:45 +00:00
|
|
|
int
|
2002-06-13 00:39:49 +00:00
|
|
|
main (int argc, char* argv[])
|
|
|
|
{
|
|
|
|
int justPrint = 0;
|
|
|
|
int idx;
|
|
|
|
int returnCode;
|
|
|
|
|
|
|
|
for (idx = 1; idx < argc; idx++)
|
|
|
|
{
|
|
|
|
convertPath (argv [idx]);
|
|
|
|
|
|
|
|
if (justPrint)
|
|
|
|
{
|
|
|
|
printf ("delete %s\n", argv [idx]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
returnCode = remove (argv [idx]);
|
|
|
|
if (returnCode != 0 && errno != ENOENT)
|
|
|
|
{
|
|
|
|
/* Continue even if there is errors */
|
|
|
|
#if 0
|
2007-10-19 23:21:45 +00:00
|
|
|
printf ("Unlink of %s failed. Unlink returned %d.\n",
|
2002-06-13 00:39:49 +00:00
|
|
|
argv [idx],
|
|
|
|
returnCode);
|
|
|
|
return returnCode;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|