-r is working
This commit is contained in:
@ -70,7 +70,7 @@ typedef struct recivedFile_s {
|
||||
typedef struct response_s {
|
||||
char ME[2]; // response
|
||||
int meerrno; // errno if sent
|
||||
int numfiles; // number of files if sent
|
||||
int64_t numfiles; // number of files if sent
|
||||
recivedFile_t *rf; // array of files
|
||||
} response_t;
|
||||
|
||||
@ -196,8 +196,8 @@ int openFile(const char* pathname, int flags) {
|
||||
errno = ENOTCONN;
|
||||
return -1;
|
||||
}
|
||||
if(isOpen(pathname, flags)) { // already open
|
||||
return -1;
|
||||
if(isOpen(pathname, flags) == 1) { // already open
|
||||
return 0;
|
||||
}
|
||||
|
||||
// invio al server la stringa "openFile|$(pathname)|$(flags)"
|
||||
@ -437,7 +437,7 @@ int readNFiles(int N, const char* dirname) {
|
||||
}
|
||||
|
||||
// invio al server la stringa "readNFile|$(N)"
|
||||
long len = strlen("readNFile")+1+((int)log10(N)+1)+1;
|
||||
long len = strlen("readNFile")+1+((int)log10((N?N:1))+1)+1;
|
||||
char *cmd = malloc(len);
|
||||
if(!cmd) {
|
||||
perror("malloc");
|
||||
@ -567,14 +567,13 @@ int writeFile(const char* pathname, const char* dirname) {
|
||||
}
|
||||
|
||||
// invio al server la stringa "writeFile|$(pathname)|$(size)"
|
||||
long len = strlen("writeFile")+1+strlen(pathname)+1+((int) log10(size)+1)+1;
|
||||
char *cmd = malloc(len);
|
||||
long len = strlen("writeFile")+1+strlen(pathname)+1+((int) log10(size?size:1)+1)+1;
|
||||
char *cmd = calloc(len, sizeof(char));
|
||||
if(!cmd) {
|
||||
perror("malloc");
|
||||
perror("calloc");
|
||||
free(content);
|
||||
return -1;
|
||||
}
|
||||
memset(cmd, 0, len);
|
||||
snprintf(cmd, len, "writeFile|%s|%zu", pathname, size);
|
||||
len = strnlen(cmd, len);
|
||||
|
||||
@ -1200,12 +1199,18 @@ int reciveData(response_t *res, int expected) {
|
||||
// ok response
|
||||
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);
|
||||
|
||||
if(res->numfiles < 0) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
res->rf = calloc(res->numfiles, sizeof(recivedFile_t));
|
||||
if(!res->rf){
|
||||
perror("calloc");
|
||||
@ -1513,7 +1518,7 @@ int isOpen(const char *pathname, const int flags) {
|
||||
|
||||
files_t *tmp = openedFiles->f;
|
||||
while(tmp) {
|
||||
if(strcmp(tmp->filename, pathname) == 0 && (tmp->locked==(flags&O_LOCK)))
|
||||
if(strcmp(tmp->filename, pathname) == 0 && (tmp->locked || !(flags&O_LOCK)))
|
||||
return 1;
|
||||
tmp = tmp->next;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user