Skip to content

Commit

Permalink
Make os.open API exactly as in CPython
Browse files Browse the repository at this point in the history
  • Loading branch information
certik committed Mar 30, 2022
1 parent edf846f commit d427bc4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions integration_tests/test_os.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from ltypes import i64
from os import (open, read, close)
from os import (open, read, close, O_RDONLY)

def test():
path: str
path = "integration_tests/test_os.py"
fd: i64
n: i64
fd = open(path, "r")
fd = open(path, O_RDONLY)
n = 100
print(read(fd, n))
close(fd)
Expand Down
16 changes: 14 additions & 2 deletions src/runtime/os.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
from ltypes import i32, i64, ccall

def open(path: str, flag: str) -> i64:
O_RDONLY: i32 # = 0 FIXME: Assign the value 0 to O_RDONLY
# O_WRONLY: i32 = 1
# O_RDWR : i32 = 2
# O_CREAT : i32 = 64
# O_APPEND: i32 = 1024


def open(path: str, flag: i32) -> i64:
"""
Returns the file descriptor for the newly opened file
"""
return _lpython_open(path, flag)
sflag: str
if flag == O_RDONLY:
sflag = "r"
else:
quit(1) # not implemented yet
return _lpython_open(path, sflag)

@ccall
def _lpython_open(path: str, flag: str) -> i64:
Expand Down

0 comments on commit d427bc4

Please sign in to comment.