diff options
| author | iceyrazor <iceyrazor@mailfence.com> | 2026-03-06 22:34:50 -0600 |
|---|---|---|
| committer | iceyrazor <iceyrazor@mailfence.com> | 2026-03-06 22:34:50 -0600 |
| commit | f3d03e71ede8e94e7137777ab5ad5570c3d11b31 (patch) | |
| tree | ddd17a5e3e1c40e645772cb9466169b98389985d /src/lsh_builtins.c | |
| parent | 5964950ca5c018e1163fe308fa4bb17b9220b383 (diff) | |
some cleanup and shell var
- SHELL is now set
- cwd now has realloc
- realloc with error checking is now a fucntion like malloce
Diffstat (limited to 'src/lsh_builtins.c')
| -rw-r--r-- | src/lsh_builtins.c | 11 |
1 files changed, 9 insertions, 2 deletions
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); } |
