-
Notifications
You must be signed in to change notification settings - Fork 0
/
structura.c
executable file
·130 lines (102 loc) · 2.64 KB
/
structura.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "structura.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <string.h>
#include <pthread.h>
#include <arpa/inet.h>
#include <sys/stat.h>
#include <unistd.h>
#include <signal.h>
#include <fcntl.h>
#include <string.h>
#include <dirent.h>
#include <limits.h>
node *CreeateNode(char *fisier) {
struct node *Nod = malloc(sizeof(struct node));
strcpy(Nod -> NumeFisier, fisier);
Nod -> urm = NULL;
return Nod;
}
node * AddFile(node *Nod, char *filename) {
struct node *Nodint = CreeateNode(filename);
struct node *p = Nod;
while(p -> urm != NULL){
p = p -> urm;
}
p -> urm = Nodint;
return Nod;
}
void parcurgereFisiere(node *Nod) {
if(Nod != NULL) {
printf("{ ");
while(Nod -> urm != NULL) {
printf("%s -> ", Nod -> NumeFisier);
Nod = Nod -> urm;
}
printf("%s }.", Nod -> NumeFisier);
printf("\n");
}
}
void checkdir() {
struct stat info;
int fd;
if(lstat("server", &info) < 0) {
printf("director inexistent, acesta se creaza\n");
mkdir("server", 0777);
system("touch server/clientslist");
}
else {
if(S_ISDIR(info.st_mode)) {
printf("director existent\n");
if((fd = open("server/clientslist", O_CREAT | O_EXCL | O_WRONLY, S_IRWXU)) < 0) {
printf("Fisier existent\n");
close(fd);
}
else {
system("touch server/clientslist");
}
}
}
}
void PrintareAllFiles(node *allFiles) {
if(allFiles != NULL) {
parcurgereFisiere(allFiles);
printf("\n");
}
else {
printf("0 files found\n");
}
}
int FileAlreadyExistsInAllFiles(node *allFiles, char *filename) {
if(allFiles == NULL) {
return 0;
}
while(allFiles != NULL) {
if(strcmp(allFiles -> NumeFisier, filename) == 0) {
return 1;
}
allFiles = allFiles -> urm;
}
return 0;
}
node *AddToAllFiles(node *allFiles, char *filename) {
if(allFiles == NULL) {
struct node *nodInt = malloc(sizeof(struct node));
strcpy(nodInt -> NumeFisier, filename);
allFiles = nodInt;
allFiles -> urm = NULL;
return allFiles;
}
struct node *nodInt = malloc(sizeof(struct node));
strcpy(nodInt -> NumeFisier, filename);
nodInt -> urm = NULL;
struct node *nodParcurge = allFiles;
while(nodParcurge -> urm != NULL) {
nodParcurge = nodParcurge -> urm;
}
nodParcurge -> urm = nodInt;
return allFiles;
}