system.pp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. {$ifdef BSD}
  18. Unit {$ifdef VER1_0}SysBSD{$else}System{$endif};
  19. {$else}
  20. Unit {$ifdef VER1_0}Syslinux{$else}System{$endif};
  21. {$endif}
  22. Interface
  23. {$define oldreaddir}
  24. {$define usedomain}
  25. {$define posixworkaround}
  26. {$I sysunixh.inc}
  27. Implementation
  28. {$ifdef ver1_0}
  29. Var
  30. {$else}
  31. ThreadVar
  32. {$endif}
  33. Errno : longint;
  34. function geterrno:longint; [public, alias: 'FPC_SYS_GETERRNO'];
  35. begin
  36. GetErrno:=Errno;
  37. end;
  38. procedure seterrno(err:longint); [public, alias: 'FPC_SYS_SETERRNO'];
  39. begin
  40. Errno:=err;
  41. end;
  42. {$I system.inc}
  43. { OS dependant parts }
  44. {$I errno.inc} // error numbers
  45. {$I bunxtype.inc} // c-types, unix base types, unix
  46. // base structures
  47. {$I ossysc.inc} // base syscalls
  48. {$I osmain.inc} // base wrappers *nix RTL (derivatives)
  49. { more OS independant parts}
  50. {$I text.inc}
  51. {$I heap.inc}
  52. {*****************************************************************************
  53. UnTyped File Handling
  54. *****************************************************************************}
  55. {$i file.inc}
  56. {*****************************************************************************
  57. Typed File Handling
  58. *****************************************************************************}
  59. {$i typefile.inc}
  60. procedure SysInitStdIO;
  61. begin
  62. OpenStdIO(Input,fmInput,StdInputHandle);
  63. OpenStdIO(Output,fmOutput,StdOutputHandle);
  64. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  65. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  66. end;
  67. procedure SysInitExecPath;
  68. var
  69. hs : string[16];
  70. link : string;
  71. i : longint;
  72. begin
  73. str(Fpgetpid,hs);
  74. hs:='/proc/'+hs+'/exe'#0;
  75. i:=Fpreadlink(@hs[1],@link[1],high(link));
  76. { it must also be an absolute filename, linux 2.0 points to a memory
  77. location so this will skip that }
  78. if (i>0) and (link[1]='/') then
  79. begin
  80. link[0]:=chr(i);
  81. ExecPathStr:=link;
  82. end;
  83. end;
  84. Begin
  85. IsConsole := TRUE;
  86. IsLibrary := FALSE;
  87. StackLength := InitialStkLen;
  88. StackBottom := Sptr - StackLength;
  89. { Set up signals handlers }
  90. InstallSignals;
  91. { Setup heap }
  92. InitHeap;
  93. SysInitExceptions;
  94. { Arguments }
  95. SetupCmdLine;
  96. SysInitExecPath;
  97. { Setup stdin, stdout and stderr }
  98. SysInitStdIO;
  99. { Reset IO Error }
  100. InOutRes:=0;
  101. {$ifdef HASVARIANT}
  102. initvariantmanager;
  103. {$endif HASVARIANT}
  104. End.
  105. {
  106. $Log$
  107. Revision 1.8 2003-09-14 20:15:01 marco
  108. * Unix reform stage two. Remove all calls from Unix that exist in Baseunix.
  109. Revision 1.7 2003/04/30 22:11:06 florian
  110. + for a lot of x86-64 dependend files mostly dummies added
  111. Revision 1.6 2002/12/27 18:36:16 peter
  112. * Setup ExecPathStr for ParamStr(0)
  113. Revision 1.5 2002/12/18 20:42:29 peter
  114. * initial stacklen setup
  115. Revision 1.3 2002/12/18 16:44:09 marco
  116. * more new RTL
  117. Revision 1.7 2002/11/12 14:57:48 marco
  118. * Ugly hack to temporarily be able to use system.pp for Linux too
  119. Revision 1.6 2002/10/27 11:58:30 marco
  120. * Modifications from Saturday.
  121. Revision 1.5 2002/10/26 18:27:51 marco
  122. * First series POSIX calls commits. Including getcwd.
  123. Revision 1.4 2002/10/18 12:19:58 marco
  124. * Fixes to get the generic *BSD RTL compiling again + fixes for thread
  125. support. Still problems left in fexpand. (inoutres?) Therefore fixed
  126. sysposix not yet commited
  127. Revision 1.3 2002/10/13 09:25:39 florian
  128. + call to initvariantmanager inserted
  129. Revision 1.2 2002/09/07 16:01:17 peter
  130. * old logs removed and tabs fixed
  131. Revision 1.1 2002/08/19 12:29:11 marco
  132. * First working POSIX *BSD system unit.
  133. }