From b23c6885a6be61c0ae16f09f6dd8ecf04066a68b Mon Sep 17 00:00:00 2001 From: "Jan (janneke) Nieuwenhuizen" Date: Fri, 1 Jan 2021 15:43:43 +0100 Subject: [PATCH] core: Move __getcwd_buf to Mes C Library. * include/mes/mes.h (__getcwd_buf): Move to.. * lib/posix/getcwd.c (__getcwd_buf): ...here. (getcwd): Refactor. * src/posix.c (getcwd_): Do not use __getcwd_buf. --- include/mes/mes.h | 3 +-- lib/posix/getcwd.c | 18 +++++++++++------- src/mes.c | 3 +-- src/posix.c | 3 +-- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/include/mes/mes.h b/include/mes/mes.h index 9127ca92..90abe592 100644 --- a/include/mes/mes.h +++ b/include/mes/mes.h @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019,2020,2021 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -100,7 +100,6 @@ struct timespec *gc_end_time; size_t gc_time; char **__execl_c_argv; -char *__getcwd_buf; char *__open_boot_buf; char *__open_boot_file_name; char *__setenv_buf; diff --git a/lib/posix/getcwd.c b/lib/posix/getcwd.c index 7eb4f28e..bc820f25 100644 --- a/lib/posix/getcwd.c +++ b/lib/posix/getcwd.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019,2020,2021 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -26,13 +26,17 @@ // CONSTANT PATH_MAX 1024 +char *__getcwd_buf; + char * getcwd (char *buffer, int size) { - if (__getcwd_buf == 0) - __getcwd_buf = malloc (PATH_MAX); - char *buf = __getcwd_buf; - if (buffer != 0) - return _getcwd (buffer, size); - return _getcwd (buf, PATH_MAX); + if (buffer == 0) + buffer = __getcwd_buf; + if (buffer == 0) + { + __getcwd_buf = malloc (PATH_MAX); + buffer = __getcwd_buf; + } + return _getcwd (buffer, size); } diff --git a/src/mes.c b/src/mes.c index d9b3ff90..86699ba5 100644 --- a/src/mes.c +++ b/src/mes.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019,2020,2021 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -161,7 +161,6 @@ init (char **envp) { environ = envp; __execl_c_argv = malloc (1024 * sizeof (char *)); /* POSIX minimum: 4096 */ - __getcwd_buf = malloc (PATH_MAX); __gettimeofday_time = malloc (sizeof (struct timeval)); __get_internal_run_time_ts = malloc (sizeof (struct timespec)); __open_boot_buf = malloc (PATH_MAX); diff --git a/src/posix.c b/src/posix.c index 538ebcd6..bfb1bcd3 100644 --- a/src/posix.c +++ b/src/posix.c @@ -435,8 +435,7 @@ get_internal_run_time () struct scm * getcwd_ () /*:((name . "getcwd")) */ { - char *buf = __getcwd_buf; - return make_string0 (getcwd (buf, PATH_MAX)); + return make_string0 (getcwd (0, PATH_MAX)); } struct scm *