Skip to content

Commit 46ede27

Browse files
committed
os: Implement open().
1 parent 6f1823b commit 46ede27

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

os/metadata.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
srctype = micropython-lib
22
type = package
3-
version = 0.1.7
3+
version = 0.1.8
44
author = Paul Sokolovsky
55
depends = libc, errno, stat

os/os/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
getcwd_ = libc.func("s", "getcwd", "si")
2222
opendir_ = libc.func("P", "opendir", "s")
2323
readdir_ = libc.func("P", "readdir", "P")
24+
open_ = libc.func("i", "open", "sii")
2425
read_ = libc.func("i", "read", "ipi")
2526
write_ = libc.func("i", "write", "iPi")
2627
close_ = libc.func("i", "close", "i")
@@ -37,6 +38,16 @@
3738
X_OK = const(1)
3839
F_OK = const(0)
3940

41+
O_ACCMODE = 0o0000003
42+
O_RDONLY = 0o0000000
43+
O_WRONLY = 0o0000001
44+
O_RDWR = 0o0000002
45+
O_CREAT = 0o0000100
46+
O_EXCL = 0o0000200
47+
O_NOCTTY = 0o0000400
48+
O_TRUNC = 0o0001000
49+
O_APPEND = 0o0002000
50+
O_NONBLOCK = 0o0004000
4051

4152
error = OSError
4253
name = "posix"
@@ -132,6 +143,11 @@ def walk(top, topdown=True):
132143
if not topdown:
133144
yield top, dirs, files
134145

146+
def open(n, flags, mode=0o777):
147+
r = open_(n, flags, mode)
148+
check_error(r)
149+
return r
150+
135151
def read(fd, n):
136152
buf = bytearray(n)
137153
r = read_(fd, buf, n)

os/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
setup(name='micropython-os',
9-
version='0.1.7',
9+
version='0.1.8',
1010
description='os module for MicroPython',
1111
long_description="This is a module reimplemented specifically for MicroPython standard library,\nwith efficient and lean design in mind. Note that this module is likely work\nin progress and likely supports just a subset of CPython's corresponding\nmodule. Please help with the development if you are interested in this\nmodule.",
1212
url='https://github.com/micropython/micropython/issues/405',

0 commit comments

Comments
 (0)