FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
micropython/examples/unix/ffi_example.py at master · itschina/micropython · GitHub
itschina
/
micropython
Public
forked from
micropython/micropython
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
micropython
/
examples
/
unix
/
ffi_example.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
41 lines (32 loc) · 854 Bytes
Breadcrumbs
micropython
/
examples
/
unix
/
ffi_example.py
Copy path
File metadata and controls
41 lines (32 loc) · 854 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import
ffi
import
uctypes
libc
=
ffi
.
open
(
"libc.so.6"
)
print
(
"libc:"
,
libc
)
print
()
# Declare few functions
perror
=
libc
.
func
(
"v"
,
"perror"
,
"s"
)
time
=
libc
.
func
(
"i"
,
"time"
,
"p"
)
open
=
libc
.
func
(
"i"
,
"open"
,
"si"
)
qsort
=
libc
.
func
(
"v"
,
"qsort"
,
"piiC"
)
# And one variable
errno
=
libc
.
var
(
"i"
,
"errno"
)
print
(
"time:"
,
time
)
print
(
"UNIX time is:"
,
time
(
None
))
print
()
perror
(
"perror before error"
)
open
(
"somethingnonexistent__"
,
0
)
print
(
"errno object:"
,
errno
)
print
(
"errno value:"
,
errno
.
get
())
perror
(
"perror after error"
)
print
()
def
cmp
(
pa
,
pb
):
a
=
uctypes
.
bytearray_at
(
pa
,
1
)
b
=
uctypes
.
bytearray_at
(
pb
,
1
)
print
(
"cmp:"
,
a
,
b
)
return
a
[
0
]
-
b
[
0
]
cmp_cb
=
ffi
.
callback
(
"i"
,
cmp
,
"PP"
)
print
(
"callback:"
,
cmp_cb
)
s
=
bytearray
(
b"foobar"
)
print
(
"org string:"
,
s
)
qsort
(
s
,
len
(
s
),
1
,
cmp_cb
)
print
(
"qsort'ed string:"
,
s
)
Back
|
FazBrowse Home
|
New Git URL