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.
This commit is contained in:
Jan (janneke) Nieuwenhuizen 2021-01-01 15:43:43 +01:00 committed by Jan Nieuwenhuizen
parent 5200ebe9ce
commit 68075eb630
4 changed files with 14 additions and 13 deletions

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software * GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2016,2017,2018,2019,2020,2021 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
* *
@ -100,7 +100,6 @@ struct timespec *gc_end_time;
size_t gc_time; size_t gc_time;
char **__execl_c_argv; char **__execl_c_argv;
char *__getcwd_buf;
char *__open_boot_buf; char *__open_boot_buf;
char *__open_boot_file_name; char *__open_boot_file_name;
char *__setenv_buf; char *__setenv_buf;

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software * GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2016,2017,2018,2019,2020,2021 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
* *
@ -26,13 +26,17 @@
// CONSTANT PATH_MAX 1024 // CONSTANT PATH_MAX 1024
char *__getcwd_buf;
char * char *
getcwd (char *buffer, int size) getcwd (char *buffer, int size)
{ {
if (__getcwd_buf == 0) if (buffer == 0)
__getcwd_buf = malloc (PATH_MAX); buffer = __getcwd_buf;
char *buf = __getcwd_buf; if (buffer == 0)
if (buffer != 0) {
return _getcwd (buffer, size); __getcwd_buf = malloc (PATH_MAX);
return _getcwd (buf, PATH_MAX); buffer = __getcwd_buf;
}
return _getcwd (buffer, size);
} }

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software * GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2016,2017,2018,2019,2020,2021 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
* *
@ -161,7 +161,6 @@ init (char **envp)
{ {
environ = envp; environ = envp;
__execl_c_argv = malloc (1024 * sizeof (char *)); /* POSIX minimum: 4096 */ __execl_c_argv = malloc (1024 * sizeof (char *)); /* POSIX minimum: 4096 */
__getcwd_buf = malloc (PATH_MAX);
__gettimeofday_time = malloc (sizeof (struct timeval)); __gettimeofday_time = malloc (sizeof (struct timeval));
__get_internal_run_time_ts = malloc (sizeof (struct timespec)); __get_internal_run_time_ts = malloc (sizeof (struct timespec));
__open_boot_buf = malloc (PATH_MAX); __open_boot_buf = malloc (PATH_MAX);

View File

@ -435,8 +435,7 @@ get_internal_run_time ()
struct scm * struct scm *
getcwd_ () /*:((name . "getcwd")) */ getcwd_ () /*:((name . "getcwd")) */
{ {
char *buf = __getcwd_buf; return make_string0 (getcwd (0, PATH_MAX));
return make_string0 (getcwd (buf, PATH_MAX));
} }
struct scm * struct scm *