summaryrefslogtreecommitdiff
path: root/src/commands/rm.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/commands/rm.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/commands/rm.c b/src/commands/rm.c
index 7d72c2d..8ce3e1c 100644
--- a/src/commands/rm.c
+++ b/src/commands/rm.c
@@ -40,16 +40,18 @@ static int short_arg(char c, char* next) {
return ARG_UNUSED;
}
-static void rm_file(char* path);
+static void rm_file (char* path);
-static bool rm_dir() {
- DIR* d = opendir(get_path_buffer());
+static bool rm_dir (void) {
+ DIR* d;
+ struct dirent* file;
+
+ d = opendir(get_path_buffer());
if (d == NULL) {
error_s("failed to stat '%s': %s\n", get_path_buffer(), strerror(errno));
return false;
}
- struct dirent* file;
while ((file = readdir(d)) != NULL) {
if (is_dot_dir(file->d_name)) continue;
rm_file(file->d_name);
@@ -82,9 +84,12 @@ static void rm_file(char* path) {
}
if (flags.prompt) {
+ char c;
+
fprintf(stderr, "delete '%s'? ", get_path_buffer());
fflush(stderr);
- char c = getchar();
+
+ c = getchar();
if (c != 'y' && c != 'Y') {
fprintf(stderr, "Skipping...\n");
pop_path_buffer(save);
@@ -102,6 +107,9 @@ static void rm_file(char* path) {
}
COMMAND(rm) {
+
+ int start, i;
+
if (argc < 1) {
global_help(help);
return EXIT_SUCCESS;
@@ -112,7 +120,7 @@ COMMAND(rm) {
flags.verbose = false;
flags.recurse = false;
- int start = parse_args(argc, argv, help, short_arg, NULL);
+ start = parse_args(argc, argv, help, short_arg, NULL);
#ifdef FRENCH
if (streql(argv[0], "-fr")) {
@@ -120,7 +128,7 @@ COMMAND(rm) {
}
#endif
- for (int i = start; i < argc; i++) {
+ for (i = start; i < argc; i++) {
rm_file(argv[i]);
}