This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


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

XScale redboot sys_read()


Greetings-

I made the following change to syscall.c to support console input
via the Green Hills stdio library, which expects a count
(0 for EOF, and -1 for error).

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

#if 1
    for (i = 0; i < nbytes; i++)
    {
        *(buf + i) = __getc();
        if ((*(buf + i) == '\n') || (*(buf + i) == '\r'))
        {
            *(buf + i + 1) = 0;
            return (i + 1); // return count one based
        }
    }
    // post increment from loop leaves i++ thus one based here
    *(buf + i + 1) = 0;
    return (i);
#else
    if (nbytes == 0) {
        return(gets(buf,1,10));
    }

    for (i = 0; i < nbytes; i++) {
	*(buf + i) = __getc();
	if ((*(buf + i) == '\n') || (*(buf + i) == '\r')) {
	    (*(buf + i + 1)) = 0;
	    break;
	}
    }
    return (i);
#endif
}


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