sysos.inc 6.1 KB

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