Write up to len characters to file.
Return the number of actually written characters, or -1 on error.
+ssize_t close(fd_t file);
+ Termine the fd `file`. If there were no other copies of it, the corresponding file is closed.
+ Returns -1 if `file` isn't an opened file descriptor.
+
ssize_t fseek(fd_t file, ssize_t offset, int from);
If from is 0, seek offset bytes from start.
If from is 1, seek offset bytes from current file position.
return len;
}
+// extern "C" std::int64_t syscall_close(std::int64_t file) {
+extern "C" std::int64_t syscall_close(std::int64_t) {
+ os::assert(false, "Close isn't implemented for now.");
+ __builtin_unreachable();
+}
+
extern "C" std::int64_t syscall_write(std::int64_t file, char const* data, std::int64_t len) {
os::assert(file == 0, "Write isn't really implemented for now.");
os::assert(len >= 0, "Write expects a positive size.");
extern "C" int64_t open(int64_t wd, char const* path, int64_t path_len, open_options options);
extern "C" int64_t read(int64_t file, char* data, int64_t len);
extern "C" int64_t write(int64_t file, char const* data, int64_t len);
+extern "C" int64_t close(int64_t file);
extern "C" int64_t fseek(int64_t file, int64_t offset, int from);
} // namespace sys
extern "C" void _start() {
- const int64_t fd = 0; // sys::open(0, "/serial", 7, sys::MODE_RW | sys::OPTION_INPLACE);
+ const int64_t wd = sys::open(0, "/", 1, open_options(MODE_RW | OPTION_INPLACE | MODE_DIRECTORY));
+ const int64_t serial = sys::open(wd, "serial", 1, MODE_RW);
+ const int64_t serial_ = sys::open(wd, "/serial", 1, MODE_WO);
- sys::write(fd, "Entrez votre nom: ", 18);
+ sys::write(serial, "Entrez votre nom: ", 18);
char data[32];
int64_t read = 0;
int64_t read_this_time;
do {
- read_this_time = sys::read(fd, data + read, 1);
+ read_this_time = sys::read(serial, data + read, 1);
if (read_this_time) {
if (data[read] == '\r') {
- sys::write(fd, "\n", 1);
+ sys::write(serial, "\n", 1);
} else {
- sys::write(fd, data + read, 1);
+ sys::write(serial, data + read, 1);
}
}
read += read_this_time;
} while (read_this_time != 0 && read < 32 && data[read - 1] != '\r');
- sys::write(fd, "Bonjour, ", 9);
- sys::write(fd, data, read - (data[read - 1] == '\r' ? 1 : 0));
- sys::write(fd, ".\n", 2);
+ sys::write(serial_, "Bonjour, ", 9);
+ sys::write(serial_, data, read - (data[read - 1] == '\r' ? 1 : 0));
+ sys::write(serial_, ".\n", 2);
+
+ sys::close(serial);
+ sys::close(serial_);
while (true) {
sys::fseek(0, 0, 1);