#include <stdio.h>
#include "libsys.h"

#undef __read

extern FILE __files[FOPEN_MAX+3];

unsigned int __read(int f,char *p,unsigned int len)
{
  unsigned int n=0;
  char c;
  __chkin(f);
  do{
   *p++=c=__chrin();
   n++;
    if(__readst()) {__files[f-1].flags|=_EOF;break;}
  }while(n<len&&c!='\n');
  __clrchn();
  if(f==1&&c=='\n') __write(2,"\n",1);
  return n;
}
