Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
typon-concurrency
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
typon
typon-concurrency
Commits
51d08474
Commit
51d08474
authored
Aug 04, 2022
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examples/: Add cat.cpp
parent
0b07808b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
0 deletions
+48
-0
rt/examples/cat.cpp
rt/examples/cat.cpp
+48
-0
No files found.
rt/examples/cat.cpp
0 → 100644
View file @
51d08474
#include <typon/typon.hpp>
#include <cstdio>
#include <string>
using
namespace
typon
;
Task
<
int
>
cat
(
const
char
*
path
)
{
struct
statx
statxbuf
;
if
(
int
err
=
co_await
io
::
statx
(
AT_FDCWD
,
path
,
0
,
STATX_SIZE
,
&
statxbuf
))
{
co_return
err
;
}
int
fd
=
co_await
io
::
openat
(
AT_FDCWD
,
path
,
O_RDONLY
,
0
);
if
(
fd
<
0
)
{
co_return
fd
;
}
auto
size
=
statxbuf
.
stx_size
;
std
::
string
buf
(
size
,
'\0'
);
int
nbytes
=
co_await
io
::
read
(
fd
,
buf
.
data
(),
size
);
co_await
io
::
close
(
fd
);
if
(
nbytes
<
0
)
{
co_return
nbytes
;
}
co_return
co_await
io
::
write
(
1
,
buf
);
}
Root
root
(
int
argc
,
char
*
argv
[])
{
if
(
argc
<
2
)
{
fprintf
(
stderr
,
"Usage: %s [file name] <[file name] ...>
\n
"
,
argv
[
0
]);
}
for
(
int
i
=
1
;
i
<
argc
;
i
++
)
{
int
res
=
co_await
cat
(
argv
[
i
]);
if
(
res
<
0
)
{
fprintf
(
stderr
,
"Failed to cat %s
\n
"
,
argv
[
i
]);
}
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
root
(
argc
,
argv
).
call
();
}
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