stdc.bmx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. Rem
  2. Standard C library (And friends!) functions.
  3. To simplify life, this is a 'structless' interface meaning some functions have been wrapped.
  4. End Rem
  5. Strict
  6. Module Pub.StdC
  7. ModuleInfo "Version: 1.13"
  8. ModuleInfo "Author: Various"
  9. ModuleInfo "License: zlib/libpng"
  10. ModuleInfo "Modserver: BRL"
  11. ModuleInfo "Credit: Adapted for BlitzMax by Mark Sibly"
  12. ModuleInfo "History: 1.13 Release"
  13. ModuleInfo "History: Added totally awesome stat_() hack for '<' and '>' in Win32 paths"
  14. ModuleInfo "History: 1.12 Release"
  15. ModuleInfo "History: remove_ now does a chmod 0x1b6 beforehand on Win32 - ie: will remove write protected files"
  16. ModuleInfo "History: chmod_ now does something on Win32"
  17. ModuleInfo "History: 1.11 Release"
  18. ModuleInfo "History: Fixed getsockopt"
  19. ModuleInfo "History: 1.10 Release"
  20. ModuleInfo "History: Fixed network byte ordering for sento_ and recvfrom_"
  21. ModuleInfo "History: 1.09 Release"
  22. ModuleInfo "History: More socket stuff added"
  23. ModuleInfo "History: 1.07 Release"
  24. ModuleInfo "History: More socket stuff added"
  25. ModuleInfo "History: 1.06 Release"
  26. ModuleInfo "History: Cleaned up Win32 system_"
  27. ModuleInfo "History: 1.05 Release"
  28. ModuleInfo "History: 1.04 Release"
  29. ModuleInfo "History: Fixed C Compiler warnings"
  30. Import "stdc.c"
  31. 'c lib
  32. Extern "c"
  33. Const SEEK_SET_=0
  34. Const SEEK_CUR_=1
  35. Const SEEK_END_=2
  36. Const S_IFMT_=$f000
  37. Const S_IFIFO_=$1000
  38. Const S_IFCHR_=$2000
  39. Const S_IFBLK_=$3000
  40. Const S_IFDIR_=$4000
  41. Const S_IFREG_=$8000
  42. Global stdin_
  43. Global stdout_
  44. Global stderr_
  45. Function getchar_()
  46. Function puts_( str$ )
  47. Function putenv_( str$ )
  48. Function getenv_$( env$ )
  49. 'file system
  50. Function fopen_( file$,mode$ )
  51. Function fclose_( c_stream )="fclose"
  52. Function fread_( buf:Byte Ptr,size,count,c_stream )="fread"
  53. Function fwrite_( buf:Byte Ptr,size,count,c_stream )="fwrite"
  54. Function fflush_( c_stream )="fflush"
  55. Function fseek_( c_stream,offset,origin )="fseek"
  56. Function ftell_( c_stream )="ftell"
  57. Function feof_( c_stream )="feof"
  58. Function fgetc_( c_stream )="fgetc"
  59. Function ungetc_( char,c_stream )="ungetc"
  60. Function fputs_( str$,c_stream )
  61. 'posix
  62. Function chdir_( dir$ )
  63. Function getcwd_$()
  64. Function chmod_( path$,mode )
  65. Function mkdir_( path$,mode )
  66. Function rmdir_( path$ )
  67. Function rename_( from_path$,to_path$ )
  68. Function remove_( path$ )
  69. Function opendir_( path$ )
  70. Function closedir_( dir )
  71. Function readdir_$( dir )
  72. Function stat_( path$,st_mode Var,st_size Var,st_mtime Var,st_ctime Var )
  73. Function system_( cmd$ )
  74. 'misc
  75. Function abort_()="abort"
  76. Function malloc_:Byte Ptr( size )="malloc"
  77. Function realloc_:Byte Ptr( p:Byte Ptr,size )="realloc"
  78. Function free_( buf:Byte Ptr )="free"
  79. Function exit_( exit_code )="exit"
  80. Function atexit_( fun() )="atexit"
  81. Function memset_( buf:Byte Ptr,val,size )="memset"
  82. Function memcmp_( lhs:Byte Ptr,rhs:Byte Ptr,size )="memcmp"
  83. Function memcpy_( dst:Byte Ptr,src:Byte Ptr,size )="memcpy"
  84. Function memmove_( dst:Byte Ptr,src:Byte Ptr,size )="memmove"
  85. 'math
  86. Function sin_!( n! )="sin"
  87. Function cos_!( n! )="cos"
  88. Function tan_!( n! )="tan"
  89. Function sinh_!( n! )="sinh"
  90. Function cosh_!( n! )="cosh"
  91. Function tanh_!( n! )="tanh"
  92. Function asin_!( n! )="asin"
  93. Function acos_!( n! )="acos"
  94. Function atan_!( n! )="atan"
  95. 'sockets
  96. Const AF_INET_=2 'address types
  97. Const SOCK_STREAM_=1,SOCK_DGRAM_=2 'communication types
  98. Const SOCKET_ERROR_=-1
  99. Const SO_DEBUG=1 'turn on debugging info recording
  100. Const SO_ACCEPTCONN=2 'socket has had listen()
  101. Const SO_REUSEADDR=4 'allow local address reuse
  102. Const SO_KEEPALIVE=8 'keep connections alive
  103. Const SO_DONTROUTE=$10 'just use interface addresses
  104. Const SO_BROADCAST=$20 'permit sending of broadcast msgs
  105. Const SO_USELOOPBACK=$40 'bypass hardware when possible
  106. Const SO_LINGER=$80 'linger on close if data present
  107. Const SO_OOBINLINE=$100 'leave received OOB data in line
  108. 'Additional options.
  109. Const SO_SNDBUF=$1001 'sendbuffersize
  110. Const SO_RCVBUF=$1002 'receivebuffersize
  111. Const SO_SNDLOWAT=$1003 'sendlow-watermark
  112. Const SO_RCVLOWAT=$1004 'receivelow-watermark
  113. Const SO_SNDTIMEO=$1005 'sendtimeout
  114. Const SO_RCVTIMEO=$1006 'receivetimeout
  115. Const SO_ERROR=$1007 'geterrorstatusandclear
  116. Const SO_TYPE=$1008 'getsockettype
  117. 'Option for opening sockets for synchronous access.
  118. Const SO_SYNCHRONOUS_ALERT=$10
  119. Const SO_SYNCHRONOUS_NONALERT=$20
  120. ?Win32
  121. Const SO_OPENTYPE=$7008
  122. Const SO_MAXDG=$7009
  123. Const SO_MAXPATHDG=$700A
  124. Const SO_UPDATE_ACCEPT_CONTEXT=$700B
  125. Const SO_CONNECT_TIME=$700C
  126. ?
  127. Const TCP_NODELAY=$0001
  128. Const TCP_BSDURGENT=$7000
  129. Const IPPROTO_UDP=17
  130. Const IPPROTO_TCP=6
  131. 'how params for shutdown_
  132. Const SD_SEND=1
  133. Const SD_RECEIVE=0
  134. Const SD_BOTH=2
  135. Function htons_( n )
  136. Function ntohs_( n )
  137. Function htonl_( n )
  138. Function ntohl_( n )
  139. Function socket_( addr_type,comm_type,protocol=0 )
  140. Function closesocket_( socket )
  141. Function bind_( socket,addr_type,port )
  142. Function gethostbyaddr_:Byte Ptr( addr:Byte Ptr,addr_len,addr_type )
  143. Function gethostbyname_:Byte Ptr Ptr( name$,addr_type Var,addr_len Var )
  144. Function connect_( socket,addr:Byte Ptr,addr_type,addr_len,port )
  145. Function listen_( socket,backlog )
  146. Function accept_( socket,addr:Byte Ptr,addr_len:Byte Ptr)
  147. Function select_( n_read,read_socks:Int Ptr,n_write,write_socks:Int Ptr,n_except,except_socks:Int Ptr,millis )
  148. Function send_( socket,buf:Byte Ptr,size,flags )
  149. Function sendto_( socket,buf:Byte Ptr,size,flags,dest_ip,dest_port )
  150. Function recv_( socket,buf:Byte Ptr,size,flags )
  151. Function recvfrom_( socket,buf:Byte Ptr,size,flags,sender_ip Var,sender_port Var)
  152. Function setsockopt_( socket,level,optname,optval:Byte Ptr,count)
  153. Function getsockopt_( socket,level,optname,optval:Byte Ptr,count Var)
  154. Function shutdown_( socket,how )
  155. Function getsockname_( socket,addr:Byte Ptr,addr_len Var )
  156. Function getpeername_( socket,addr:Byte Ptr,addr_len Var )
  157. 'time
  158. Function time_( time:Byte Ptr )
  159. Function localtime_:Byte Ptr( time:Byte Ptr )
  160. Function strftime_( buf:Byte Ptr,size,fmt$,time:Byte Ptr )
  161. End Extern
  162. Private
  163. Extern "c"
  164. Function Startup()="bb_stdc_Startup"
  165. End Extern
  166. Startup
  167. Public