view src/file_read.cbc @ 151:06449f2ae0c7

remove file_read constructor
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Mon, 16 Dec 2019 21:38:50 +0900
parents fd166dda4361
children 49d8aba0002a
line wrap: on
line source

#include "../context.h"
#interface "SysRead.h"

// ----
// typedef struct FileRead<Type, Isa> impl SysRead {
//   struct file* f;
//   int r;
//   __code cbc_fileread1(Type* file_read, struct file* f,int r,__code next(r,...));
//   __code next(...);
// } FileRead;
// ----

SysRead* createFileReadInstFromFile(struct Context* cbc_context, struct file* f,char* addr, int n) {
   if (f->type == FD_PIPE) {
       return create_piperead(cbc_context, f->pipe, addr, n, next);
   }

   if (f->type == FD_INODE) {
       ilock(f->ip);
       return create_readi(cbc_context, f->ip, addr, f->off, n, cbc_fileread1);
   }
   return NULL; //Error?
}

__code selectReadInstance(struct Context cbc_context, struct file* f, __code ret(int i)) {
   if (f->readable == 0) {
     i = -1;
     goto ret(i);
   }
   SysRead* read = createFileReadInstFromFile(proc->cbc_context, f);
   goto read->read(f,addr,n);
}