{
    $Id: system.pp,v 1.1.2.1 2001/12/20 02:55:01 carl Exp $
    This file is part of the Free Pascal run time library.
    Copyright (c) 1999-2000 by the Free Pascal development team.

    QNX system unit

    See the file COPYING.FPC, included in this distribution,
    for details about the copyright.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 **********************************************************************}
{ no stack check in system }

{$S-}
unit System;

interface

{ include system-independent routine headers }

{$I systemh.inc}

{ include heap support headers }

{$I heaph.inc}

var
  argc : longint;
  argv : ppchar;
  envp : ppchar;
  
  
var
  Errno : longint; external name 'errno';  { declared in libc } 
  

var
  UnusedHandle:longint;
  StdInputHandle:longint;
  StdOutputHandle:longint;
  StdErrorHandle:longint;
  
{Platform specific information}
const
 LineEnding = #10;
 LFNSupport = true;
 DirectorySeparator = '/';
 DriveSeparator = '';
 PathSeparator = ':';
 FileNameCaseSensitive  = True;
  

implementation


{$I system.inc}
{$i errno.inc}          { Error numbers                   }
{$I osposixh.inc}       { include POSIX types / constants }
{$I osposix.inc}        { include POSIX system calls      }

{$i sysposix.inc}






{*****************************************************************************
                              Heap Management
*****************************************************************************}

function malloc(size: size_t): pointer; cdecl; external name 'malloc';
{ IMPORTANT SOLARIS PORT NOTE: mmap() cannot be used, since ANONYMOUS      }
{ requests are only available starting from Solaris 8. sbrk() cannot       }
{ be used either since C libraries  linked in with the runtime library may }
{ use malloc(), and the man pages of Solaris indicate that mixing both     }
{ sbrk() and malloc() is a no-no.                                          }
function Sbrk(size : longint):longint;
var ptr : pointer;
begin
  ptr := malloc(size_t(size));
  if ptr = nil then
    sbrk := -1
  else
    begin
      sbrk := longint(ptr);
      errno := 0;
    end;
end;


{ include standard heap management }
{$I heap.inc}


{****************************************************************************
                        Low level File Routines
       All these functions can set InOutRes on errors
 ****************************************************************************}



function do_isdevice(handle:longint):boolean;
begin
  do_isdevice:= (handle=StdInputHandle) or
                (handle=StdOutputHandle) or
                (handle=StdErrorHandle);
end;


{*****************************************************************************
                           UnTyped File Handling
*****************************************************************************}

{$i file.inc}

{*****************************************************************************
                           Typed File Handling
*****************************************************************************}

{$i typefile.inc}

{*****************************************************************************
                           Text File Handling
*****************************************************************************}
{$DEFINE SHORT_LINEBREAK}
{ DEFINE EXTENDED_EOF}

{$i text.inc}

{*****************************************************************************
                         SystemUnit Initialization
*****************************************************************************}
var
  stacklength : longint;external name '__stklen';

begin
  { setup lowest value of stack pointer }
  StackBottom := SPtr - StackLength;
  InitHeap;
{ Set up signals handlers }
  InstallSignals;
{ Setup heap }
  InitExceptions;
{ Arguments }
  SetupCmdLine;
{ Setup IO }
  StdInputHandle:=0;
  StdOutputHandle:=1;
  StdErrorHandle:=2;

  OpenStdIO(Input,fmInput,StdInputHandle);
  OpenStdIO(Output,fmOutput,StdOutputHandle);
  OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  
{ Reset IO Error }
  InOutRes:=0;
end.


{
 $Log: system.pp,v $
 Revision 1.1.2.1  2001/12/20 02:55:01  carl
 + QNX versions (still untested)


}
