Skip to content

Commit d9e5416

Browse files
committed
Define DN Flags
1 parent 3da1abd commit d9e5416

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

Src/IronPython.Modules/fcntl.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ a file object.
2929

3030
// FD Flags
3131
public static int FD_CLOEXEC = 1;
32+
public static int FASYNC => RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? 0x0040 : 0x2000;
3233

3334

3435
#region Generated FD Commands
@@ -160,4 +161,44 @@ a file object.
160161
// *** END GENERATED CODE ***
161162

162163
#endregion
164+
165+
166+
// Linux only
167+
#region Generated Directory Notify Flags
168+
169+
// *** BEGIN GENERATED CODE ***
170+
// generated by function: generate_DN_flags from: generate_os_codes.py
171+
172+
173+
[PythonHidden(PlatformID.MacOSX)]
174+
[SupportedOSPlatform("linux")]
175+
public static int DN_ACCESS => 0x1;
176+
177+
[PythonHidden(PlatformID.MacOSX)]
178+
[SupportedOSPlatform("linux")]
179+
public static int DN_ATTRIB => 0x20;
180+
181+
[PythonHidden(PlatformID.MacOSX)]
182+
[SupportedOSPlatform("linux")]
183+
public static int DN_CREATE => 0x4;
184+
185+
[PythonHidden(PlatformID.MacOSX)]
186+
[SupportedOSPlatform("linux")]
187+
public static int DN_DELETE => 0x8;
188+
189+
[PythonHidden(PlatformID.MacOSX)]
190+
[SupportedOSPlatform("linux")]
191+
public static int DN_MODIFY => 0x2;
192+
193+
[PythonHidden(PlatformID.MacOSX)]
194+
[SupportedOSPlatform("linux")]
195+
public static long DN_MULTISHOT => 0x80000000;
196+
197+
[PythonHidden(PlatformID.MacOSX)]
198+
[SupportedOSPlatform("linux")]
199+
public static int DN_RENAME => 0x10;
200+
201+
// *** END GENERATED CODE ***
202+
203+
#endregion
163204
}

Src/Scripts/generate_os_codes.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
# See the LICENSE file in the project root for more information.
44

5+
import re
56
from generate import generate
67
from collections import OrderedDict
78

@@ -214,7 +215,12 @@ def generate_codes(cw, codeval, access, fmt, unix_only=False):
214215
cw.write(f'[SupportedOSPlatform("{s}")]')
215216

216217
value = windows_code_expr(codes, fmt)
217-
cw.write(f"{access} static int {name} => {value};")
218+
typ = "int"
219+
if (all(c.isdigit() for c in value) or re.match(r'^0x[0-9a-fA-F]+$', value)):
220+
n = eval(value)
221+
if n > 2**31 - 1 or n < -2**31:
222+
typ = "long"
223+
cw.write(f"{access} static {typ} {name} => {value};")
218224

219225

220226
def generate_all_O_flags(cw):
@@ -243,6 +249,19 @@ def generate_FD_commands(cw):
243249
generate_codes(cw, codeval, 'public', str, unix_only=True)
244250

245251

252+
# python3 -c 'import fcntl;print(dict(sorted((s, getattr(fcntl, s)) for s in dir(fcntl) if s.startswith("DN_"))))'
253+
# Python 3.6.15 [GCC 12.2.0] on linux 6.10.14
254+
# Python 3.12.3 [GCC 13.2.0] on linux 6.8.0
255+
DN_flags_linux = {'DN_ACCESS': 1, 'DN_ATTRIB': 32, 'DN_CREATE': 4, 'DN_DELETE': 8, 'DN_MODIFY': 2, 'DN_MULTISHOT': 2147483648, 'DN_RENAME': 16}
256+
257+
def generate_DN_flags(cw):
258+
codeval = {}
259+
for name in DN_flags_linux:
260+
set_value(codeval, name, DN_flags_linux[name], linux_idx)
261+
codeval = OrderedDict(sorted(codeval.items()))
262+
generate_codes(cw, codeval, 'public', hex, unix_only=True)
263+
264+
246265
def main():
247266
return generate(
248267
("Errno Codes", generate_errno_codes),
@@ -251,6 +270,7 @@ def main():
251270
("O_Flags", generate_all_O_flags),
252271
("Common O_Flags", generate_common_O_flags),
253272
("FD Commands", generate_FD_commands),
273+
("Directory Notify Flags", generate_DN_flags),
254274
)
255275

256276
if __name__ == "__main__":

0 commit comments

Comments
 (0)