Re: fix build error on MinGW (HAVE_READLINK) undefined

Pedro Alves
2012-01-27T10:02:14Z

On 01/27/2012 09:21 AM, Eli Zaretskii wrote:
>> Date: Fri, 27 Jan 2012 10:07:26 +0800
>> From: asmwarrior <asmwarrior@gmail.com>
>>
>> diff --git a/gdb/gdbserver/hostio.c b/gdb/gdbserver/hostio.c
>> index 34e4fa8..7575fb1 100644
>> --- a/gdb/gdbserver/hostio.c
>> +++ b/gdb/gdbserver/hostio.c
>> @@ -459,6 +459,7 @@ handle_unlink (char *own_buf)
>> static void
>> handle_readlink (char *own_buf, int *new_packet_len)
>> {
>> +#if defined (HAVE_READLINK) && defined (PATH_MAX)

You need to teach config.h about HAVE_READLINK. Add readlink to
AC_CHECK_FUNCS in gdbserver/configure.ac, and regenerate (autoconf/autoheader).

>> char filename[PATH_MAX], linkname[PATH_MAX];
>> char *p;
>> int ret, bytes_sent;
>> @@ -485,6 +486,10 @@ handle_readlink (char *own_buf, int *new_packet_len)
>> to return a partial response, but simply fail. */
>> if (bytes_sent < ret)
>> sprintf (own_buf, "F-1,%x", FILEIO_ENAMETOOLONG);
>> +#else
>> + hostio_error (own_buf);
>> + return;
>> +#endif
>
> I think you need to set errno to EINVAL in the #else branch, because
> the meaning of that error on systems that do have readlink is "the
> named file is not a symbolic link".
>
> On second thought, perhaps a better way would be to define a readlink
> for MinGW that always sets errno to EINVAL and returns -1. Then the
> ugly #ifdef can go away.

The corresponding native side returns ENOSYS/FILEIO_ENOSYS, indicating
the function is not supported by the implementation. GDBserver should do
the same.

>
>> static char *
>> inf_child_fileio_readlink (const char *filename, int *target_errno)
>> {
>> /* We support readlink only on systems that also provide a compile-time
>> maximum path length (MAXPATHLEN), at least for now. */
>> #if defined (HAVE_READLINK) && defined (MAXPATHLEN)
>> char buf[MAXPATHLEN];
>> int len;
>> char *ret;
>>
>> len = readlink (filename, buf, sizeof buf);
>
> Here too.

The #else branch just below reads:

#else
*target_errno = FILEIO_ENOSYS;
return NULL;
#endif

--
Pedro Alves