summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorAbdellah El Morabit <nsrddyn@gmail.com>2025-02-24 08:48:26 +0100
committerAbdellah El Morabit <nsrddyn@gmail.com>2025-02-24 08:48:26 +0100
commit84785a1cf4a8505a6c65d19afcd9656b19822711 (patch)
treed64293eda2b74f6503b4acb1378974f71b3fe26f /main.c
parentc887a71add3ebb8ed5bf1436c2746651b1e7b640 (diff)
i was getting errors becasue i was passing structures into the execute structure while it was expecting a const char; but i ended up splitting up the char using the split_command and passing thazt result into the variable which apparently fixes the problem
Diffstat (limited to 'main.c')
-rw-r--r--main.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/main.c b/main.c
index dcad1f2..f1feecf 100644
--- a/main.c
+++ b/main.c
@@ -42,9 +42,11 @@ void remove_file(const char *path);
void remove_dir(const char *path); // trying to delete the folder and the files init recursively
-void copy_files(struct split_arg argument);
+// void copy_files(struct split_arg argument);
+void copy_files(const char *arg);
-void move_files(struct split_arg argument);
+// void move_files(struct split_arg argument);
+void move_files(const char* arg);
void print_cdirectory(const char *arg);
@@ -148,7 +150,8 @@ void remove_dir(const char *path) {
perror("failed to delete the directory");
} else {
struct dirent *entry;
- const DIR *dP = opendir(path);
+ // cant be a const because inserting it into the readdir functions causes a warning becasue it expects a non const dir variable
+ DIR *dP = opendir(path);
if (dP == NULL) {
perror("failed to open the directory to delete the files recursively");
@@ -185,10 +188,11 @@ void change_ownership(const char *path) {
}
}
-void copy_files(const struct split_arg argument) {
+void copy_files(const char *arg) {
// split the argument into the source and destination
// make a copy of the source file in the destination file
int c;
+ struct split_arg argument = split_argument((struct command){.arg = (char *)arg});
FILE *pold_file = fopen(argument.source, "r");
if (pold_file == NULL) {
@@ -209,7 +213,10 @@ void copy_files(const struct split_arg argument) {
fclose(pold_file);
}
-void move_files(const struct split_arg argument) {
+void move_files(const char *arg) {
+
+ struct split_arg argument = split_argument((struct command){.arg = (char *)arg});
+
if (remove(argument.source) != 0) {
perror("failed while trying to move the file");
}