sysos.inc 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. {*****************************************************************************
  14. AmigaOS structures
  15. *****************************************************************************}
  16. {$include execd.inc}
  17. {$include timerd.inc}
  18. {$include doslibd.inc}
  19. {*****************************************************************************
  20. AmigaOS functions
  21. *****************************************************************************}
  22. {$include execf.inc}
  23. {$include doslibf.inc}
  24. {*****************************************************************************
  25. CPU specific
  26. *****************************************************************************}
  27. {$ifdef cpum68k}
  28. {$include m68kamiga.inc}
  29. {$endif}
  30. {*****************************************************************************
  31. System Dependent Structures/Consts
  32. *****************************************************************************}
  33. const
  34. CTRL_C = 20; { Error code on CTRL-C press }
  35. { Used for CTRL_C checking in I/O calls }
  36. procedure checkCTRLC;
  37. begin
  38. if BreakOn then begin
  39. if (SetSignal(0,0) And SIGBREAKF_CTRL_C)<>0 then begin
  40. { Clear CTRL-C signal }
  41. SetSignal(0,SIGBREAKF_CTRL_C);
  42. Halt(CTRL_C);
  43. end;
  44. end;
  45. end;
  46. { Converts a AmigaOS dos.library error code to a TP compatible error code }
  47. { Based on 1.0.x Amiga RTL }
  48. procedure dosError2InOut(errno: LongInt);
  49. begin
  50. case errno of
  51. ERROR_BAD_NUMBER,
  52. ERROR_ACTION_NOT_KNOWN,
  53. ERROR_NOT_IMPLEMENTED : InOutRes := 1;
  54. ERROR_OBJECT_NOT_FOUND : InOutRes := 2;
  55. ERROR_DIR_NOT_FOUND : InOutRes := 3;
  56. ERROR_DISK_WRITE_PROTECTED : InOutRes := 150;
  57. ERROR_OBJECT_WRONG_TYPE : InOutRes := 151;
  58. ERROR_OBJECT_EXISTS,
  59. ERROR_DELETE_PROTECTED,
  60. ERROR_WRITE_PROTECTED,
  61. ERROR_READ_PROTECTED,
  62. ERROR_OBJECT_IN_USE,
  63. ERROR_DIRECTORY_NOT_EMPTY : InOutRes := 5;
  64. ERROR_NO_MORE_ENTRIES : InOutRes := 18;
  65. ERROR_RENAME_ACROSS_DEVICES : InOutRes := 17;
  66. ERROR_DISK_FULL : InOutRes := 101;
  67. ERROR_INVALID_RESIDENT_LIBRARY : InoutRes := 153;
  68. ERROR_BAD_HUNK : InOutRes := 153;
  69. ERROR_NOT_A_DOS_DISK : InOutRes := 157;
  70. ERROR_NO_DISK,
  71. ERROR_DISK_NOT_VALIDATED,
  72. ERROR_DEVICE_NOT_MOUNTED : InOutRes := 152;
  73. ERROR_SEEK_ERROR : InOutRes := 156;
  74. ERROR_LOCK_COLLISION,
  75. ERROR_LOCK_TIMEOUT,
  76. ERROR_UNLOCK_ERROR,
  77. ERROR_INVALID_LOCK,
  78. ERROR_INVALID_COMPONENT_NAME,
  79. ERROR_BAD_STREAM_NAME,
  80. ERROR_FILE_NOT_OBJECT : InOutRes := 6;
  81. else
  82. InOutRes := errno;
  83. end;
  84. end;
  85. { Converts an Unix-like path to Amiga-like path }
  86. function PathConv(path: string): string; alias: 'PATHCONV'; [public];
  87. var tmppos: longint;
  88. begin
  89. { check for short paths }
  90. if length(path)<=2 then begin
  91. if (path='.') or (path='./') then path:='' else
  92. if path='..' then path:='/' else
  93. if path='*' then path:='#?';
  94. end else begin
  95. { convert parent directories }
  96. tmppos:=pos('../',path);
  97. while tmppos<>0 do begin
  98. { delete .. to have / as parent dir sign }
  99. delete(path,tmppos,2);
  100. tmppos:=pos('../',path);
  101. end;
  102. { convert current directories }
  103. tmppos:=pos('./',path);
  104. while tmppos<>0 do begin
  105. { delete ./ since we doesn't need to sign current directory }
  106. delete(path,tmppos,2);
  107. tmppos:=pos('./',path);
  108. end;
  109. { convert wildstar to #? }
  110. tmppos:=pos('*',path);
  111. while tmppos<>0 do begin
  112. delete(path,tmppos,1);
  113. insert('#?',path,tmppos);
  114. tmppos:=pos('*',path);
  115. end;
  116. end;
  117. PathConv:=path;
  118. end;
  119. { Converts an Unix-like path to Amiga-like path }
  120. function PathConv(const path: rawbytestring): rawbytestring; alias: 'PATHCONVRBS'; [public];
  121. var tmppos: longint;
  122. begin
  123. { check for short paths }
  124. if length(path)<=2 then begin
  125. if (path='.') or (path='./') then PathConv:='' else
  126. if path='..' then PathConv:='/' else
  127. if path='*' then PathConv:='#?'
  128. else PathConv:=path;
  129. end else begin
  130. { convert parent directories }
  131. PathConv:=path;
  132. tmppos:=pos('../',PathConv);
  133. while tmppos<>0 do begin
  134. { delete .. to have / as parent dir sign }
  135. delete(PathConv,tmppos,2);
  136. tmppos:=pos('../',PathConv);
  137. end;
  138. { convert current directories }
  139. tmppos:=pos('./',PathConv);
  140. while tmppos<>0 do begin
  141. { delete ./ since we doesn't need to sign current directory }
  142. delete(PathConv,tmppos,2);
  143. tmppos:=pos('./',PathConv);
  144. end;
  145. { convert wildstar to #? }
  146. tmppos:=pos('*',PathConv);
  147. while tmppos<>0 do begin
  148. delete(PathConv,tmppos,1);
  149. insert('#?',PathConv,tmppos);
  150. tmppos:=pos('*',PathConv);
  151. end;
  152. end;
  153. end;
  154. { Thread Init/Exit Procedure support }
  155. Type
  156. PThreadProcInfo = ^TThreadProcInfo;
  157. TThreadProcInfo = Record
  158. Next : PThreadProcInfo;
  159. Proc : TProcedure;
  160. End;
  161. const
  162. threadInitProcList :PThreadProcInfo = nil;
  163. threadExitProcList :PThreadProcInfo = nil;
  164. Procedure DoThreadProcChain(p: PThreadProcInfo);
  165. Begin
  166. while p <> nil do
  167. begin
  168. p^.proc;
  169. p:=p^.next;
  170. end;
  171. End;
  172. Procedure AddThreadProc(var procList: PThreadProcInfo; Proc: TProcedure);
  173. var
  174. P : PThreadProcInfo;
  175. Begin
  176. New(P);
  177. P^.Next:=procList;
  178. P^.Proc:=Proc;
  179. procList:=P;
  180. End;
  181. Procedure CleanupThreadProcChain(var procList: PThreadProcInfo);
  182. var
  183. P : PThreadProcInfo;
  184. Begin
  185. while procList <> nil do
  186. begin
  187. p:=procList;
  188. procList:=procList^.next;
  189. dispose(p);
  190. end;
  191. End;
  192. Procedure AddThreadInitProc(Proc: TProcedure);
  193. Begin
  194. AddThreadProc(threadInitProcList,Proc);
  195. End;
  196. Procedure AddThreadExitProc(Proc: TProcedure);
  197. Begin
  198. AddThreadProc(threadExitProcList,Proc);
  199. End;
  200. Procedure DoThreadInitProcChain;
  201. Begin
  202. DoThreadProcChain(threadInitProcList);
  203. End;
  204. Procedure DoThreadExitProcChain;
  205. Begin
  206. DoThreadProcChain(threadExitProcList);
  207. End;