-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew.c
39 lines (36 loc) · 1.02 KB
/
new.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "commands.h"
#include "utils.h"
int command_new(Cli_args *args, Arena *arena)
{
bool is_dir_command = args->new_dir_name[0] != NULL;
bool is_file_command = args->new_file_name[0] != NULL;
int success;
if (is_dir_command)
{
for (int i = 0; i < args->num_dir_or_files; i++)
{
success = mkdir(args->new_dir_name[i], 0700);
if (success != 0)
{
fprintf(stderr, "Error creating directory: %s\n", args->new_dir_name[i]);
return EXIT_FAILURE;
}
}
return EXIT_SUCCESS;
}
if (is_file_command)
{
for (int i = 0; i < args->num_dir_or_files; i++)
{
FILE *file = fopen(args->new_file_name[i], "wx");
if (file == NULL)
{
fprintf(stderr, "Error creating file: %s\n", args->new_file_name[i]);
return EXIT_FAILURE;
}
fclose(file);
}
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
}