From f3d03e71ede8e94e7137777ab5ad5570c3d11b31 Mon Sep 17 00:00:00 2001 From: iceyrazor Date: Fri, 6 Mar 2026 22:34:50 -0600 Subject: some cleanup and shell var - SHELL is now set - cwd now has realloc - realloc with error checking is now a fucntion like malloce --- src/lsh_builtins.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/lsh_builtins.c') diff --git a/src/lsh_builtins.c b/src/lsh_builtins.c index dda49c4..51a44cd 100644 --- a/src/lsh_builtins.c +++ b/src/lsh_builtins.c @@ -40,6 +40,7 @@ int lsh_num_builtins() { /* Builtin function implementations. */ +#define LSH_CWD_BUF_SIZE 1024; int lsh_cd(char **args) { if (args[1] == NULL) { @@ -49,8 +50,14 @@ int lsh_cd(char **args) if (err != 0) { perror("lsh"); } - char *cwd=(char*)malloce(sizeof(char)*4096); - getcwd(cwd,sizeof(char*)*4096); + + int bufsize=LSH_CWD_BUF_SIZE; + char *cwd=(char*)malloce(sizeof(char)*bufsize+1); + while(getcwd(cwd,sizeof(char)*bufsize)==NULL){ + bufsize += LSH_CWD_BUF_SIZE; + cwd=(char*)realloce(cwd,sizeof(char)*bufsize+1); + } + setenv("PWD",cwd,1); free(cwd); } -- cgit v1.3