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
56from generate import generate
67from 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
220226def 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+
246265def 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
256276if __name__ == "__main__" :
0 commit comments