#include <ncurses.h>
#include <unistd.h>
#include <stdio.h>
+#include <stdlib.h>
/* internal libraries */
#include "vec.h"
}
}
+//get the curent directory and copy it into a ref-counted memory block
+//return a pointer to the new block
+char* pwd(){
+ char* dir = getcwd(NULL, 0);
+ char* rid = mem_allocate(sizeof(char)*strlen(dir), NULL);
+ strcpy(rid, dir);
+ free(dir);
+ return rid;
+}
+
static frame_t* screen_frame_new(void) {
frame_t* p_frame = (frame_t*)mem_allocate(sizeof(frame_t),&screen_frame_free);
p_frame->p_win = newwin(1, 1, 0, 0);
- char* path = state_get_focused_frame() ? state_get_focused_frame()->workdir->path : getcwd(NULL, 0);
+ char* path = state_get_focused_frame() ? state_get_focused_frame()->workdir->path : pwd();
p_frame->workdir = workdir_new(path);
return p_frame;
}
WorkDir_T* wd = mem_allocate(sizeof(WorkDir_T), &workdir_free);
wd->idx = 0;
wd->path = path;
+ mem_retain(path);
wd->vfiles = vec_new(0);
workdir_ls(wd);
wd->top_index = 0;
void workdir_free(void* p_wd){
WorkDir_T* wd = (WorkDir_T*)p_wd;
mem_release(wd->vfiles);
+ mem_release(wd->path);
}
void workdir_next(WorkDir_T* wd) {
void workdir_cd(WorkDir_T* wd) {
char* newpath = (wd->idx == 0) ? workdir_cd_up(wd) : workdir_cd_down(wd);
if(is_dir(newpath)){
- //TODO: this segfaults: mem_release(wd->path);
+ mem_release(wd->path);
wd->path = newpath;
wd->idx = 0;
wd->top_index = 0;