Rev 3386 | Rev 4327 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 3386 | Rev 4153 | ||
|---|---|---|---|
| Line 58... | Line 58... | ||
| 58 | {"follow", no_argument, 0, 'f'}, |
58 | {"follow", no_argument, 0, 'f'}, |
| 59 | {0, 0, 0, 0} |
59 | {0, 0, 0, 0} |
| 60 | }; |
60 | }; |
| 61 | 61 | ||
| 62 | 62 | ||
| 63 | void * help_cmd_mkdir(unsigned int level) |
63 | void help_cmd_mkdir(unsigned int level) |
| 64 | { |
64 | { |
| 65 | if (level == HELP_SHORT) { |
65 | if (level == HELP_SHORT) { |
| 66 | printf("`%s' creates a new directory\n", cmdname); |
66 | printf("`%s' creates a new directory\n", cmdname); |
| 67 | } else { |
67 | } else { |
| 68 | help_cmd_mkdir(HELP_SHORT); |
68 | help_cmd_mkdir(HELP_SHORT); |
| Line 77... | Line 77... | ||
| 77 | " -f, --follow Go to the new directory once created\n" |
77 | " -f, --follow Go to the new directory once created\n" |
| 78 | "Currently, %s is under development, some options don't work.\n", |
78 | "Currently, %s is under development, some options don't work.\n", |
| 79 | cmdname, cmdname); |
79 | cmdname, cmdname); |
| 80 | } |
80 | } |
| 81 | 81 | ||
| 82 | return CMD_VOID; |
82 | return; |
| 83 | } |
83 | } |
| 84 | 84 | ||
| 85 | /* This is kind of clunky, but effective for now */ |
85 | /* This is kind of clunky, but effective for now */ |
| 86 | static unsigned int |
86 | static unsigned int |
| 87 | create_directory(const char *path, unsigned int p) |
87 | create_directory(const char *path, unsigned int p) |
| Line 91... | Line 91... | ||
| 91 | char *dirs[255]; |
91 | char *dirs[255]; |
| 92 | unsigned int absolute = 0, i = 0, ret = 0; |
92 | unsigned int absolute = 0, i = 0, ret = 0; |
| 93 | 93 | ||
| 94 | /* Its a good idea to allocate path, plus we (may) need a copy of |
94 | /* Its a good idea to allocate path, plus we (may) need a copy of |
| 95 | * path to tokenize if parents are specified */ |
95 | * path to tokenize if parents are specified */ |
| 96 | if (NULL == (tmp = cli_strdup(path))) { |
96 | if (NULL == (tmp = strdup(path))) { |
| 97 | cli_error(CL_ENOMEM, "%s: path too big?", cmdname); |
97 | cli_error(CL_ENOMEM, "%s: path too big?", cmdname); |
| 98 | return 1; |
98 | return 1; |
| 99 | } |
99 | } |
| 100 | 100 | ||
| 101 | if (NULL == (wdp = (char *) malloc(PATH_MAX))) { |
101 | if (NULL == (wdp = (char *) malloc(PATH_MAX))) { |
| Line 126... | Line 126... | ||
| 126 | /* See if path[0] is a slash, if so we have to remember to append it */ |
126 | /* See if path[0] is a slash, if so we have to remember to append it */ |
| 127 | if (tmp[0] == '/') |
127 | if (tmp[0] == '/') |
| 128 | absolute = 1; |
128 | absolute = 1; |
| 129 | 129 | ||
| 130 | /* TODO: Canonify the path prior to tokenizing it, see below */ |
130 | /* TODO: Canonify the path prior to tokenizing it, see below */ |
| 131 | dirs[i] = cli_strtok(tmp, "/"); |
131 | dirs[i] = strtok(tmp, "/"); |
| 132 | while (dirs[i] && i < 255) |
132 | while (dirs[i] && i < 255) |
| 133 | dirs[++i] = cli_strtok(NULL, "/"); |
133 | dirs[++i] = strtok(NULL, "/"); |
| 134 | 134 | ||
| 135 | if (NULL == dirs[0]) |
135 | if (NULL == dirs[0]) |
| 136 | return 1; |
136 | return 1; |
| 137 | 137 | ||
| 138 | if (absolute == 1) { |
138 | if (absolute == 1) { |
| Line 179... | Line 179... | ||
| 179 | free(wdp); |
179 | free(wdp); |
| 180 | free(tmp); |
180 | free(tmp); |
| 181 | return ret; |
181 | return ret; |
| 182 | } |
182 | } |
| 183 | 183 | ||
| 184 | int * cmd_mkdir(char **argv) |
184 | int cmd_mkdir(char **argv) |
| 185 | { |
185 | { |
| 186 | unsigned int argc, create_parents = 0, i, ret = 0, follow = 0; |
186 | unsigned int argc, create_parents = 0, i, ret = 0, follow = 0; |
| 187 | unsigned int verbose = 0; |
187 | unsigned int verbose = 0; |
| 188 | int c, opt_ind; |
188 | int c, opt_ind; |
| 189 | char *cwd; |
189 | char *cwd; |