libc.monkey2 3.2 KB

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