system.pp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time librar~y.
  4. Copyright (c) 2000 by Marco van de Voort
  5. member of the Free Pascal development team.
  6. System unit for the *BSD's.
  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. { These things are set in the makefile, }
  14. { But you can override them here.}
  15. { If you use an aout system, set the conditional AOUT}
  16. { $Define AOUT}
  17. Unit {$ifdef VER1_0}Syslinux{$else}System{$endif};
  18. Interface
  19. {$define oldreaddir}
  20. {$define usedomain}
  21. {$define posixworkaround}
  22. {$define FPC_IS_SYSTEM}
  23. {$I sysunixh.inc}
  24. Implementation
  25. {$ifdef FPC_USE_LIBC}
  26. const clib = 'c';
  27. type libcint=longint;
  28. plibcint=^libcint;
  29. function geterrnolocation: Plibcint; cdecl;external clib name'__errno_location';
  30. function geterrno:libcint; [public, alias: 'FPC_SYS_GETERRNO'];
  31. begin
  32. geterrno:=geterrnolocation^;
  33. end;
  34. procedure seterrno(err:libcint); [public, alias: 'FPC_SYS_SETERRNO'];
  35. begin
  36. geterrnolocation^:=err;
  37. end;
  38. {$else}
  39. {$ifdef ver1_0}
  40. Var
  41. {$else}
  42. ThreadVar
  43. {$endif}
  44. Errno : longint;
  45. function geterrno:longint; [public, alias: 'FPC_SYS_GETERRNO'];
  46. begin
  47. GetErrno:=Errno;
  48. end;
  49. procedure seterrno(err:longint); [public, alias: 'FPC_SYS_SETERRNO'];
  50. begin
  51. Errno:=err;
  52. end;
  53. {$endif}
  54. {$I system.inc}
  55. { OS dependant parts }
  56. {$I errno.inc} // error numbers
  57. {$I bunxtype.inc} // c-types, unix base types, unix
  58. // base structures
  59. {$I ossysc.inc} // base syscalls
  60. {$I osmain.inc} // base wrappers *nix RTL (derivatives)
  61. { more OS independant parts}
  62. {$I text.inc}
  63. {$I heap.inc}
  64. {*****************************************************************************
  65. UnTyped File Handling
  66. *****************************************************************************}
  67. {$i file.inc}
  68. {*****************************************************************************
  69. Typed File Handling
  70. *****************************************************************************}
  71. {$i typefile.inc}
  72. {*****************************************************************************
  73. Extra cdecl declarations for FPC_USE_LIBC for this os
  74. *****************************************************************************}
  75. {$ifdef FPC_USE_LIBC}
  76. Function fpReadLink(name,linkname:pchar;maxlen:cint):cint; cdecl; external name 'readlink';
  77. {$endif}
  78. procedure SysInitStdIO;
  79. begin
  80. OpenStdIO(Input,fmInput,StdInputHandle);
  81. OpenStdIO(Output,fmOutput,StdOutputHandle);
  82. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  83. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  84. end;
  85. procedure SysInitExecPath;
  86. var
  87. hs : string[16];
  88. link : string;
  89. i : longint;
  90. begin
  91. str(Fpgetpid,hs);
  92. hs:='/proc/'+hs+'/exe'#0;
  93. i:=Fpreadlink(@hs[1],@link[1],high(link));
  94. { it must also be an absolute filename, linux 2.0 points to a memory
  95. location so this will skip that }
  96. if (i>0) and (link[1]='/') then
  97. begin
  98. link[0]:=chr(i);
  99. ExecPathStr:=link;
  100. end;
  101. end;
  102. Begin
  103. IsConsole := TRUE;
  104. IsLibrary := FALSE;
  105. StackLength := InitialStkLen;
  106. StackBottom := Sptr - StackLength;
  107. { Set up signals handlers }
  108. InstallSignals;
  109. { Setup heap }
  110. InitHeap;
  111. SysInitExceptions;
  112. { Arguments }
  113. SetupCmdLine;
  114. SysInitExecPath;
  115. { Setup stdin, stdout and stderr }
  116. SysInitStdIO;
  117. { Reset IO Error }
  118. InOutRes:=0;
  119. {$ifdef HASVARIANT}
  120. initvariantmanager;
  121. {$endif HASVARIANT}
  122. End.
  123. {
  124. $Log$
  125. Revision 1.11 2003-12-30 16:26:10 marco
  126. * some more fixes. Testing on idefix
  127. Revision 1.10 2003/12/30 15:43:20 marco
  128. * linux now compiles with FPC_USE_LIBC
  129. Revision 1.9 2003/12/30 12:36:56 marco
  130. * FPC_USE_LIBC
  131. Revision 1.8 2003/09/14 20:15:01 marco
  132. * Unix reform stage two. Remove all calls from Unix that exist in Baseunix.
  133. Revision 1.7 2003/04/30 22:11:06 florian
  134. + for a lot of x86-64 dependend files mostly dummies added
  135. Revision 1.6 2002/12/27 18:36:16 peter
  136. * Setup ExecPathStr for ParamStr(0)
  137. Revision 1.5 2002/12/18 20:42:29 peter
  138. * initial stacklen setup
  139. Revision 1.3 2002/12/18 16:44:09 marco
  140. * more new RTL
  141. Revision 1.7 2002/11/12 14:57:48 marco
  142. * Ugly hack to temporarily be able to use system.pp for Linux too
  143. Revision 1.6 2002/10/27 11:58:30 marco
  144. * Modifications from Saturday.
  145. Revision 1.5 2002/10/26 18:27:51 marco
  146. * First series POSIX calls commits. Including getcwd.
  147. Revision 1.4 2002/10/18 12:19:58 marco
  148. * Fixes to get the generic *BSD RTL compiling again + fixes for thread
  149. support. Still problems left in fexpand. (inoutres?) Therefore fixed
  150. sysposix not yet commited
  151. Revision 1.3 2002/10/13 09:25:39 florian
  152. + call to initvariantmanager inserted
  153. Revision 1.2 2002/09/07 16:01:17 peter
  154. * old logs removed and tabs fixed
  155. Revision 1.1 2002/08/19 12:29:11 marco
  156. * First working POSIX *BSD system unit.
  157. }