This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: [PATCH] Handle ld.so.conf the same in ld as in ldconfig
On Mon, Oct 11, 2004 at 10:28:33AM -0400, Daniel Jacobowitz wrote:
> On Mon, Oct 11, 2004 at 04:13:06PM +0200, Jakub Jelinek wrote:
> > On Tue, Oct 05, 2004 at 11:12:28PM +0930, Alan Modra wrote:
> > > > + /* Normally this would use getline(3), but we need to be portable. */
> > >
> > > This code is only used on native linux systems, so why not use getline?
> >
> > This is what I have checked in. If portability needs arise for this,
> > we can always go back to the non-getline code.
>
> Sorry for not catching this sooner...
>
> if [ "x${USE_LIBPATH}" = xyes ] ; then
> ...
> case ${target} in
> *-*-linux-gnu*)
> ...
> while (getline (&line, &linelen, f) != -1)
>
> That's not native-only code. It's used for natives, almost-natives
> (NATIVE=yes), and sysrooted builds from any host.
Ok, reverted to the getline by hand code.
2004-10-11 Jakub Jelinek <jakub@redhat.com>
* emultempl/elf32.em (gld${EMULATION_NAME}_parse_ld_so_conf): Avoid
getline for portability.
--- ld/emultempl/elf32.em.jj 2004-10-11 16:04:30.450576084 +0200
+++ ld/emultempl/elf32.em 2004-10-11 16:38:43.196852204 +0200
@@ -563,15 +563,30 @@ gld${EMULATION_NAME}_parse_ld_so_conf
(struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename)
{
FILE *f = fopen (filename, FOPEN_RT);
- char *line = NULL;
- size_t linelen = 0;
+ char *line;
+ size_t linelen;
if (f == NULL)
return;
- while (getline (&line, &linelen, f) != -1)
- {
- char *p;
+ linelen = 256;
+ line = xmalloc (linelen);
+ do
+ {
+ char *p = line, *q;
+
+ /* Normally this would use getline(3), but we need to be portable. */
+ while ((q = fgets (p, linelen - (p - line), f)) != NULL
+ && strlen (q) == linelen - (p - line) - 1
+ && line[linelen - 2] != '\n')
+ {
+ line = xrealloc (line, 2 * linelen);
+ p = line + linelen - 1;
+ linelen += linelen;
+ }
+
+ if (q == NULL && p == line)
+ break;
p = strchr (line, '\n');
if (p)
@@ -647,6 +662,7 @@ gld${EMULATION_NAME}_parse_ld_so_conf
info->path[info->len] = '\0';
}
}
+ while (! feof (f));
free (line);
fclose (f);
}
Jakub