fixed -W, working on -r

This commit is contained in:
elvis
2022-04-25 20:24:55 +02:00
parent d8a0220ade
commit e67d3b5580
8 changed files with 72 additions and 105 deletions

View File

@ -196,6 +196,10 @@ int main(int argc, char* argv[]) {
goto _cleanup;
}
if(cmds) {
destroyCommandList(cmds);
}
return 0;
_cleanup:
@ -217,9 +221,9 @@ void destroyCommandList(cmd_t *l) {
while (l) {
tmp = l;
free(l->arg);
l = l->next;
free(tmp->arg);
free(tmp);
}
}
@ -322,8 +326,10 @@ int execute(cmd_t *l, int print) {
if(!ok)
printf("errore\n");
}
if(!ok)
if(!ok) {
closeConnection(tmp->arg);
return 0; // no socket to connect, nothing to do
}
// we only read the first -f, no error reported if more than one is
// specified
tmp = NULL;
@ -398,7 +404,7 @@ int execute(cmd_t *l, int print) {
case 'D':
if(Dir)
free(Dir);
Dir = malloc(strnlen(tmp->arg, MAXARGLENGTH)+1);
Dir = calloc(strnlen(tmp->arg, MAXARGLENGTH)+1, sizeof(char));
strncpy(Dir, tmp->arg, strnlen(tmp->arg, MAXARGLENGTH));
if (setDirectory(Dir, 1) == -1) {
@ -417,7 +423,7 @@ int execute(cmd_t *l, int print) {
case 'd':
if(dir)
free(dir);
dir = malloc(strnlen(tmp->arg, MAXARGLENGTH)+1);
dir = calloc(strnlen(tmp->arg, MAXARGLENGTH)+1, sizeof(char));
strncpy(dir, tmp->arg, strnlen(tmp->arg, MAXARGLENGTH));
if(setDirectory(dir, 0) == -1) {
@ -569,9 +575,10 @@ int cmd_W(char *filelist, char *Dir, int print) {
perror("malloc");
return -1;
}
strncpy(tofree, filelist, strnlen(filelist, MAXARGLENGTH));
memset(tofree, 0, strnlen(filelist, MAXARGLENGTH)+1);
strncpy(tofree, filelist, strnlen(filelist, MAXARGLENGTH)+1);
char *token;
char *token = NULL;
char *string = tofree;
if (print == 1) {
@ -631,13 +638,14 @@ int cmd_r(char *filelist, char *dir, int print) {
// we copy filelist because we are nice
char *tofree = malloc(strnlen(filelist, MAXARGLENGTH)+1);
memset(tofree, 0, strnlen(filelist, MAXARGLENGTH)+1);
if(!tofree) {
perror("malloc");
return -1;
}
strncpy(tofree, filelist, strnlen(filelist, MAXARGLENGTH));
char *token;
char *token = NULL;
char *string = tofree;
if (print) {
@ -663,7 +671,7 @@ int cmd_r(char *filelist, char *dir, int print) {
void *buf = NULL;
size_t size = -1;
printInfo(0, stdout);
// printInfo(0, stdout);
// read the content of the file
if (ok && readFile(token, &buf, &size) == -1) {
ok = 0;