diff --git a/backend.c b/backend.c index c4ee54b..eeb0a8a 100644 --- a/backend.c +++ b/backend.c @@ -71,6 +71,8 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten lstat(full_path, file); dir_content[i].file_size = file->st_size; + dir_content[i].permissions = 1; + dir_content[i].permissions = file->st_mode; if (S_ISDIR(file->st_mode)) { dir_content[i].file_type = FILE_TYPE_DIR; @@ -82,8 +84,8 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten } else if (S_ISBLK(file->st_mode)) { dir_content[i].file_type = FILE_TYPE_BLOCK; dir_content[i].color_pair = COLOR_BLOCK; - /*} else if (S_ISCHR(file->st_mode)) { - dir_content[i].file_type = COLOR_CHARDEV; */ + } else if (S_ISCHR(file->st_mode)) { + dir_content[i].file_type = COLOR_CHARDEV; } else if (S_ISLNK(file->st_mode)) { dir_content[i].file_type = FILE_TYPE_SYMLINK; dir_content[i].color_pair = COLOR_SYMLINK; diff --git a/defines.h b/defines.h index f104357..2f8ac0a 100644 --- a/defines.h +++ b/defines.h @@ -1,3 +1,4 @@ +#include #define STATUS_QUIT_PROGRAM 1 #define STATUS_RUN_BACKEND 2 @@ -57,6 +58,7 @@ typedef struct File { char *file_name; unsigned char file_type; unsigned short color_pair; + unsigned int permissions; unsigned long file_name_width; unsigned long file_size; /*if its a file, its in bytes, if its a dir, its the count of files within that dir */ } file; diff --git a/threading.c b/threading.c index 36d13a7..a1647b0 100644 --- a/threading.c +++ b/threading.c @@ -36,12 +36,15 @@ unsigned long top_width; unsigned long selected_file_current=0; unsigned long selected_file_last=0; +unsigned int status_mid; extern unsigned int status; +extern unsigned int terminal_width; void *thread_rgt(void *data); void *thread_mid(void *data){ pthread_mutex_lock(&mutex_mid); + status_mid = 0; char *path; @@ -77,6 +80,7 @@ void *thread_mid(void *data){ file_current->file_name_width = mid_content[selected_file_current].file_name_width; file_current->file_size = mid_content[selected_file_current].file_size; file_current->file_type = mid_content[selected_file_current].file_type; + file_current->permissions = mid_content[selected_file_current].permissions; break; } } @@ -84,6 +88,7 @@ void *thread_mid(void *data){ } free(path); + status_mid=1; pthread_mutex_unlock(&mutex_mid); pthread_exit(NULL); } @@ -119,7 +124,14 @@ void *thread_lft(void *data){ void *thread_rgt(void *data){ pthread_mutex_lock(&mutex_rgt); - pthread_mutex_lock(&mutex_mid); + while(1) { + if (!pthread_mutex_trylock(&mutex_mid)) { + if (status_mid == 1) { + break; + } + } + } + free(rgt_content); rgt_content = malloc(sizeof(file)); rgt_content[0].file_name = malloc(file_current->file_name_width + 1); @@ -173,7 +185,33 @@ void *thread_top(void *data){ pthread_exit(NULL); } void *thread_btm(void *data){ + pthread_mutex_lock(&mutex_btm); + while(1) { + if (!pthread_mutex_trylock(&mutex_mid)) { + if (status_mid == 1) { + break; + } + } + } + pthread_mutex_unlock(&mutex_mid); + + free(btm_buffer); + int buffer_width = terminal_width; + btm_buffer = malloc(buffer_width); + memset(btm_buffer, 0, buffer_width); + btm_buffer[0] = (file_current->permissions & S_IRUSR) ? 'r' : '-'; + btm_buffer[1] = (file_current->permissions & S_IWUSR) ? 'w' : '-'; + btm_buffer[2] = (file_current->permissions & S_IXUSR) ? 'x' : '-'; + btm_buffer[3] = (file_current->permissions & S_IRGRP) ? 'r' : '-'; + btm_buffer[4] = (file_current->permissions & S_IWGRP) ? 'w' : '-'; + btm_buffer[5] = (file_current->permissions & S_IXGRP) ? 'x' : '-'; + btm_buffer[6] = (file_current->permissions & S_IROTH) ? 'r' : '-'; + btm_buffer[7] = (file_current->permissions & S_IWOTH) ? 'w' : '-'; + btm_buffer[8] = (file_current->permissions & S_IXOTH) ? 'x' : '-'; + + + pthread_mutex_unlock(&mutex_btm); pthread_exit(NULL); }