This is the mail archive of the crossgcc@cygnus.com mailing list for the crossgcc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: scanf() acting strange


Hi,

> I think this came up a couple weeks ago and I thought
> I saved the message(s) but I couldn't find them.
>
> My platform is a mc68333 board and I'm using a Linux
> to m68k cross-compiler.  I have printf() working great,
> but when I call scanf() it doesn't seem to get the
> end-of-line character correctly.

This is broken in newlib-1.8.0(I haven't checked 1.8.1 yet). It would appear
that the read() function in libgloss/read.c get's things all mixed up.
Here's a fix that was posted to the ColdFire mailing list a month or two ago
by Paul Breed(paul@rasdoc.com):

The fix is to replace the code in the LIBGLOSS read.c with:

/*
 * read  -- read bytes from the serial port. Ignore fd, since
 *          we only have stdin.
 */
int	read(int fd ,char * buf,int nbytes)
{
  int i = 0;

  for (i = 0; i < nbytes; i++) {
    *(buf + i) = inbyte();
    if ((*(buf + i) == '\r') || (*(buf + i) == '\n'))  {
	*(buf +i)='\n';
        outbyte('\r');
        outbyte('\n');
        return i+1;
	}
	else
	outbyte(*(buf+i));
  }
  return (i);
}

His fix has the added benefit that it echo's characters back to the terminal
as well as fixing the bug :)

You could always use an OS with real IO like RTEMS of course ;)

Dave

David Fiddes, CALM Software Production Officer
Department of Mathematics, Heriot-Watt University, Edinburgh
email D.J.Fiddes@hw.ac.uk - Tel: +44 131-451-3251
50th Aniversary of the Computer : 21st June 1948 :
http://www.computer50.org/