sysos.inc 9.1 KB

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