-r is working

This commit is contained in:
elvis
2022-04-27 21:18:25 +02:00
parent 5151418090
commit 8841ca95a0
8 changed files with 65 additions and 43 deletions

View File

@ -1,10 +1,12 @@
#define _POSIX_C_SOURCE 200809L
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fileQueue.h>
#include <util.h>
#define MAXNAMELEN 256
#define MAXNAMELEN 512
// creazione di un fileT
fileT* createFileT(char *f, int O_LOCK, int client, int open){
@ -26,13 +28,13 @@ fileT* createFileT(char *f, int O_LOCK, int client, int open){
file->size = 0;
file->valid = 0;
if ((file->filepath = malloc(sizeof(char)*MAXNAMELEN)) == NULL) {
if ((file->filepath = calloc(strnlen(f, MAXNAMELEN)+1, sizeof(char))) == NULL) {
perror("Malloc filepath");
destroyFile(file);
return NULL;
}
strncpy(file->filepath, f, MAXNAMELEN);
strncpy(file->filepath, f, strnlen(f, MAXNAMELEN));
// in seguito semplicemente facciamo realloc
if ((file->data = malloc(1)) == NULL) {
@ -49,6 +51,8 @@ int writeFileT(fileT *f, void *data, size_t size) {
return -1;
}
size = (size == 0)?1:size;
if ((f->data = realloc(f->data, f->valid + size)) == NULL) {
perror("Realloc content");
return -1;
@ -147,7 +151,6 @@ int enqueue(queueT *q, fileT* data) {
++q->len;
q->size += data->size;
UNLOCK_RETURN(&q->m, -1); // end me
return 0;
@ -318,17 +321,14 @@ int printQueue(FILE *stream, queueT *q) {
LOCK_RETURN(&q->m, -1); // begin me
UNLOCK_RETURN(&q->m, -1);
return 0;
nodeT *tmp = q->head;
fprintf(stream, "Lista file:");
fprintf(stream, "[Nome File] -> Dimensione in MB");
fprintf(stream, "Lista file:\n");
fprintf(stream, "[Nome File] -> Dimensione in MB\n");
while (tmp!=NULL) {
float res = ((float)(tmp->data)->size)/1000000; // in MB
// float res = ((float)(tmp->data)->valid)/1000000; // in MB
fprintf(stream, "[%s]\t-> %f MB\n", (tmp->data)->filepath, res);
fprintf(stream, "[%s] -> %f MB\n", (tmp->data)->filepath, res);
tmp = tmp->next;
}
@ -755,6 +755,8 @@ fileT* find(queueT *q, char *filepath) {
goto _end_find_in_queue;
}
UNLOCK_RETURN(&q->m, NULL); // end me
return res;