* emultempl/elf32.em (gld${EMULATION_NAME}_parse_ld_so_conf): Avoid
authorJakub Jelinek <jakub@redhat.com>
Mon, 11 Oct 2004 14:42:30 +0000 (14:42 +0000)
committerJakub Jelinek <jakub@redhat.com>
Mon, 11 Oct 2004 14:42:30 +0000 (14:42 +0000)
getline for portability.

ld/ChangeLog
ld/emultempl/elf32.em

index efb7abc78af960e4acff8d16409a2f2f57f491c9..1058f03b741506775bb1759defefad3c67729d4d 100644 (file)
@@ -1,5 +1,8 @@
 2004-10-11  Jakub Jelinek  <jakub@redhat.com>
 
+       * emultempl/elf32.em (gld${EMULATION_NAME}_parse_ld_so_conf): Avoid
+       getline for portability.
+
        * emultempl/elf32.em (gld${EMULATION_NAME}_ld_so_conf): New structure.
        (gld${EMULATION_NAME}_parse_ld_so_conf,
        gld${EMULATION_NAME}_parse_ld_so_conf_include): New functions.
index a4e2f1e1073495c141700f5053416876c0c6412d..6273f0e90c81a824a6da1da33e687a784979207f 100644 (file)
@@ -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);
 }