libc.monkey2 3.2 KB

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