Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
typon
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tom Niget
typon
Commits
4c139017
Commit
4c139017
authored
Jul 07, 2023
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add mode support to open()
parent
51775850
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
5 deletions
+43
-5
rt/include/python/builtins.hpp
rt/include/python/builtins.hpp
+43
-5
No files found.
rt/include/python/builtins.hpp
View file @
4c139017
...
...
@@ -184,17 +184,55 @@ struct {
using
PyFile
=
decltype
(
file
)
::
type
;
//}
typon
::
Task
<
typon
::
PyFile
>
open
(
const
PyStr
&
path
,
std
::
string_view
mode
)
{
typon
::
Task
<
PyFile
>
open
(
const
PyStr
&
path
,
std
::
string_view
mode
)
{
const
char
*
path_c
=
path
.
c_str
();
size_t
len
=
0
;
struct
statx
statxbuf
;
if
(
int
err
=
co_await
typon
::
io
::
statx
(
AT_FDCWD
,
path_c
,
0
,
STATX_SIZE
,
&
statxbuf
))
{
system_error
(
-
err
,
"statx()"
);
if
(
int
err
=
co_await
typon
::
io
::
statx
(
AT_FDCWD
,
path_c
,
0
,
STATX_SIZE
,
&
statxbuf
))
{
// new file
}
else
{
len
=
statxbuf
.
stx_size
;
}
int
fd
=
co_await
typon
::
io
::
openat
(
AT_FDCWD
,
path_c
,
O_RDONLY
,
0
);
int
flags
=
0
;
bool
created
=
false
,
writable
=
false
,
readable
=
false
;
if
(
mode
.
find
(
'x'
)
!=
std
::
string_view
::
npos
)
{
created
=
true
;
writable
=
true
;
flags
=
O_EXCL
|
O_CREAT
;
}
else
if
(
mode
.
find
(
'r'
)
!=
std
::
string_view
::
npos
)
{
readable
=
true
;
flags
=
0
;
}
else
if
(
mode
.
find
(
'w'
)
!=
std
::
string_view
::
npos
)
{
writable
=
true
;
flags
=
O_CREAT
|
O_TRUNC
;
}
else
if
(
mode
.
find
(
'a'
)
!=
std
::
string_view
::
npos
)
{
writable
=
true
;
flags
=
O_APPEND
|
O_CREAT
;
}
if
(
mode
.
find
(
'+'
)
!=
std
::
string_view
::
npos
)
{
readable
=
true
;
writable
=
true
;
}
if
(
readable
&&
writable
)
{
flags
|=
O_RDWR
;
}
else
if
(
readable
)
{
flags
|=
O_RDONLY
;
}
else
{
flags
|=
O_WRONLY
;
}
flags
|=
O_CLOEXEC
;
int
fd
=
co_await
typon
::
io
::
openat
(
AT_FDCWD
,
path_c
,
flags
,
0666
);
if
(
fd
<
0
)
{
std
::
cerr
<<
path
<<
","
<<
flags
<<
std
::
endl
;
system_error
(
-
fd
,
"openat()"
);
}
co_return
typon
::
PyFile
(
fd
,
statxbuf
.
stx_size
);
co_return
PyFile
(
fd
,
len
);
}
#include "../typon/generator.hpp"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment