Skip to content

Commit db3b28f

Browse files
authored
[unix_api] Generate functions if their types are understood by dart:ffi (#273)
1 parent e0d5874 commit db3b28f

20 files changed

+979
-49
lines changed

pkgs/unix_api/.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ lib/src/constants.g.dart linguist-generated
44
lib/src/libc_bindings.g.dart linguist-generated
55
src/constants.g.c linguist-generated
66
src/constants.g.h linguist-generated
7+
src/functions.g.c linguist-generated
8+
src/functions.g.h linguist-generated

pkgs/unix_api/constants.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,14 @@
6969
"DT_REG",
7070
"DT_SOCK",
7171
"DT_UNKNOWN"
72+
],
73+
"<stdio.h>": [
74+
"L_ctermid"
75+
],
76+
"<unistd.h>": [
77+
"F_OK",
78+
"R_OK",
79+
"W_OK",
80+
"X_OK"
7281
]
7382
}

pkgs/unix_api/ffigen.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ output: 'lib/src/libc_bindings.g.dart'
88
headers:
99
entry-points:
1010
- 'src/libc_shim.h'
11+
- 'src/functions.g.h'
1112

1213
include-directives:
1314
- 'src/libc_shim.h'
15+
- 'src/functions.g.h'
1416
preamble: |
1517
// ignore_for_file: type=lint, unused_field
1618
comments:

pkgs/unix_api/functions.json

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{
2+
"<stdio.h>" : [
3+
{
4+
"comment": "Renames a file.",
5+
"url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/rename.html",
6+
"prototype": "int rename(const char *, const char *)"
7+
}
8+
],
9+
"<string.h>" : [
10+
{
11+
"comment": "Formats an error code as a string.",
12+
"url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/strerror.html",
13+
"prototype": "char *strerror(int)"
14+
}
15+
],
16+
"<unistd.h>" : [
17+
{
18+
"comment": "Determines the accessibility of a file.",
19+
"url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/access.html",
20+
"prototype": "int access(const char *, int)"
21+
},
22+
{
23+
"comment": "Schedules an alarm signal.",
24+
"url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/alarm.html",
25+
"prototype": "unsigned alarm(unsigned)"
26+
},
27+
{
28+
"comment": "Changes the working directory.",
29+
"url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/chdir.html",
30+
"prototype": "int chdir(const char *)"
31+
},
32+
{
33+
"comment": "Closes a file descriptor.",
34+
"url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/close.html",
35+
"prototype": "int close(int)"
36+
},
37+
{
38+
"comment": "Encrypts a string.",
39+
"url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/crypt.html",
40+
"prototype": "char * crypt(const char *, const char *)",
41+
"available_android": false,
42+
"unavailable_value": "NULL"
43+
},
44+
{
45+
"comment": "Generates a path name for the controlling terminal.",
46+
"url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/ctermid.html",
47+
"prototype": "char * ctermid(char *)",
48+
"available_android": false,
49+
"unavailable_value": "\"\""
50+
},
51+
{
52+
"comment": "Duplicates an open file descriptor.",
53+
"url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/dup.html",
54+
"prototype": "int dup(int)"
55+
},
56+
{
57+
"comment": "Copies an open file descriptor into another.",
58+
"url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/dup.html",
59+
"prototype": "int dup2(int, int)"
60+
},
61+
{
62+
"comment": "Determines the accessibility of a file descriptor.",
63+
"url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/faccessat.html",
64+
"prototype": "int faccessat(int, const char *, int, int)"
65+
},
66+
{
67+
"comment": "Changes the current directory.",
68+
"url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/fchdir.html",
69+
"prototype": "int fchdir(int)"
70+
},
71+
{
72+
"comment": "Forces all queued I/O operations to complete.",
73+
"url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/fdatasync.html",
74+
"prototype": "int fdatasync(int)",
75+
"available_ios": false,
76+
"unavailable_value": "-1"
77+
},
78+
{
79+
"comment": "Removes a directory entry.",
80+
"url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/linkat.html",
81+
"prototype": "int unlink(const char *)"
82+
},
83+
{
84+
"comment": "Removes a directory entry relative to another file.",
85+
"url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/unlinkat.html",
86+
"prototype": "int unlinkat(int, const char *, int)"
87+
}
88+
]
89+
}

pkgs/unix_api/hook/build.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ void main(List<String> args) async {
1414
await CBuilder.library(
1515
name: packageName,
1616
assetName: 'libc_shim',
17-
sources: ['src/libc_shim.c', 'src/constants.g.c'],
17+
libraries: [
18+
if ([OS.linux].contains(input.config.code.targetOS)) 'crypt',
19+
],
20+
sources: ['src/libc_shim.c', 'src/constants.g.c', 'src/functions.g.c'],
1821
flags: ['-Weverything'],
1922
).run(
2023
input: input,

pkgs/unix_api/lib/src/constant_bindings.g.dart

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkgs/unix_api/lib/src/constants.g.dart

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkgs/unix_api/lib/src/libc_bindings.g.dart

Lines changed: 110 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)