Skip to content

Commit 397e915

Browse files
Include flags as an argument for open function
1 parent ae42276 commit 397e915

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

integration_tests/run_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"test_numpy_01.py",
2121
"test_numpy_02.py",
2222
"test_random.py",
23-
# "test_os.py",
23+
"test_os.py",
2424
"test_builtin.py",
2525
"test_builtin_abs.py",
2626
"test_builtin_bool.py",

integration_tests/test_os.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from ltypes import i64
2-
from os import (open, read, close)
2+
from os import (open, read, close, O_RDONLY)
33

44
def test():
55
path: str
66
path = "integration_tests/test_os.py"
77
fd: i64
88
n: i64
9-
fd = open(path)
9+
fd = open(path, O_RDONLY)
1010
n = 100
1111
print(read(fd, n))
1212
close(fd)

src/runtime/impure/lfortran_intrinsics.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,9 +789,9 @@ LFORTRAN_API void _lfortran_dp_rand_num(double *x) {
789789
*x = rand() / (double) RAND_MAX;
790790
}
791791

792-
LFORTRAN_API int64_t _lpython_open(char *path)
792+
LFORTRAN_API int64_t _lpython_open(char *path, int32_t flags)
793793
{
794-
int64_t fd = open(path, O_RDONLY);
794+
int64_t fd = open(path, flags);
795795
if (fd < 0)
796796
{
797797
printf("Error in opening the file!\n");

src/runtime/impure/lfortran_intrinsics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ LFORTRAN_API void _lfortran_i64sys_clock(
160160
uint64_t *count, int64_t *rate, int64_t *max);
161161
LFORTRAN_API void _lfortran_sp_rand_num(float *x);
162162
LFORTRAN_API void _lfortran_dp_rand_num(double *x);
163-
LFORTRAN_API int64_t _lpython_open(char *path);
163+
LFORTRAN_API int64_t _lpython_open(char *path, int32_t flags);
164164
LFORTRAN_API char* _lpython_read(int64_t fd, int64_t n);
165165
LFORTRAN_API void _lpython_close(int64_t fd);
166166

src/runtime/os.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
from ltypes import i64, ccall
1+
from ltypes import i32, i64, ccall
22

3-
def open(path: str) -> i64:
3+
O_RDONLY: i32 # = 0 FIXME: Assign the value 0 to O_RDONLY
4+
# O_WRONLY: i32 = 1
5+
# O_RDWR : i32 = 2
6+
# O_CREAT : i32 = 64
7+
# O_APPEND: i32 = 1024
8+
9+
def open(path: str, flag: i32) -> i64:
410
"""
511
Returns the file descriptor for the newly opened file
612
"""
7-
return _lpython_open(path)
13+
return _lpython_open(path, flag)
814

915
@ccall
10-
def _lpython_open(path: str) -> i64:
16+
def _lpython_open(path: str, flag: i32) -> i64:
1117
pass
1218

1319
def read(fd: i64, n: i64) -> str:

0 commit comments

Comments
 (0)