This commit is contained in:
elvis
2022-04-24 13:03:00 +02:00

View File

@ -34,6 +34,31 @@
// #define ME "52" // not used
#define MESE "55" // server error
#define printOpenedFiles(str) \
fprintf(stdout, "\nInside of function: %s\n", __func__); \
fprintf(stdout, "\t[%s]\n", str); \
fprintf(stdout, "\tcreatedAndlocked: %s\n", openedFiles->createdAndLocked); \
fprintf(stdout, "\tf: %p\n", (void *)openedFiles->f); \
fprintf(stdout, "\tnumOfFiles: %d\n", openedFiles->numOfFiles); \
fprintf(stdout, "\tout: %p\n", (void *)openedFiles->out); \
fprintf(stdout, "\tvalidrDir: %d\n", openedFiles->validrDir); \
fprintf(stdout, "\trDir: %p\n", (void *)openedFiles->rDir); \
fprintf(stdout, "\tvalidwDir: %d\n", openedFiles->validwDir); \
fprintf(stdout, "\twDir: %p\n", (void *)openedFiles->wDir); \
fflush(stdout); \
// -----------------------------------------------------------------------------
/* structs */
typedef struct files_s {
@ -98,6 +123,9 @@ int createOpenedFiles(void);
// -----------------------------------------------------------------------------
int openConnection(const char* sockname, int msec, const struct timespec abstime) {
printOpenedFiles("before");
if(!sockname){
errno = EINVAL;
return -1;
@ -150,10 +178,14 @@ int openConnection(const char* sockname, int msec, const struct timespec abstime
}
strncpy(socketName, sockname, sizeof(socketName)-1);
printOpenedFiles("after");
return 0;
}
int closeConnection(const char* sockname) {
printOpenedFiles("before");
if (!sockname || strncmp(socketName, sockname, sizeof(socketName)) != 0) {
errno = EINVAL;
return -1;
@ -174,6 +206,9 @@ int closeConnection(const char* sockname) {
}
int openFile(const char* pathname, int flags) {
printOpenedFiles("before");
if(!pathname){
errno = EINVAL;
return -1;
@ -291,10 +326,15 @@ int openFile(const char* pathname, int flags) {
free(res);
free(cmd);
printOpenedFiles("after");
return 0;
}
int readFile(const char* pathname, void** buf, size_t* size) {
printOpenedFiles("before");
if(!pathname) {
errno = EINVAL;
return -1;
@ -413,6 +453,9 @@ int readFile(const char* pathname, void** buf, size_t* size) {
}
int readNFiles(int N, const char* dirname) {
printOpenedFiles("before");
if(!dirname) {
errno = EINVAL;
return -1;
@ -493,6 +536,7 @@ int readNFiles(int N, const char* dirname) {
}
int writeFile(const char* pathname, const char* dirname) {
printOpenedFiles("before");
if(!pathname) {
errno = EINVAL;
return -1;
@ -674,10 +718,14 @@ int writeFile(const char* pathname, const char* dirname) {
free(cmd);
free(content);
printOpenedFiles("after");
return 0;
}
int appendToFile(const char* pathname, void* buf, size_t size, const char* dirname) {
printOpenedFiles("before");
if(!pathname || !buf) {
errno = EINVAL;
return -1;
@ -796,6 +844,7 @@ int appendToFile(const char* pathname, void* buf, size_t size, const char* dirna
}
int lockFile(const char* pathname) {
printOpenedFiles("before");
if(!pathname){
errno = EINVAL;
return -1;
@ -893,6 +942,7 @@ _unlockFile: {
}
int unlockFile(const char* pathname) {
printOpenedFiles("before");
if(!pathname){
errno = EINVAL;
return -1;
@ -966,6 +1016,7 @@ int unlockFile(const char* pathname) {
}
int closeFile(const char *pathname) {
printOpenedFiles("before");
if(!pathname){
errno = EINVAL;
return -1;
@ -1043,10 +1094,12 @@ int closeFile(const char *pathname) {
free(res);
free(cmd);
printOpenedFiles("after");
return 0;
}
int removeFile(const char* pathname) {
printOpenedFiles("before");
if(!pathname){
errno = EINVAL;
return -1;
@ -1121,12 +1174,14 @@ int removeFile(const char* pathname) {
}
free(cmd);
printOpenedFiles("after");
return 0;
}
// -----------------------------------------------------------------------------
int setDirectory(char* Dir, int rw) {
printOpenedFiles("before");
if (!Dir) {
errno = EINVAL;
return -1;
@ -1149,6 +1204,7 @@ int setDirectory(char* Dir, int rw) {
openedFiles->rDir = malloc(strlen(Dir)+1);
strncpy(openedFiles->rDir, Dir, strlen(Dir)+1);
}
printOpenedFiles("after");
return 0;
}
@ -1162,12 +1218,14 @@ void printInfo(int p, FILE *stream) {
}
openedFiles->print = (p)? 1: 0;
openedFiles->out = stream;
printOpenedFiles("after");
return;
}
// -----------------------------------------------------------------------------
int reciveData(response_t *res, int expected) {
printOpenedFiles("before");
if(!res) {
errno = EINVAL;
return -1;
@ -1415,6 +1473,7 @@ _nofile:
}
int storeFilesInDirectory(const char *dirname, int n, recivedFile_t *rf) {
printOpenedFiles("before");
if(!dirname || strcmp(dirname, "") || !rf || n<0) {
errno = EINVAL;
return -1;
@ -1470,6 +1529,7 @@ int storeFilesInDirectory(const char *dirname, int n, recivedFile_t *rf) {
}
free(basepath);
printOpenedFiles("after");
return 0;
}
@ -1511,6 +1571,7 @@ int isOpen(const char *pathname) {
}
int addOpenFile(const char *pathname) {
printOpenedFiles("before");
if(!pathname) {
errno = EINVAL;
return -1;
@ -1545,10 +1606,12 @@ int addOpenFile(const char *pathname) {
}
tail->next = new;
openedFiles->numOfFiles++;
printOpenedFiles("after");
return 0;
}
int removeOpenFile(const char *pathname) {
printOpenedFiles("before");
if(!pathname) {
errno = EINVAL;
return -1;
@ -1588,6 +1651,7 @@ int removeOpenFile(const char *pathname) {
}
int closeEveryFile() {
printOpenedFiles("before");
if (openedFiles == NULL)
return 0;
@ -1606,6 +1670,7 @@ int closeEveryFile() {
}
}
}
if(openedFiles->createdAndLocked) {
free(openedFiles->createdAndLocked);
openedFiles->createdAndLocked = NULL;
@ -1621,9 +1686,7 @@ int closeEveryFile() {
openedFiles->wDir = NULL;
}
fprintf(stdout, "\nhere\n");
fflush(stdout);
printOpenedFiles("after");
return 0;
}
@ -1642,5 +1705,7 @@ int createOpenedFiles(void) {
openedFiles->wDir = NULL;
openedFiles->print = 0;
openedFiles->out = NULL;
printOpenedFiles("after");
return 0;
}