system.pp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 Linux.
  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. {$ifdef FPC_USE_LIBC}
  24. {$define usegetcwd}
  25. {$endif}
  26. {$I sysunixh.inc}
  27. Implementation
  28. {$I system.inc}
  29. procedure SysInitStdIO;
  30. begin
  31. OpenStdIO(Input,fmInput,StdInputHandle);
  32. OpenStdIO(Output,fmOutput,StdOutputHandle);
  33. OpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
  34. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  35. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  36. end;
  37. procedure SysInitExecPath;
  38. var
  39. i : longint;
  40. begin
  41. execpathstr[0]:=#0;
  42. i:=Fpreadlink('/proc/self/exe',@execpathstr[1],high(execpathstr));
  43. { it must also be an absolute filename, linux 2.0 points to a memory
  44. location so this will skip that }
  45. if (i>0) and (execpathstr[1]='/') then
  46. execpathstr[0]:=char(i);
  47. end;
  48. function GetProcessID: SizeUInt;
  49. begin
  50. GetProcessID := SizeUInt (fpGetPID);
  51. end;
  52. Begin
  53. IsConsole := TRUE;
  54. IsLibrary := FALSE;
  55. StackLength := InitialStkLen;
  56. StackBottom := Sptr - StackLength;
  57. { Set up signals handlers }
  58. InstallSignals;
  59. { Setup heap }
  60. InitHeap;
  61. SysInitExceptions;
  62. { Arguments }
  63. SetupCmdLine;
  64. SysInitExecPath;
  65. { Setup stdin, stdout and stderr }
  66. SysInitStdIO;
  67. { Reset IO Error }
  68. InOutRes:=0;
  69. { threading }
  70. InitSystemThreads;
  71. {$ifdef HASVARIANT}
  72. initvariantmanager;
  73. {$endif HASVARIANT}
  74. {$ifdef HASWIDESTRING}
  75. initwidestringmanager;
  76. {$endif HASWIDESTRING}
  77. End.
  78. {
  79. $Log$
  80. Revision 1.22 2005-02-06 11:20:52 peter
  81. * threading in system unit
  82. * removed systhrds unit
  83. Revision 1.21 2005/02/01 20:22:49 florian
  84. * improved widestring infrastructure manager
  85. Revision 1.20 2004/12/05 14:36:37 hajny
  86. + GetProcessID added
  87. Revision 1.19 2004/11/04 09:32:31 peter
  88. ErrOutput added
  89. Revision 1.18 2004/07/09 22:31:22 peter
  90. * fixed execpathstr setting
  91. Revision 1.17 2004/07/08 21:22:15 daniel
  92. * Tweaking...
  93. Revision 1.16 2004/07/08 19:45:42 daniel
  94. * Use /proc/self/exe instead of /proc/[getpid]/exe
  95. Revision 1.15 2004/06/17 16:16:13 peter
  96. * New heapmanager that releases memory back to the OS, donated
  97. by Micha Nelissen
  98. Revision 1.14 2004/01/20 23:09:14 hajny
  99. * ExecuteProcess fixes, ProcessID and ThreadID added
  100. Revision 1.13 2004/01/01 14:16:55 marco
  101. * getcwd missed cdecl
  102. Revision 1.12 2003/12/31 20:20:57 marco
  103. * small additions for getcwd what we need for FPC_USE_LIBC
  104. Revision 1.11 2003/12/30 16:26:10 marco
  105. * some more fixes. Testing on idefix
  106. Revision 1.10 2003/12/30 15:43:20 marco
  107. * linux now compiles with FPC_USE_LIBC
  108. Revision 1.9 2003/12/30 12:36:56 marco
  109. * FPC_USE_LIBC
  110. Revision 1.8 2003/09/14 20:15:01 marco
  111. * Unix reform stage two. Remove all calls from Unix that exist in Baseunix.
  112. Revision 1.7 2003/04/30 22:11:06 florian
  113. + for a lot of x86-64 dependend files mostly dummies added
  114. Revision 1.6 2002/12/27 18:36:16 peter
  115. * Setup ExecPathStr for ParamStr(0)
  116. Revision 1.5 2002/12/18 20:42:29 peter
  117. * initial stacklen setup
  118. Revision 1.3 2002/12/18 16:44:09 marco
  119. * more new RTL
  120. Revision 1.7 2002/11/12 14:57:48 marco
  121. * Ugly hack to temporarily be able to use system.pp for Linux too
  122. Revision 1.6 2002/10/27 11:58:30 marco
  123. * Modifications from Saturday.
  124. Revision 1.5 2002/10/26 18:27:51 marco
  125. * First series POSIX calls commits. Including getcwd.
  126. Revision 1.4 2002/10/18 12:19:58 marco
  127. * Fixes to get the generic *BSD RTL compiling again + fixes for thread
  128. support. Still problems left in fexpand. (inoutres?) Therefore fixed
  129. sysposix not yet commited
  130. Revision 1.3 2002/10/13 09:25:39 florian
  131. + call to initvariantmanager inserted
  132. Revision 1.2 2002/09/07 16:01:17 peter
  133. * old logs removed and tabs fixed
  134. Revision 1.1 2002/08/19 12:29:11 marco
  135. * First working POSIX *BSD system unit.
  136. }