From 50f2e27564937fc8b0a736e4262a4bfbb8483ec8 Mon Sep 17 00:00:00 2001 From: elvis Date: Sun, 24 Apr 2022 12:20:31 +0200 Subject: [PATCH] aaaaaaaaaaa --- lib/api/api.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 68 insertions(+), 3 deletions(-) diff --git a/lib/api/api.c b/lib/api/api.c index 8f82b70..37b5b50 100644 --- a/lib/api/api.c +++ b/lib/api/api.c @@ -31,6 +31,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 { @@ -95,6 +120,9 @@ int createOpenedFiles(void); // ----------------------------------------------------------------------------- int openConnection(const char* sockname, int msec, const struct timespec abstime) { + + printOpenedFiles("before"); + if(!sockname){ errno = EINVAL; return -1; @@ -147,10 +175,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; @@ -171,6 +203,9 @@ int closeConnection(const char* sockname) { } int openFile(const char* pathname, int flags) { + + printOpenedFiles("before"); + if(!pathname){ errno = EINVAL; return -1; @@ -288,10 +323,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; @@ -410,6 +450,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; @@ -490,6 +533,7 @@ int readNFiles(int N, const char* dirname) { } int writeFile(const char* pathname, const char* dirname) { + printOpenedFiles("before"); if(!pathname) { errno = EINVAL; return -1; @@ -671,10 +715,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; @@ -793,6 +841,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; @@ -890,6 +939,7 @@ _unlockFile: { } int unlockFile(const char* pathname) { + printOpenedFiles("before"); if(!pathname){ errno = EINVAL; return -1; @@ -963,6 +1013,7 @@ int unlockFile(const char* pathname) { } int closeFile(const char *pathname) { + printOpenedFiles("before"); if(!pathname){ errno = EINVAL; return -1; @@ -1040,10 +1091,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; @@ -1118,12 +1171,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; @@ -1146,6 +1201,7 @@ int setDirectory(char* Dir, int rw) { openedFiles->rDir = malloc(strlen(Dir)+1); strncpy(openedFiles->rDir, Dir, strlen(Dir)+1); } + printOpenedFiles("after"); return 0; } @@ -1159,12 +1215,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; @@ -1412,6 +1470,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; @@ -1467,6 +1526,7 @@ int storeFilesInDirectory(const char *dirname, int n, recivedFile_t *rf) { } free(basepath); + printOpenedFiles("after"); return 0; } @@ -1508,6 +1568,7 @@ int isOpen(const char *pathname) { } int addOpenFile(const char *pathname) { + printOpenedFiles("before"); if(!pathname) { errno = EINVAL; return -1; @@ -1542,10 +1603,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; @@ -1585,6 +1648,7 @@ int removeOpenFile(const char *pathname) { } int closeEveryFile() { + printOpenedFiles("before"); if (openedFiles == NULL) return 0; @@ -1603,6 +1667,7 @@ int closeEveryFile() { } } } + if(openedFiles->createdAndLocked) { free(openedFiles->createdAndLocked); openedFiles->createdAndLocked = NULL; @@ -1618,9 +1683,7 @@ int closeEveryFile() { openedFiles->wDir = NULL; } - fprintf(stdout, "\nhere\n"); - fflush(stdout); - + printOpenedFiles("after"); return 0; } @@ -1639,5 +1702,7 @@ int createOpenedFiles(void) { openedFiles->wDir = NULL; openedFiles->print = 0; openedFiles->out = NULL; + + printOpenedFiles("after"); return 0; }