aboutsummaryrefslogtreecommitdiff
path: root/ld/emultempl/elf32.em
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2004-10-11 14:42:30 +0000
committerJakub Jelinek <jakub@redhat.com>2004-10-11 14:42:30 +0000
commit563f4125b7408b420e91959ef88d0f6623f4489e (patch)
tree89e352f88ae8c6372e9fa9d202803f2d459a81ac /ld/emultempl/elf32.em
parentd3989512d9d920c66be68a543d0c984eda2542a0 (diff)
downloadfsf-binutils-gdb-563f4125b7408b420e91959ef88d0f6623f4489e.zip
fsf-binutils-gdb-563f4125b7408b420e91959ef88d0f6623f4489e.tar.gz
fsf-binutils-gdb-563f4125b7408b420e91959ef88d0f6623f4489e.tar.bz2
* emultempl/elf32.em (gld${EMULATION_NAME}_parse_ld_so_conf): Avoid
getline for portability.
Diffstat (limited to 'ld/emultempl/elf32.em')
-rw-r--r--ld/emultempl/elf32.em24
1 files changed, 20 insertions, 4 deletions
diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em
index a4e2f1e..6273f0e 100644
--- a/ld/emultempl/elf32.em
+++ b/ld/emultempl/elf32.em
@@ -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)
+ linelen = 256;
+ line = xmalloc (linelen);
+ do
{
- char *p;
+ 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);
}