#include <syscall.h>
#include <lib.h>
#include <kern/unistd.h>

size_t sys_read(int fh, userptr_t buf, size_t size) {
  int i=0;
  int * ary = (int*)buf;
  if (fh!=STDIN_FILENO) {
    kprintf("sys_read supported only to stdin\n");
    return -1;
  }

  for (i=0;i<(int)size;i++) {
    ary[i] = getch();
  }
  return i;
}

size_t sys_write(int fh, const userptr_t buf, size_t size) {
  int i=0;
  int * ary = (int*)buf;
  
  if (fh!=STDOUT_FILENO && fh!=STDERR_FILENO) {
    kprintf("sys_write supported only to stdout\n");
    return -1;
  }

  for (i=0;i<(int)size;i++) {
    putch(ary[i]);
  }
  return i;
}
