ldlex should use streams

Andreas Jaeger aj@suse.de
Sun Jan 20 07:06:00 GMT 2002


We currently have a discussion on the glibc lists that you cannot just
do fopen a file and then read on it, the file pointer need not be at
the beginning of the file (it seems to be in all current
implementations but you never know).

Therefore I propose the following simple patch to avoid this
situation, I don't see a reason for read in that place.

Ok to commit?  I run make check sucessfully.

Andreas

2002-01-20  Andreas Jaeger  <aj@suse.de>

	* ldlex.l: Use fread instead of read.

============================================================
Index: ld/ldlex.l
--- ld/ldlex.l	2001/10/20 13:49:00	1.8
+++ ld/ldlex.l	2002/01/20 07:27:37
@@ -1,7 +1,7 @@
 %{
 
-/* Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
-   Free Software Foundation, Inc.
+/* Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+   2000, 2001, 2002  Free Software Foundation, Inc.
 
 This file is part of GLD, the Gnu Linker.
 
@@ -595,7 +595,7 @@
     {
       if (yyin)
 	{
-	  *result = read (fileno (yyin), (char *) buf, max_size);
+	  *result = fread ((char *) buf, 1, max_size, yyin);
 	  if (*result < 0) 
 	    einfo ("%F%P: read in flex scanner failed\n");
 	}

-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.inka.de
    http://www.suse.de/~aj



More information about the Binutils mailing list