delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2002/05/25/05:42:19

Message-ID: <000d01c203d0$8ca32c20$0102a8c0@acceleron>
From: "Andrew Cottrell" <acottrel AT ihug DOT com DOT au>
To: <djgpp-workers AT delorie DOT com>, "Richard Dawe" <rich AT phekda DOT freeserve DOT co DOT uk>
References: <10205241453 DOT AA19974 AT clio DOT rice DOT edu> <002901c20392$d9b3c120$0102a8c0 AT acceleron> <3CEF4E7B DOT 17584050 AT phekda DOT freeserve DOT co DOT uk>
Subject: Re: refresh++
Date: Sat, 25 May 2002 19:42:25 +1000
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
Reply-To: djgpp-workers AT delorie DOT com

> > Please note that confstr.c as simple as I thought and I am wtill working
on
> > it as the compiler does not like the following line in the file:-
> >       out_len = snprintf(buf, len, "");
> > GCC 3.1 complains about the third parameter.
> [snip]
>
> What complaint does it have? I suspect it's complaining that there's no
format
> string. Does it complain about this?
Correct.
>     out_len = snprintf(buf, len, "%s", "");
>
> It looks like this call is intended to truncate the buffer, to return to
an
> empty string.

Correct. The GNU LIBC code to do this is as follows, when the lines that are
not required are chopped out:-

size_t
confstr (name, buf, len)
     int name;
     char *buf;
     size_t len;
{
  const char *string;
  size_t string_len;

..SNIP..SWITCH...

      /* GNU libc does not require special actions to use LFS functions.  */
      string = "";
      string_len = 1;
      break;

    default:
      __set_errno (EINVAL);
      return 0;
    }
  if (len > 0 && buf != NULL)
    {
      if (string_len <= len)
 memcpy (buf, string, string_len);
      else
 {
   memcpy (buf, string, len - 1);
   buf[len - 1] = '\0';
 }
    }
  return string_len;


I have translated this into my WIP version as follows:-
    /* No options are required for the default 32-bit environment.  */
    case _CS_POSIX_V6_ILP32_OFF32_CFLAGS:
    case _CS_POSIX_V6_ILP32_OFF32_LDFLAGS:
    case _CS_POSIX_V6_ILP32_OFF32_LIBS:
    {
      out_len = 1;
      memcpy (buf, "\0", out_len);
      break;
    }

Any comments on this?

Andrew

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019