annotate wc_sigos/UnixFileImpl.cpp @ 5:7599728af8ba default tip

add wc
author ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
date Sat, 19 Jun 2021 07:24:43 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <stdio.h>
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #impl UnixFileImp as "UnixFileImpl.h"
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 File* createUnixFileImpl(struct Context* context) {
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 File *file = new File();
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 file->FileImpl = (union Data*)new FileImpl();
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 return file;
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 }
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 readBlock(UnixFileImpl* file) {
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 Block *block = new Block();
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 int len = read(fd, BUFSIZE, block->data);
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 block->eof &= ~BLOCK_FLAG_EOF;
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 if (len <=0 ) {
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 block->eof |= BLOCK_FLAG_EOF;
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 close(file->fd);
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 }
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 return block ;
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 }
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 __code unixOpen(UnixFileImpl* file,Key *key, __code next(Block *block,...));
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 file->fd = open(key->path,unix_mode(key->modde));
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 if (fd < 0) {
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 goto error("can't open");
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 }
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 goto next(readBlock(file), ...);
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 }
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 __code uniAck(UnixFileImpl* file,Ack *ack, __code next(Block *block,...));
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 if (!ack->isOk) {
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 close(file->fd);
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 goto next(...);
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 }
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 goto next(readBlock(file), ...); // file is automaticaly put into local dataGearManger/input
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 }
ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37