2
0

sysos.inc 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2001 by Free Pascal development team
  4. This file implements all the base types and limits required
  5. for a minimal POSIX compliant subset required to port the compiler
  6. to a new OS.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. const
  14. { constants for GetStdHandle }
  15. STD_INPUT_HANDLE = longint($fffffff6);
  16. STD_OUTPUT_HANDLE = longint($fffffff5);
  17. STD_ERROR_HANDLE = longint($fffffff4);
  18. INVALID_HANDLE_VALUE = longint($ffffffff);
  19. IGNORE = 0; { Ignore signal }
  20. INFINITE = longint($FFFFFFFF); { Infinite timeout }
  21. { flags for CreateFile }
  22. GENERIC_READ=$80000000;
  23. GENERIC_WRITE=$40000000;
  24. CREATE_NEW = 1;
  25. CREATE_ALWAYS = 2;
  26. OPEN_EXISTING = 3;
  27. OPEN_ALWAYS = 4;
  28. TRUNCATE_EXISTING = 5;
  29. FILE_ATTRIBUTE_ARCHIVE = 32;
  30. FILE_ATTRIBUTE_COMPRESSED = 2048;
  31. FILE_ATTRIBUTE_NORMAL = 128;
  32. FILE_ATTRIBUTE_DIRECTORY = 16;
  33. FILE_ATTRIBUTE_HIDDEN = 2;
  34. FILE_ATTRIBUTE_READONLY = 1;
  35. FILE_ATTRIBUTE_SYSTEM = 4;
  36. FILE_ATTRIBUTE_TEMPORARY = 256;
  37. { Share mode open }
  38. fmShareCompat = $00000000;
  39. fmShareExclusive = $10;
  40. fmShareDenyWrite = $20;
  41. fmShareDenyRead = $30;
  42. fmShareDenyNone = $40;
  43. { flags for SetFilePos }
  44. FILE_BEGIN = 0;
  45. FILE_CURRENT = 1;
  46. FILE_END = 2;
  47. { GetFileType }
  48. FILE_TYPE_UNKNOWN = 0;
  49. FILE_TYPE_DISK = 1;
  50. FILE_TYPE_CHAR = 2;
  51. FILE_TYPE_PIPE = 3;
  52. VER_PLATFORM_WIN32s = 0;
  53. VER_PLATFORM_WIN32_WINDOWS = 1;
  54. VER_PLATFORM_WIN32_NT = 2;
  55. { These constants are used for conversion of error codes }
  56. { from win32 i/o errors to tp i/o errors }
  57. { errors 1 to 18 are the same as in Turbo Pascal }
  58. { DO NOT MODIFY UNLESS YOU KNOW EXACTLY WHAT YOU ARE DOING! }
  59. { The media is write protected. }
  60. ERROR_WRITE_PROTECT = 19;
  61. { The system cannot find the device specified. }
  62. ERROR_BAD_UNIT = 20;
  63. { The device is not ready. }
  64. ERROR_NOT_READY = 21;
  65. { The device does not recognize the command. }
  66. ERROR_BAD_COMMAND = 22;
  67. { Data error (cyclic redundancy check) }
  68. ERROR_CRC = 23;
  69. { The program issued a command but the }
  70. { command length is incorrect. }
  71. ERROR_BAD_LENGTH = 24;
  72. { The drive cannot locate a specific }
  73. { area or track on the disk. }
  74. ERROR_SEEK = 25;
  75. { The specified disk or diskette cannot be accessed. }
  76. ERROR_NOT_DOS_DISK = 26;
  77. { The drive cannot find the sector requested. }
  78. ERROR_SECTOR_NOT_FOUND = 27;
  79. { The printer is out of paper. }
  80. ERROR_OUT_OF_PAPER = 28;
  81. { The system cannot write to the specified device. }
  82. ERROR_WRITE_FAULT = 29;
  83. { The system cannot read from the specified device. }
  84. ERROR_READ_FAULT = 30;
  85. { A device attached to the system is not functioning.}
  86. ERROR_GEN_FAILURE = 31;
  87. { The process cannot access the file because }
  88. { it is being used by another process. }
  89. ERROR_SHARING_VIOLATION = 32;
  90. { A pipe has been closed on the other end }
  91. { Removing that error allows eof to works as on other OSes }
  92. ERROR_BROKEN_PIPE = 109;
  93. ERROR_DIR_NOT_EMPTY = 145;
  94. ERROR_ALREADY_EXISTS = 183;
  95. type
  96. {UINT = longint;
  97. BOOL = longint; obsolete }
  98. UINT = cardinal;
  99. BOOL = longbool;
  100. // WCHAR = word;
  101. {$ifdef UNICODE}
  102. LPTCH = ^word;
  103. LPTSTR = ^word;
  104. LPCTSTR = ^word;
  105. {$else UNICODE}
  106. LPTCH = ^char;
  107. LPTSTR = ^char;
  108. LPCTSTR = ^char;
  109. {$endif UNICODE}
  110. LPWSTR = ^wchar;
  111. PVOID = pointer;
  112. LPVOID = pointer;
  113. LPCVOID = pointer;
  114. LPDWORD = ^DWORD;
  115. HLocal = THandle;
  116. PStr = pchar;
  117. LPStr = pchar;
  118. PLPSTR = ^LPSTR;
  119. PLPWSTR = ^LPWSTR;
  120. PSecurityAttributes = ^TSecurityAttributes;
  121. TSecurityAttributes = packed record
  122. nLength : DWORD;
  123. lpSecurityDescriptor : Pointer;
  124. bInheritHandle : BOOL;
  125. end;
  126. PProcessInformation = ^TProcessInformation;
  127. TProcessInformation = record
  128. hProcess: THandle;
  129. hThread: THandle;
  130. dwProcessId: DWORD;
  131. dwThreadId: DWORD;
  132. end;
  133. PFileTime = ^TFileTime;
  134. TFileTime = record
  135. dwLowDateTime,
  136. dwHighDateTime : DWORD;
  137. end;
  138. LPSystemTime= ^PSystemTime;
  139. PSystemTime = ^TSystemTime;
  140. TSystemTime = record
  141. wYear,
  142. wMonth,
  143. wDayOfWeek,
  144. wDay,
  145. wHour,
  146. wMinute,
  147. wSecond,
  148. wMilliseconds: Word;
  149. end;
  150. {$IFDEF SUPPORT_THREADVAR}
  151. threadvar
  152. {$ELSE SUPPORT_THREADVAR}
  153. var
  154. {$ENDIF SUPPORT_THREADVAR}
  155. errno : longint;
  156. {$ASMMODE ATT}
  157. { misc. functions }
  158. function GetLastError : DWORD;
  159. stdcall;external 'kernel32' name 'GetLastError';
  160. { time and date functions }
  161. function GetTickCount : longint;
  162. stdcall;external 'kernel32' name 'GetTickCount';
  163. { process functions }
  164. procedure ExitProcess(uExitCode : UINT);
  165. stdcall;external 'kernel32' name 'ExitProcess';
  166. { Startup }
  167. procedure GetStartupInfo(p : pointer);
  168. stdcall;external 'kernel32' name 'GetStartupInfoA';
  169. function GetStdHandle(nStdHandle:DWORD):THANDLE;
  170. stdcall;external 'kernel32' name 'GetStdHandle';
  171. { command line/enviroment functions }
  172. function GetCommandLine : pchar;
  173. stdcall;external 'kernel32' name 'GetCommandLineA';
  174. function GetCurrentProcessId:DWORD;
  175. stdcall; external 'kernel32' name 'GetCurrentProcessId';
  176. function Win32GetCurrentThreadId:DWORD;
  177. stdcall; external 'kernel32' name 'GetCurrentThreadId';
  178. { module functions }
  179. function GetModuleFileName(l1:longint;p:pointer;l2:longint):longint;
  180. stdcall;external 'kernel32' name 'GetModuleFileNameA';
  181. function GetModuleHandle(p : pointer) : longint;
  182. stdcall;external 'kernel32' name 'GetModuleHandleA';
  183. function GetCommandFile:pchar;forward;
  184. { file functions }
  185. function WriteFile(fh:thandle;buf:pointer;len:longint;var loaded:longint;
  186. overlap:pointer):longint;
  187. stdcall;external 'kernel32' name 'WriteFile';
  188. function ReadFile(fh:thandle;buf:pointer;len:longint;var loaded:longint;
  189. overlap:pointer):longint;
  190. stdcall;external 'kernel32' name 'ReadFile';
  191. function CloseHandle(h : thandle) : longint;
  192. stdcall;external 'kernel32' name 'CloseHandle';
  193. function DeleteFile(p : pchar) : longint;
  194. stdcall;external 'kernel32' name 'DeleteFileA';
  195. function MoveFile(old,_new : pchar) : longint;
  196. stdcall;external 'kernel32' name 'MoveFileA';
  197. function SetFilePointer(l1,l2 : thandle;l3 : pointer;l4 : longint) : longint;
  198. stdcall;external 'kernel32' name 'SetFilePointer';
  199. function GetFileSize(h:thandle;p:pointer) : longint;
  200. stdcall;external 'kernel32' name 'GetFileSize';
  201. function CreateFile(lpFileName:pchar; dwDesiredAccess:DWORD; dwShareMode:DWORD;
  202. lpSecurityAttributes:PSECURITYATTRIBUTES; dwCreationDisposition:DWORD;
  203. dwFlagsAndAttributes:DWORD; hTemplateFile:DWORD):longint;
  204. stdcall;external 'kernel32' name 'CreateFileA';
  205. function SetEndOfFile(h : thandle) : longbool;
  206. stdcall;external 'kernel32' name 'SetEndOfFile';
  207. function GetFileType(Handle:thandle):DWord;
  208. stdcall;external 'kernel32' name 'GetFileType';
  209. function GetFileAttributes(p : pchar) : dword;
  210. stdcall;external 'kernel32' name 'GetFileAttributesA';
  211. { Directory }
  212. function CreateDirectory(name : pointer;sec : pointer) : longbool;
  213. stdcall;external 'kernel32' name 'CreateDirectoryA';
  214. function RemoveDirectory(name:pointer):longbool;
  215. stdcall;external 'kernel32' name 'RemoveDirectoryA';
  216. function SetCurrentDirectory(name : pointer) : longbool;
  217. stdcall;external 'kernel32' name 'SetCurrentDirectoryA';
  218. function GetCurrentDirectory(bufsize : longint;name : pchar) : longbool;
  219. stdcall;external 'kernel32' name 'GetCurrentDirectoryA';
  220. Procedure Errno2InOutRes;
  221. Begin
  222. { DO NOT MODIFY UNLESS YOU KNOW EXACTLY WHAT YOU ARE DOING }
  223. case Errno of
  224. ERROR_WRITE_PROTECT..ERROR_GEN_FAILURE :
  225. begin
  226. { This is the offset to the Win32 to add to directly map }
  227. { to the DOS/TP compatible error codes when in this range }
  228. InOutRes := word(errno)+131;
  229. end;
  230. ERROR_DIR_NOT_EMPTY,
  231. ERROR_ALREADY_EXISTS,
  232. ERROR_SHARING_VIOLATION :
  233. begin
  234. InOutRes :=5;
  235. end;
  236. else
  237. begin
  238. { other error codes can directly be mapped }
  239. InOutRes := Word(errno);
  240. end;
  241. end;
  242. errno:=0;
  243. end;