Skip to content

Commit

Permalink
Added free_flags to arg_parse.c and moved free_args to arg_parse.c.
Browse files Browse the repository at this point in the history
  • Loading branch information
omer committed Dec 5, 2017
1 parent da14019 commit ca64b9d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
11 changes: 11 additions & 0 deletions arg_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,14 @@ char *get_flags(char *buf, char *flags)
*flags = '\0';
return flags;
}

void free_args(char **args) {
for (int i = 0; i < _argc; i++) {
free(args[i]);
}
free(args);
}

void free_flags(char *flags) {
free(flags);
}
3 changes: 2 additions & 1 deletion arg_parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
int get_argc(char *s);
char *skip_flag(char *s);
char **get_args(char *s, int index);
void free_args(char **args);
char *get_flags(char *buf, char *flags);

void free_flags(char *flags);
#endif
8 changes: 1 addition & 7 deletions cmd_mains.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "misc.h"
#include "cmd_mains.h"
#include "arg_parse.h"

int rm_main(char *buf)
{
Expand Down Expand Up @@ -205,11 +206,4 @@ int cd_main(char *buf)

free_args(args);
return 0;
}

void free_args(char **args) {
for (int i = 0; i < _argc; i++) {
free(args[i]);
}
free(args);
}
1 change: 0 additions & 1 deletion cmd_mains.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ int cat(const char *name, int nflag);
int cat_main(char *buf);
int cd(const char *name);
int cd_main(char *buf);
void free_args(char **args);
#endif

0 comments on commit ca64b9d

Please sign in to comment.