#include "libsys.h"

unsigned int __read(int f,char *p,unsigned int len)
{
 unsigned char cnt=0,c;
 while(1){
  c=__chrin();
  if(c==0) continue;
  if(c==127){
    if(cnt==0) continue;
    cnt--;
    goto out;
  }
  if(cnt>=len) continue;
  p[cnt]=c;
  cnt++;
out:
  __chrout(c);
  if(c==13) {__chrout(10);p[cnt-1]=10;return cnt;}
 }
}
