Amjad50 / Emerald

An Operating System in Rust
https://amjad.alsharafi.dev/Emerald
MIT License
12 stars 0 forks source link

Add support for open file operations #93

Closed Amjad50 closed 7 months ago

Amjad50 commented 7 months ago

Lets make it similar to what Rust provide in the OpenOptions types, i.e.

All of the flags may be used with each other, i.e. I don't think we need to report hard error if for example "create + create_new", but instead will need to ignore other fields.

The operation will be something like this.

write = write or append # append implicit "write"

file = open(read, write)

if not file:
    if create or create_new:
        return create(read, write)
    fail "File not available"
else:
    if create_new:
        fail "already exist"

# here, the file is opened
if truncate:
    if write:
        file.set_length(0)
    else:
        fail "File is not writable, can't truncate"

if append:
    file.seek(END, 0)