aaaaaaaaaaa
This commit is contained in:
@ -31,6 +31,31 @@
|
|||||||
// #define ME "52" // not used
|
// #define ME "52" // not used
|
||||||
#define MESE "55" // server error
|
#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 */
|
/* structs */
|
||||||
typedef struct files_s {
|
typedef struct files_s {
|
||||||
@ -95,6 +120,9 @@ int createOpenedFiles(void);
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
int openConnection(const char* sockname, int msec, const struct timespec abstime) {
|
int openConnection(const char* sockname, int msec, const struct timespec abstime) {
|
||||||
|
|
||||||
|
printOpenedFiles("before");
|
||||||
|
|
||||||
if(!sockname){
|
if(!sockname){
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
@ -147,10 +175,14 @@ int openConnection(const char* sockname, int msec, const struct timespec abstime
|
|||||||
}
|
}
|
||||||
|
|
||||||
strncpy(socketName, sockname, sizeof(socketName)-1);
|
strncpy(socketName, sockname, sizeof(socketName)-1);
|
||||||
|
|
||||||
|
printOpenedFiles("after");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int closeConnection(const char* sockname) {
|
int closeConnection(const char* sockname) {
|
||||||
|
printOpenedFiles("before");
|
||||||
|
|
||||||
if (!sockname || strncmp(socketName, sockname, sizeof(socketName)) != 0) {
|
if (!sockname || strncmp(socketName, sockname, sizeof(socketName)) != 0) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
@ -171,6 +203,9 @@ int closeConnection(const char* sockname) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int openFile(const char* pathname, int flags) {
|
int openFile(const char* pathname, int flags) {
|
||||||
|
|
||||||
|
printOpenedFiles("before");
|
||||||
|
|
||||||
if(!pathname){
|
if(!pathname){
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
@ -288,10 +323,15 @@ int openFile(const char* pathname, int flags) {
|
|||||||
free(res);
|
free(res);
|
||||||
|
|
||||||
free(cmd);
|
free(cmd);
|
||||||
|
|
||||||
|
printOpenedFiles("after");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int readFile(const char* pathname, void** buf, size_t* size) {
|
int readFile(const char* pathname, void** buf, size_t* size) {
|
||||||
|
|
||||||
|
printOpenedFiles("before");
|
||||||
|
|
||||||
if(!pathname) {
|
if(!pathname) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
@ -410,6 +450,9 @@ int readFile(const char* pathname, void** buf, size_t* size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int readNFiles(int N, const char* dirname) {
|
int readNFiles(int N, const char* dirname) {
|
||||||
|
|
||||||
|
printOpenedFiles("before");
|
||||||
|
|
||||||
if(!dirname) {
|
if(!dirname) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
@ -490,6 +533,7 @@ int readNFiles(int N, const char* dirname) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int writeFile(const char* pathname, const char* dirname) {
|
int writeFile(const char* pathname, const char* dirname) {
|
||||||
|
printOpenedFiles("before");
|
||||||
if(!pathname) {
|
if(!pathname) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
@ -671,10 +715,14 @@ int writeFile(const char* pathname, const char* dirname) {
|
|||||||
free(cmd);
|
free(cmd);
|
||||||
|
|
||||||
free(content);
|
free(content);
|
||||||
|
|
||||||
|
printOpenedFiles("after");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int appendToFile(const char* pathname, void* buf, size_t size, const char* dirname) {
|
int appendToFile(const char* pathname, void* buf, size_t size, const char* dirname) {
|
||||||
|
|
||||||
|
printOpenedFiles("before");
|
||||||
if(!pathname || !buf) {
|
if(!pathname || !buf) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
@ -793,6 +841,7 @@ int appendToFile(const char* pathname, void* buf, size_t size, const char* dirna
|
|||||||
}
|
}
|
||||||
|
|
||||||
int lockFile(const char* pathname) {
|
int lockFile(const char* pathname) {
|
||||||
|
printOpenedFiles("before");
|
||||||
if(!pathname){
|
if(!pathname){
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
@ -890,6 +939,7 @@ _unlockFile: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int unlockFile(const char* pathname) {
|
int unlockFile(const char* pathname) {
|
||||||
|
printOpenedFiles("before");
|
||||||
if(!pathname){
|
if(!pathname){
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
@ -963,6 +1013,7 @@ int unlockFile(const char* pathname) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int closeFile(const char *pathname) {
|
int closeFile(const char *pathname) {
|
||||||
|
printOpenedFiles("before");
|
||||||
if(!pathname){
|
if(!pathname){
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
@ -1040,10 +1091,12 @@ int closeFile(const char *pathname) {
|
|||||||
free(res);
|
free(res);
|
||||||
free(cmd);
|
free(cmd);
|
||||||
|
|
||||||
|
printOpenedFiles("after");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int removeFile(const char* pathname) {
|
int removeFile(const char* pathname) {
|
||||||
|
printOpenedFiles("before");
|
||||||
if(!pathname){
|
if(!pathname){
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
@ -1118,12 +1171,14 @@ int removeFile(const char* pathname) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
free(cmd);
|
free(cmd);
|
||||||
|
printOpenedFiles("after");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
int setDirectory(char* Dir, int rw) {
|
int setDirectory(char* Dir, int rw) {
|
||||||
|
printOpenedFiles("before");
|
||||||
if (!Dir) {
|
if (!Dir) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
@ -1146,6 +1201,7 @@ int setDirectory(char* Dir, int rw) {
|
|||||||
openedFiles->rDir = malloc(strlen(Dir)+1);
|
openedFiles->rDir = malloc(strlen(Dir)+1);
|
||||||
strncpy(openedFiles->rDir, Dir, strlen(Dir)+1);
|
strncpy(openedFiles->rDir, Dir, strlen(Dir)+1);
|
||||||
}
|
}
|
||||||
|
printOpenedFiles("after");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1159,12 +1215,14 @@ void printInfo(int p, FILE *stream) {
|
|||||||
}
|
}
|
||||||
openedFiles->print = (p)? 1: 0;
|
openedFiles->print = (p)? 1: 0;
|
||||||
openedFiles->out = stream;
|
openedFiles->out = stream;
|
||||||
|
printOpenedFiles("after");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
int reciveData(response_t *res, int expected) {
|
int reciveData(response_t *res, int expected) {
|
||||||
|
printOpenedFiles("before");
|
||||||
if(!res) {
|
if(!res) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
@ -1412,6 +1470,7 @@ _nofile:
|
|||||||
}
|
}
|
||||||
|
|
||||||
int storeFilesInDirectory(const char *dirname, int n, recivedFile_t *rf) {
|
int storeFilesInDirectory(const char *dirname, int n, recivedFile_t *rf) {
|
||||||
|
printOpenedFiles("before");
|
||||||
if(!dirname || strcmp(dirname, "") || !rf || n<0) {
|
if(!dirname || strcmp(dirname, "") || !rf || n<0) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
@ -1467,6 +1526,7 @@ int storeFilesInDirectory(const char *dirname, int n, recivedFile_t *rf) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
free(basepath);
|
free(basepath);
|
||||||
|
printOpenedFiles("after");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1508,6 +1568,7 @@ int isOpen(const char *pathname) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int addOpenFile(const char *pathname) {
|
int addOpenFile(const char *pathname) {
|
||||||
|
printOpenedFiles("before");
|
||||||
if(!pathname) {
|
if(!pathname) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
@ -1542,10 +1603,12 @@ int addOpenFile(const char *pathname) {
|
|||||||
}
|
}
|
||||||
tail->next = new;
|
tail->next = new;
|
||||||
openedFiles->numOfFiles++;
|
openedFiles->numOfFiles++;
|
||||||
|
printOpenedFiles("after");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int removeOpenFile(const char *pathname) {
|
int removeOpenFile(const char *pathname) {
|
||||||
|
printOpenedFiles("before");
|
||||||
if(!pathname) {
|
if(!pathname) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
@ -1585,6 +1648,7 @@ int removeOpenFile(const char *pathname) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int closeEveryFile() {
|
int closeEveryFile() {
|
||||||
|
printOpenedFiles("before");
|
||||||
if (openedFiles == NULL)
|
if (openedFiles == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -1603,6 +1667,7 @@ int closeEveryFile() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(openedFiles->createdAndLocked) {
|
if(openedFiles->createdAndLocked) {
|
||||||
free(openedFiles->createdAndLocked);
|
free(openedFiles->createdAndLocked);
|
||||||
openedFiles->createdAndLocked = NULL;
|
openedFiles->createdAndLocked = NULL;
|
||||||
@ -1618,9 +1683,7 @@ int closeEveryFile() {
|
|||||||
openedFiles->wDir = NULL;
|
openedFiles->wDir = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stdout, "\nhere\n");
|
printOpenedFiles("after");
|
||||||
fflush(stdout);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1639,5 +1702,7 @@ int createOpenedFiles(void) {
|
|||||||
openedFiles->wDir = NULL;
|
openedFiles->wDir = NULL;
|
||||||
openedFiles->print = 0;
|
openedFiles->print = 0;
|
||||||
openedFiles->out = NULL;
|
openedFiles->out = NULL;
|
||||||
|
|
||||||
|
printOpenedFiles("after");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user