-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinked_dir.c
More file actions
56 lines (52 loc) · 1.42 KB
/
Copy pathlinked_dir.c
File metadata and controls
56 lines (52 loc) · 1.42 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "main.h"
location* linked_dir()
{
char *token;
char *env = _getenv("PWD");
DIR *dir = opendir("/");
location *current, *head, *tmp;
char curr_path[1024] = "";
head = malloc(sizeof(location));
if (head == NULL)
{
perror("Can't initiate memory location of the head node");
kill(getpid(), SIGINT);
}
if (dir == NULL)
{
perror("Can't open the root directory\n");
kill(getpid(), SIGINT);
}
head->dir = dir;
head->path = env;
head->next = NULL;
// token = _strtok(env, "/");
// for (current = head; token != NULL; token = _strtok(NULL, "/"))
// {
// tmp = malloc(sizeof(location));
// if (tmp == NULL)
// {
// perror("Can't initiate memery for tmp!");
// exit(98);
// }
// _strcat(curr_path, "/");
// _strcat(curr_path, token);
// // printf("Here is the current path %s\n", curr_path);
// tmp->dir = opendir(curr_path);
// if (tmp->dir == NULL)
// {
// dprintf(2, "Can't open directory: %s\n", curr_path);
// exit(98);
// }
// tmp->path = curr_path;
// tmp->next = NULL;
// current->next = tmp;
// }
// current = head;
// while (current != NULL)
// {
// printf("%s\n", current->path);
// current = current->next;
// }
return(head);
}