libc.monkey2 3.6 KB

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