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

unsigned int __write(int f,const char *p,unsigned int len)
{
  if(f<FOPEN_MAX){
    __pdos_cmd.write.cnt=4;
    __pdos_cmd.write.ref_num=f;
    __pdos_cmd.write.data_buffer=p;
    __pdos_cmd.write.request_count=len;
    __pdos_call(PDOS_WRITE);
    if(__pdos_err){errno=__pdos_err;return 0;}
    return __pdos_cmd.write.trans_count;
  }else{
    unsigned int n=len;
    while(n){
     char c=*p++;
     if(c==10) c=13;
     __chrout(c);
     n--;
    }
  }
  return len;
}
