libc.monkey2 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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++ 'intptr_t' type
  47. #end
  48. Alias intptr_t:ULong
  49. #rem monkeydoc C/C++ 'uintptr_t' type
  50. #end
  51. Alias uintptr_t:ULong
  52. Function sizeof<T>:size_t( t:T )="sizeof"
  53. '***** stdio.h *****
  54. Struct FILE
  55. End
  56. Const stdin:FILE Ptr
  57. Const stdout:FILE Ptr
  58. Const stderr:FILE Ptr
  59. Const SEEK_SET:Int
  60. Const SEEK_CUR:Int
  61. Const SEEK_END:Int
  62. Function fopen:FILE Ptr( path:CString,mode:CString )
  63. Function rewind:Void( stream:FILE )
  64. Function ftell:Int( stream:FILE Ptr )
  65. Function fseek:Int( stream:FILE Ptr,offset:Int,whence:Int )
  66. Function fread:Int( buf:Void Ptr,size:Int,count:Int,stream:FILE Ptr )
  67. Function fwrite:Int( buf:Void Ptr,size:Int,count:Int,stream:FILE Ptr )
  68. Function fflush:Int( stream:FILE Ptr )
  69. Function fclose:Int( stream:FILE Ptr )
  70. Function fputs:Int( str:CString,stream:FILE Ptr )
  71. Function remove:Int( path:CString )
  72. Function rename:Int( oldPath:CString,newPath:CString )
  73. Function puts:Int( str:CString )
  74. '***** stdlib.h *****
  75. Function malloc:Void Ptr( size:Int )
  76. Function free:Void( mem:Void Ptr )
  77. Function system:Int( cmd:CString )="system_"
  78. Function setenv:Int( name:CString,value:CString,overwrite:Int )="setenv_"
  79. Function getenv:char_t Ptr( name:CString )
  80. Function exit_:Void( status:Int )="exit"
  81. Function atexit:Int( func:Void() )="atexit"
  82. Function abort:Void()
  83. '***** string.h *****
  84. Function strlen:Int( str:CString )
  85. Function memset:Void Ptr( dst:Void Ptr,value:Int,count:Int )
  86. Function memcpy:Void Ptr( dst:Void Ptr,src:Void Ptr,length:Int )
  87. Function memmove:Void Ptr( dst:Void Ptr,src:Void Ptr,length:Int )
  88. Function memcmp:Int( dst:Void Ptr,src:Void Ptr,length:Int )
  89. '***** time.h *****
  90. Struct time_t
  91. End
  92. Struct tm_t
  93. Field tm_sec:Int
  94. Field tm_min:Int
  95. Field tm_hour:Int
  96. Field tm_mday:Int
  97. Field tm_mon:Int
  98. Field tm_year:Int
  99. Field tm_wday:Int
  100. Field tm_yday:Int
  101. Field tm_isdst:Int
  102. End
  103. Struct timeval
  104. Field tv_sec:Long 'dodgy - should be time_t
  105. Field tv_usec:Long 'dodyy - should be suseconds_t
  106. End
  107. Struct timezone
  108. End
  109. 'Note: clock() scary - pauses while process sleeps!
  110. Const CLOCKS_PER_SEC:Long="((bbLong)CLOCKS_PER_SEC)"
  111. Function clock:Long()="(bbLong)clock"
  112. Function tolong:Long( timer:time_t )="bbLong"
  113. Function time:time_t( timer:time_t Ptr )
  114. Function localtime:tm_t Ptr( timer:time_t Ptr )
  115. Function gmtime:tm_t Ptr( timer:time_t Ptr )
  116. Function difftime:Double( endtime:time_t,starttime:time_t )
  117. Function gettimeofday:Int( tv:timeval Ptr )="gettimeofday_"
  118. '***** unistd.h *****
  119. Function getcwd:char_t Ptr( buf:char_t Ptr,size:Int )
  120. Function chdir:Int( path:CString )
  121. Function rmdir:Int( path:CString )
  122. '***** sys/stat.h *****
  123. Enum mode_t
  124. End
  125. Const S_IFMT:mode_t '$f000
  126. Const S_IFIFO:mode_t '$1000
  127. Const S_IFCHR:mode_t '$2000
  128. Const S_IFBLK:mode_t '$3000
  129. Const S_IFDIR:mode_t '$4000
  130. Const S_IFREG:mode_t '$8000
  131. Struct stat_t
  132. Field st_mode:mode_t
  133. Field st_size:Long
  134. Field st_atime:time_t 'last access
  135. Field st_mtime:time_t 'last modification
  136. Field st_ctime:time_t 'status change
  137. End
  138. Function stat:Int( path:CString,buf:stat_t Ptr )
  139. Function mkdir:Int( path:CString,mode:Int )="mkdir_"
  140. '***** dirent.h *****
  141. Struct DIR
  142. End
  143. Struct dirent
  144. Field d_name:Void Ptr
  145. End
  146. Function opendir:DIR Ptr( path:CString )
  147. Function readdir:dirent Ptr( dir:DIR Ptr )
  148. Function closedir( dir:DIR Ptr )