-w, -W, -r all working

This commit is contained in:
elvis
2022-04-29 01:26:31 +02:00
parent 59814f06db
commit b0b9310acc
4 changed files with 40 additions and 14 deletions

View File

@ -1259,7 +1259,6 @@ int reciveData(response_t *res, int expected) {
readnres = readn(fd_skt, &res->numfiles, sizeof(int));
if(readnres<=0) // readn sets errno
return -1;
if(res->rf)
free(res->rf);
res->rf = calloc(res->numfiles, sizeof(recivedFile_t));
@ -1267,6 +1266,7 @@ int reciveData(response_t *res, int expected) {
perror("calloc");
return -1;
}
// get files
for(int i=0;i<res->numfiles;++i) {
// read path
@ -1350,10 +1350,11 @@ _nofile:
// file purged
res->meerrno = 0;
// get number of files sent
readnres = readn(fd_skt, &res->numfiles, sizeof(int));
readnres = readn(fd_skt, &res->numfiles, sizeof(int64_t));
if(readnres<=0) // readn sets errno
return -1;
if(res->rf)
free(res->rf);
res->rf = calloc(res->numfiles, sizeof(recivedFile_t));
@ -1386,6 +1387,16 @@ _nofile:
readnres = readn(fd_skt, &res->rf[i].filelen, sizeof(int64_t));
if(readnres<=0) // readn sets errno
return -1;
// file has lenght 0 -> allocate memory but dont read
if(res->rf[i].filelen == 0) {
res->rf[i].file = calloc(1, sizeof(char));
if(!res->rf[i].file){
perror("calloc");
return -1;
}
continue;
}
res->rf[i].file = calloc(res->rf[i].filelen, sizeof(char));
if(!res->rf[i].file){
perror("calloc");