started fixing bugs
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
#include <fileQueue.h>
|
||||
#include <util.h>
|
||||
|
||||
#define NAMELEN 256
|
||||
#define MAXNAMELEN 256
|
||||
|
||||
// creazione di un fileT
|
||||
fileT* createFileT(char *f, int O_LOCK, int client, int open){
|
||||
@ -12,30 +12,31 @@ fileT* createFileT(char *f, int O_LOCK, int client, int open){
|
||||
|
||||
fileT *file = malloc(sizeof(fileT));
|
||||
|
||||
if (f == NULL) {
|
||||
if (file == NULL) {
|
||||
perror("Malloc createFileT");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
f->O_LOCK = (O_LOCK == 0)? 0 : 1;
|
||||
f->owner = client;
|
||||
f->open = (open == 0)? 0 : 1;
|
||||
f->size = 0;
|
||||
f->valid = 0;
|
||||
file->O_LOCK = (O_LOCK == 0)? 0 : 1;
|
||||
file->owner = client;
|
||||
file->open = (open == 0)? 0 : 1;
|
||||
file->size = 0;
|
||||
file->valid = 0;
|
||||
|
||||
if ((f->filepath = malloc(sizeof(char)*NAMELEN)) == NULL) {
|
||||
if ((file->filepath = malloc(sizeof(char)*MAXNAMELEN)) == NULL) {
|
||||
perror("Malloc filepath");
|
||||
destroyFile(f);
|
||||
destroyFile(file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strncpy(f->filepath, f, NAMELEN);
|
||||
strncpy(file->filepath, f, MAXNAMELEN);
|
||||
|
||||
if ((f->data = malloc(1)) == NULL) { // così semplicemente facciamo realloc
|
||||
// in seguito semplicemente facciamo realloc
|
||||
if ((file->data = malloc(1)) == NULL) {
|
||||
perror("Malloc content");
|
||||
return NULL;
|
||||
}
|
||||
return f;
|
||||
return file;
|
||||
}
|
||||
|
||||
// append su fileT
|
||||
@ -53,6 +54,7 @@ int writeFileT(fileT *f, void *data, size_t size) {
|
||||
memcpy((char*) f->data + f->valid, data, size);
|
||||
f->valid = f->valid + size;
|
||||
f->size = (f->valid>f->size)?f->valid:f->size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// destroy fileT
|
||||
@ -126,15 +128,15 @@ int enqueue(queueT *q, fileT* data) {
|
||||
|
||||
newNode->data = data;
|
||||
newNode->next = NULL;
|
||||
nodeT *tmp = queue->head;
|
||||
nodeT *tmp = q->head;
|
||||
|
||||
if (q->head == NULL)
|
||||
q->head = newNode;
|
||||
else {
|
||||
while (tmp->next)
|
||||
tmp = temp->next;
|
||||
tmp = tmp->next;
|
||||
|
||||
temp->next = newNode;
|
||||
tmp->next = newNode;
|
||||
}
|
||||
|
||||
q->tail = newNode;
|
||||
@ -228,14 +230,8 @@ fileT ** dequeueN(queueT *q, char *filepath, size_t s) {
|
||||
goto _end_dequeueN;
|
||||
}
|
||||
|
||||
if ((tmp->data)->open == 0 || ((tmp->data)->O_LOCK && (tmp->data)->owner != owner)) {
|
||||
// if file non è aperto o la lock non è del owner
|
||||
errno = EPERM;
|
||||
goto _end_dequeueN;
|
||||
}
|
||||
|
||||
fileT **returnList = NULL; // lista dei file rimossi
|
||||
nodeT *tmp = NULL;
|
||||
tmp = NULL;
|
||||
|
||||
returnList = calloc(1, sizeof(fileT*));
|
||||
returnList[0] = NULL;
|
||||
|
||||
Reference in New Issue
Block a user