> On 18 Mar 2025, at 12:08, Richard Biener <richard.guent...@gmail.com> wrote:
> 
> On Tue, Mar 18, 2025 at 1:07 PM Iain Sandoe <i...@sandoe.co.uk> wrote:
>> 
>> 
>> 
>>> On 18 Mar 2025, at 12:01, Richard Biener <richard.guent...@gmail.com> wrote:
>>> 
>>> On Tue, Mar 18, 2025 at 12:13 PM Iain Sandoe <iains....@gmail.com> wrote:
>>>> 
>>>> tested on x86_64/aarch64 Linux and x86_64-darwin, OK for trunk?
>>>> thanks
>>>> Iain
>>>> 
>>>> --- 8< ---
>>>> 
>>>> This adds a configure check for get_current_dir_name and falls back
>>>> to getcwd() if it is not available on the host.
>>>> 
>>>>       PR cobol/119301
>>>> 
>>>> gcc/cobol/ChangeLog:
>>>> 
>>>>       * util.cc: Check for the availability of get_current_dir_name
>>>>       and fall back to getcwd() if it is not present on the host.
>>>> 
>>>> gcc/ChangeLog:
>>>> 
>>>>       * config.in: Regenerate.
>>>>       * configure: Regenerate.
>>>>       * configure.ac: Add check for get_current_dir_name.
>>>> 
>>>> Signed-off-by: Iain Sandoe <i...@sandoe.co.uk>
>>>> ---
>>>> gcc/cobol/util.cc | 9 +++++++++
>>>> gcc/config.in     | 6 ++++++
>>>> gcc/configure     | 2 +-
>>>> gcc/configure.ac  | 2 +-
>>>> 4 files changed, 17 insertions(+), 2 deletions(-)
>>>> 
>>>> diff --git a/gcc/cobol/util.cc b/gcc/cobol/util.cc
>>>> index 9f746a38808..ecef10190eb 100644
>>>> --- a/gcc/cobol/util.cc
>>>> +++ b/gcc/cobol/util.cc
>>>> @@ -72,6 +72,15 @@ extern int yyparse(void);
>>>> 
>>>> extern int demonstration_administrator(int N);
>>>> 
>>>> +#if !defined (HAVE_GET_CURRENT_DIR_NAME)
>>>> +static inline char *
>>>> +get_current_dir_name ()
>>>> +{
>>>> +  /* Fall back to getcwd which is also present in libiberty.  */
>>>> +  return getcwd (nullptr, 0);
>>> 
>>> Isn't that getcwd allocates the storage an extension?
>> 
>> Hmm.. indeed Posix:
>> 
>> "The size argument is the size in bytes of the character array pointed to by 
>> the buf argument. If buf is a null pointer, the behavior of getcwd() is 
>> unspecified."
>> 
>> and Linux and Darwin differ (Darwin does allocate, Linux does not).
>> 
>>> I see libiberty
>>> also does this, but IIRC that copy isn't used if the system provides it?
>> 
>> Maybe we need a libiberty implementation of get_current_dir_name() which 
>> does the same as the Linux one (and actually the same as the Darwin getcwd).
>> 
>> Open to suggestions ..
> 
> char *buf = malloc  (PATH_MAX);
> return getcwd (buf, PATH_MAX);
> 
> ?

I’m fine with that - providing we have an expectation that PATH_MAX will be 
available (with a suitable header include).
I’ll do some grepping for existing practice.
thanks
Iain

> 
>> Iain
>> 
>>> 
>>>> +}
>>>> +#endif
>>>> +
>>>> const char *
>>>> symbol_type_str( enum symbol_type_t type )
>>>> {
>>>> diff --git a/gcc/config.in b/gcc/config.in
>>>> index 7023209f2ed..0d8a6ba1808 100644
>>>> --- a/gcc/config.in
>>>> +++ b/gcc/config.in
>>>> @@ -1624,6 +1624,12 @@
>>>> #endif
>>>> 
>>>> 
>>>> +/* Define to 1 if you have the `get_current_dir_name' function. */
>>>> +#ifndef USED_FOR_TARGET
>>>> +#undef HAVE_GET_CURRENT_DIR_NAME
>>>> +#endif
>>>> +
>>>> +
>>>> /* Define to 1 if using GNU as. */
>>>> #ifndef USED_FOR_TARGET
>>>> #undef HAVE_GNU_AS
>>>> diff --git a/gcc/configure b/gcc/configure
>>>> index 2679a05d9c6..063b9ce6701 100755
>>>> --- a/gcc/configure
>>>> +++ b/gcc/configure
>>>> @@ -10640,7 +10640,7 @@ for ac_func in times clock kill getrlimit 
>>>> setrlimit atoq \
>>>>       popen sysconf strsignal getrusage nl_langinfo \
>>>>       gettimeofday mbstowcs wcswidth mmap posix_fallocate setlocale \
>>>>       clearerr_unlocked feof_unlocked   ferror_unlocked fflush_unlocked 
>>>> fgetc_unlocked fgets_unlocked   fileno_unlocked fprintf_unlocked 
>>>> fputc_unlocked fputs_unlocked   fread_unlocked fwrite_unlocked 
>>>> getchar_unlocked getc_unlocked   putchar_unlocked putc_unlocked madvise 
>>>> mallinfo mallinfo2 fstatat getauxval \
>>>> -       clock_gettime munmap msync
>>>> +       clock_gettime munmap msync get_current_dir_name
>>>> do :
>>>>  as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
>>>> ac_fn_cxx_check_func "$LINENO" "$ac_func" "$as_ac_var"
>>>> diff --git a/gcc/configure.ac b/gcc/configure.ac
>>>> index 78973755f7a..3243472680c 100644
>>>> --- a/gcc/configure.ac
>>>> +++ b/gcc/configure.ac
>>>> @@ -1574,7 +1574,7 @@ AC_CHECK_FUNCS(times clock kill getrlimit setrlimit 
>>>> atoq \
>>>>       popen sysconf strsignal getrusage nl_langinfo \
>>>>       gettimeofday mbstowcs wcswidth mmap posix_fallocate setlocale \
>>>>       gcc_UNLOCKED_FUNCS madvise mallinfo mallinfo2 fstatat getauxval \
>>>> -       clock_gettime munmap msync)
>>>> +       clock_gettime munmap msync get_current_dir_name)
>>>> 
>>>> # At least for glibc, clock_gettime is in librt.  But don't pull that
>>>> # in if it still doesn't give us the function we want.
>>>> --
>>>> 2.39.2 (Apple Git-143)

Reply via email to