/******************************************************************************
*     $Date: 2004/07/09 23:41:55 $
*     $RCSfile: read.c,v $
*******************************************************************************

*******************************************************************************
*
*     XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS"
*     SOLELY FOR USE IN DEVELOPING PROGRAMS AND SOLUTIONS FOR
*     XILINX DEVICES.  BY PROVIDING THIS DESIGN, CODE, OR INFORMATION
*     AS ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION
*     OR STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS
*     IMPLEMENTATION IS FREE FROM ANY CLAIMS OF INFRINGEMENT,
*     AND YOU ARE RESPONSIBLE FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE
*     FOR YOUR IMPLEMENTATION.  XILINX EXPRESSLY DISCLAIMS ANY
*     WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE
*     IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR
*     REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF
*     INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
*     FOR A PARTICULAR PURPOSE.
*     
*     (c) Copyright 2004 Xilinx, Inc.
*     All rights reserved.
*
******************************************************************************/

extern char inbyte(void);

#ifndef ECHO
#define ECHO               1
#endif

#if ECHO
extern int write(int fd, char *buf, int nbytes);
#endif

int read(int fd, char *buf, int nbytes)
{
  int i = 0;
  
  while(i < nbytes)
  {
    buf[i] = inbyte();
    if (buf[i] == '\r')
      buf[i] = '\n';

#if ECHO
    write(fd, &buf[i], 1);
#endif
    
    if (buf[i] == '\n')
    {
      i++;
      buf[i] = 0;
      break;
    }
    i++;
  }
  return (i);
}
