From 3960ffc393a97a26805f7a2e9e98f3125ae0f20d Mon Sep 17 00:00:00 2001 From: nasrlol Date: Tue, 18 Feb 2025 22:56:36 +0100 Subject: these are my curent findings on the getcwd command from the unistd.h library Signed-off-by: nasrlol --- main.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/main.c b/main.c index 076d23c..5db0488 100644 --- a/main.c +++ b/main.c @@ -106,6 +106,19 @@ void clear() { printf("\033[3J"); } +char *print_cdirectory() { + char *current_working_directory = getcwd(NULL, 0); + /* getcwd() command already allocates malloc for the path that should be returned, + to do: should I free it when finished or not?/ + so what I understand from the documentation, you should only free it when actually setting an exact size + but when keeping the max size to 0 and relying on the malloc there is no need for it + not sure though + should rely on further debugging + */ + + return current_working_directory; +} + void change_directory(const char *path) { if (path == NULL) { printf("No path found\n"); -- cgit v1.2.3-70-g09d2