libc.monkey2 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. Namespace libc
  2. #Import "native/libc.cpp"
  3. #Import "native/libc.h"
  4. Extern
  5. #rem monkeydoc C/C++ 'char' type.
  6. #end
  7. Struct char_t="char"
  8. End
  9. #rem monkeydoc C/C++ 'const char' type.
  10. #end
  11. Struct const_char_t="const char"
  12. End
  13. #rem monkeydoc C/C++ 'signed char' type.
  14. #end
  15. Struct signed_char_t="signed char"
  16. End
  17. #rem monkeydoc C/C++ 'unsigned char' type
  18. #end
  19. Struct unsigned_char_t="unsigned char"
  20. End
  21. #rem monkeydoc C/C++ 'wchar_t' type
  22. #end
  23. Struct wchar_t="wchar_t"
  24. End
  25. #rem monkeydoc C/C++ 'size_t' type
  26. #end
  27. Alias size_t:UInt
  28. #rem monkeydoc C/C++ 'int8_t' type
  29. #end
  30. Alias int8_t:Byte
  31. #rem monkeydoc C/C++ 'uint8_t' type
  32. #end
  33. Alias uint8_t:UByte
  34. #rem monkeydoc C/C++ 'int16_t' type
  35. #end
  36. Alias int16_t:Short
  37. #rem monkeydoc C/C++ 'uint16_t' type
  38. #end
  39. Alias uint16_t:UShort
  40. #rem monkeydoc C/C++ 'int32_t' type
  41. #end
  42. Alias int32_t:Int
  43. #rem monkeydoc C/C++ 'uint32_t' type
  44. #end
  45. Alias uint32_t:UInt
  46. #rem monkeydoc C/C++ 'int64_t' type
  47. #end
  48. Alias int64_t:Long
  49. #rem monkeydoc C/C++ 'uint64_t' type
  50. #end
  51. Alias uint64_t:ULong
  52. #rem monkeydoc C/C++ 'intptr_t' type
  53. #end
  54. Alias intptr_t:ULong
  55. #rem monkeydoc C/C++ 'uintptr_t' type
  56. #end
  57. Alias uintptr_t:ULong
  58. Function sizeof<T>:size_t( t:T )="sizeof"
  59. Public
  60. Function sizeof<T>:size_t()
  61. Return libc.sizeof( Cast<T Ptr>(0)[0] )
  62. End
  63. Extern
  64. '***** limits.h *****
  65. Const PATH_MAX:Int
  66. '***** stdio.h *****
  67. Struct FILE
  68. End
  69. Const stdin:FILE Ptr
  70. Const stdout:FILE Ptr
  71. Const stderr:FILE Ptr
  72. Const SEEK_SET:Int
  73. Const SEEK_CUR:Int
  74. Const SEEK_END:Int
  75. Function fopen:FILE Ptr( path:CString,mode:CString )="fopen_utf8"
  76. Function rewind:Void( stream:FILE )
  77. Function ftell:Int( stream:FILE Ptr )
  78. Function fseek:Int( stream:FILE Ptr,offset:Int,whence:Int )
  79. Function fread:Int( buf:Void Ptr,size:Int,count:Int,stream:FILE Ptr )
  80. Function fwrite:Int( buf:Void Ptr,size:Int,count:Int,stream:FILE Ptr )
  81. Function fflush:Int( stream:FILE Ptr )
  82. Function fclose:Int( stream:FILE Ptr )
  83. Function fputs:Int( str:CString,stream:FILE Ptr )="fputs_utf8"
  84. Function remove:Int( path:CString )="remove_utf8"
  85. Function rename:Int( oldPath:CString,newPath:CString )="rename_utf8"
  86. Function puts:Int( str:CString )="puts_utf8"
  87. '***** stdlib.h *****
  88. Function malloc:Void Ptr( size:Int )
  89. Function free:Void( mem:Void Ptr )
  90. #If __TARGET__<>"ios" 'gone in ios11!
  91. Function system:Int( cmd:CString )="system_utf8"
  92. #endif
  93. Function setenv:Int( name:CString,value:CString,overwrite:Int )="setenv_utf8"
  94. Function getenv:char_t Ptr( name:CString )="getenv_utf8"
  95. Function exit_:Void( status:Int )="exit"
  96. Function atexit:Int( func:Void() )="atexit"
  97. Function abort:Void()
  98. Function realpath:char_t Ptr( path:CString,resolved_path:char_t Ptr )="realpath_utf8"
  99. '***** string.h *****
  100. Function strlen:Int( str:CString )
  101. Function memset:Void Ptr( dst:Void Ptr,value:Int,count:Int )
  102. Function memcpy:Void Ptr( dst:Void Ptr,src:Void Ptr,length:Int )
  103. Function memmove:Void Ptr( dst:Void Ptr,src:Void Ptr,length:Int )
  104. Function memcmp:Int( dst:Void Ptr,src:Void Ptr,length:Int )
  105. '***** time.h *****
  106. Struct time_t
  107. End
  108. Struct tm_t
  109. Field tm_sec:Int
  110. Field tm_min:Int
  111. Field tm_hour:Int
  112. Field tm_mday:Int
  113. Field tm_mon:Int
  114. Field tm_year:Int
  115. Field tm_wday:Int
  116. Field tm_yday:Int
  117. Field tm_isdst:Int
  118. End
  119. Struct timeval
  120. Field tv_sec:Long 'dodgy - should be time_t
  121. Field tv_usec:Long 'dodyy - should be suseconds_t
  122. End
  123. Struct timezone
  124. End
  125. 'Note: clock() scary - pauses while process sleeps!
  126. Const CLOCKS_PER_SEC:Long="((bbLong)CLOCKS_PER_SEC)"
  127. Function clock:Long()="(bbLong)clock"
  128. Function tolong:Long( timer:time_t )="bbLong"
  129. Function time:time_t( timer:time_t Ptr )
  130. Function localtime:tm_t Ptr( timer:time_t Ptr )
  131. Function gmtime:tm_t Ptr( timer:time_t Ptr )
  132. Function difftime:Double( endtime:time_t,starttime:time_t )
  133. Function gettimeofday:Int( tv:timeval Ptr )="gettimeofday_utf8"
  134. Function mktime:time_t( tm:tm_t Ptr )
  135. '***** unistd.h *****
  136. Function getcwd:char_t Ptr( buf:char_t Ptr,size:Int )="getcwd_utf8"
  137. Function chdir:Int( path:CString )="chdir_utf8"
  138. Function rmdir:Int( path:CString )="rmdir_utf8"
  139. '***** sys/stat.h *****
  140. Enum mode_t
  141. End
  142. Const S_IFMT:mode_t '$f000
  143. Const S_IFIFO:mode_t '$1000
  144. Const S_IFCHR:mode_t '$2000
  145. Const S_IFBLK:mode_t '$3000
  146. Const S_IFDIR:mode_t '$4000
  147. Const S_IFREG:mode_t '$8000
  148. Struct stat_t
  149. Field st_mode:mode_t
  150. Field st_size:Long
  151. Field st_atime:time_t 'last access
  152. Field st_mtime:time_t 'last modification
  153. Field st_ctime:time_t 'status change
  154. End
  155. Function stat:Int( path:CString,buf:stat_t Ptr )="stat_utf8"
  156. Function mkdir:Int( path:CString,mode:Int )="mkdir_utf8"
  157. '***** dirent.h *****
  158. Struct DIR
  159. End
  160. Struct dirent
  161. Field d_name:CString
  162. End
  163. Function opendir:DIR Ptr( path:CString )="opendir_utf8"
  164. Function readdir:dirent Ptr( dir:DIR Ptr )="readdir_utf8"
  165. Function closedir( dir:DIR Ptr )="closedir_utf8"
  166. Public