mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-05 05:13:25 +02:00
* Turn cmdline into property on Linux.
* Move some procedure in Linux system unit. git-svn-id: trunk@4964 -
This commit is contained in:
parent
7c915938d9
commit
bbc80554b1
@ -329,9 +329,6 @@ const
|
|||||||
fmInOut = $D7B3;
|
fmInOut = $D7B3;
|
||||||
fmAppend = $D7B4;
|
fmAppend = $D7B4;
|
||||||
Filemode : byte = 2;
|
Filemode : byte = 2;
|
||||||
{$ifndef HAS_CMDLINE}
|
|
||||||
CmdLine : PChar = nil;
|
|
||||||
{$endif HAS_CMDLINE}
|
|
||||||
(* Value should be changed during system initialization as appropriate. *)
|
(* Value should be changed during system initialization as appropriate. *)
|
||||||
|
|
||||||
{ assume that this program will not spawn other threads, when the
|
{ assume that this program will not spawn other threads, when the
|
||||||
@ -353,6 +350,11 @@ var
|
|||||||
{ Threading support }
|
{ Threading support }
|
||||||
fpc_threadvar_relocate_proc : pointer; public name 'FPC_THREADVAR_RELOCATE';
|
fpc_threadvar_relocate_proc : pointer; public name 'FPC_THREADVAR_RELOCATE';
|
||||||
|
|
||||||
|
{$ifndef HAS_CMDLINE}
|
||||||
|
{Value should be changed during system initialization as appropriate.}
|
||||||
|
var cmdline:Pchar=nil;
|
||||||
|
{$endif}
|
||||||
|
|
||||||
|
|
||||||
ThreadVar
|
ThreadVar
|
||||||
ThreadID : TThreadID;
|
ThreadID : TThreadID;
|
||||||
|
@ -25,15 +25,25 @@
|
|||||||
|
|
||||||
Unit System;
|
Unit System;
|
||||||
|
|
||||||
Interface
|
{*****************************************************************************}
|
||||||
|
interface
|
||||||
|
{*****************************************************************************}
|
||||||
|
|
||||||
{$define FPC_IS_SYSTEM}
|
{$define FPC_IS_SYSTEM}
|
||||||
|
{$define HAS_CMDLINE}
|
||||||
|
{$define USE_NOTHREADMANAGER}
|
||||||
|
|
||||||
{$i osdefs.inc}
|
{$i osdefs.inc}
|
||||||
|
|
||||||
{$I sysunixh.inc}
|
{$I sysunixh.inc}
|
||||||
|
|
||||||
Implementation
|
function get_cmdline:Pchar;
|
||||||
|
property cmdline:Pchar read get_cmdline;
|
||||||
|
|
||||||
|
|
||||||
|
{*****************************************************************************}
|
||||||
|
implementation
|
||||||
|
{*****************************************************************************}
|
||||||
|
|
||||||
{ Include ELF resources }
|
{ Include ELF resources }
|
||||||
|
|
||||||
@ -44,6 +54,7 @@ Implementation
|
|||||||
|
|
||||||
{$I system.inc}
|
{$I system.inc}
|
||||||
|
|
||||||
|
const calculated_cmdline:Pchar=nil;
|
||||||
|
|
||||||
{*****************************************************************************
|
{*****************************************************************************
|
||||||
Misc. System Dependent Functions
|
Misc. System Dependent Functions
|
||||||
@ -63,7 +74,7 @@ Begin
|
|||||||
End;
|
End;
|
||||||
|
|
||||||
|
|
||||||
function BackPos(c:char; const s: shortstring): integer;
|
{function BackPos(c:char; const s: shortstring): integer;
|
||||||
var
|
var
|
||||||
i: integer;
|
i: integer;
|
||||||
Begin
|
Begin
|
||||||
@ -73,7 +84,7 @@ Begin
|
|||||||
BackPos := 0
|
BackPos := 0
|
||||||
else
|
else
|
||||||
BackPos := i;
|
BackPos := i;
|
||||||
end;
|
end;}
|
||||||
|
|
||||||
|
|
||||||
{ variable where full path and filename and executable is stored }
|
{ variable where full path and filename and executable is stored }
|
||||||
@ -98,49 +109,10 @@ Begin
|
|||||||
randseed:=longint(Fptime(nil));
|
randseed:=longint(Fptime(nil));
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
|
||||||
{*****************************************************************************
|
{*****************************************************************************
|
||||||
SystemUnit Initialization
|
cmdline
|
||||||
*****************************************************************************}
|
*****************************************************************************}
|
||||||
|
|
||||||
function reenable_signal(sig : longint) : boolean;
|
|
||||||
var
|
|
||||||
e : TSigSet;
|
|
||||||
i,j : byte;
|
|
||||||
begin
|
|
||||||
fillchar(e,sizeof(e),#0);
|
|
||||||
{ set is 1 based PM }
|
|
||||||
dec(sig);
|
|
||||||
i:=sig mod (sizeof(cuLong) * 8);
|
|
||||||
j:=sig div (sizeof(cuLong) * 8);
|
|
||||||
e[j]:=1 shl i;
|
|
||||||
fpsigprocmask(SIG_UNBLOCK,@e,nil);
|
|
||||||
reenable_signal:=geterrno=0;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
// signal handler is arch dependant due to processorexception to language
|
|
||||||
// exception translation
|
|
||||||
|
|
||||||
{$i sighnd.inc}
|
|
||||||
|
|
||||||
var
|
|
||||||
act: SigActionRec;
|
|
||||||
|
|
||||||
Procedure InstallSignals;
|
|
||||||
begin
|
|
||||||
{ Initialize the sigaction structure }
|
|
||||||
{ all flags and information set to zero }
|
|
||||||
FillChar(act, sizeof(SigActionRec),0);
|
|
||||||
{ initialize handler }
|
|
||||||
act.sa_handler := SigActionHandler(@SignalToRunError);
|
|
||||||
act.sa_flags:=SA_SIGINFO;
|
|
||||||
FpSigAction(SIGFPE,@act,nil);
|
|
||||||
FpSigAction(SIGSEGV,@act,nil);
|
|
||||||
FpSigAction(SIGBUS,@act,nil);
|
|
||||||
FpSigAction(SIGILL,@act,nil);
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure SetupCmdLine;
|
procedure SetupCmdLine;
|
||||||
var
|
var
|
||||||
bufsize,
|
bufsize,
|
||||||
@ -151,14 +123,13 @@ var
|
|||||||
|
|
||||||
procedure AddBuf;
|
procedure AddBuf;
|
||||||
begin
|
begin
|
||||||
reallocmem(cmdline,size+bufsize);
|
reallocmem(calculated_cmdline,size+bufsize);
|
||||||
move(buf^,cmdline[size],bufsize);
|
move(buf^,calculated_cmdline[size],bufsize);
|
||||||
inc(size,bufsize);
|
inc(size,bufsize);
|
||||||
bufsize:=0;
|
bufsize:=0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
cmdline:=nil;
|
|
||||||
if i>=argc then
|
if i>=argc then
|
||||||
exit;
|
exit;
|
||||||
GetMem(buf,ARG_MAX);
|
GetMem(buf,ARG_MAX);
|
||||||
@ -202,6 +173,55 @@ begin
|
|||||||
FreeMem(buf,ARG_MAX);
|
FreeMem(buf,ARG_MAX);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function get_cmdline:Pchar;
|
||||||
|
|
||||||
|
begin
|
||||||
|
if calculated_cmdline=nil then
|
||||||
|
setupcmdline;
|
||||||
|
get_cmdline:=calculated_cmdline;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{*****************************************************************************
|
||||||
|
SystemUnit Initialization
|
||||||
|
*****************************************************************************}
|
||||||
|
|
||||||
|
function reenable_signal(sig : longint) : boolean;
|
||||||
|
var
|
||||||
|
e : TSigSet;
|
||||||
|
i,j : byte;
|
||||||
|
begin
|
||||||
|
fillchar(e,sizeof(e),#0);
|
||||||
|
{ set is 1 based PM }
|
||||||
|
dec(sig);
|
||||||
|
i:=sig mod (sizeof(cuLong) * 8);
|
||||||
|
j:=sig div (sizeof(cuLong) * 8);
|
||||||
|
e[j]:=1 shl i;
|
||||||
|
fpsigprocmask(SIG_UNBLOCK,@e,nil);
|
||||||
|
reenable_signal:=geterrno=0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
// signal handler is arch dependant due to processorexception to language
|
||||||
|
// exception translation
|
||||||
|
|
||||||
|
{$i sighnd.inc}
|
||||||
|
|
||||||
|
var
|
||||||
|
act: SigActionRec;
|
||||||
|
|
||||||
|
Procedure InstallSignals;
|
||||||
|
begin
|
||||||
|
{ Initialize the sigaction structure }
|
||||||
|
{ all flags and information set to zero }
|
||||||
|
FillChar(act, sizeof(SigActionRec),0);
|
||||||
|
{ initialize handler }
|
||||||
|
act.sa_handler := SigActionHandler(@SignalToRunError);
|
||||||
|
act.sa_flags:=SA_SIGINFO;
|
||||||
|
FpSigAction(SIGFPE,@act,nil);
|
||||||
|
FpSigAction(SIGSEGV,@act,nil);
|
||||||
|
FpSigAction(SIGBUS,@act,nil);
|
||||||
|
FpSigAction(SIGILL,@act,nil);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure SysInitStdIO;
|
procedure SysInitStdIO;
|
||||||
begin
|
begin
|
||||||
@ -251,7 +271,7 @@ end;
|
|||||||
|
|
||||||
var
|
var
|
||||||
initialstkptr : Pointer;external name '__stkptr';
|
initialstkptr : Pointer;external name '__stkptr';
|
||||||
Begin
|
begin
|
||||||
SysResetFPU;
|
SysResetFPU;
|
||||||
IsConsole := TRUE;
|
IsConsole := TRUE;
|
||||||
StackLength := CheckInitialStkLen(initialStkLen);
|
StackLength := CheckInitialStkLen(initialStkLen);
|
||||||
@ -264,7 +284,6 @@ Begin
|
|||||||
{ Setup stdin, stdout and stderr }
|
{ Setup stdin, stdout and stderr }
|
||||||
SysInitStdIO;
|
SysInitStdIO;
|
||||||
{ Arguments }
|
{ Arguments }
|
||||||
SetupCmdLine;
|
|
||||||
SysInitExecPath;
|
SysInitExecPath;
|
||||||
{ Reset IO Error }
|
{ Reset IO Error }
|
||||||
InOutRes:=0;
|
InOutRes:=0;
|
||||||
@ -272,4 +291,4 @@ Begin
|
|||||||
InitSystemThreads;
|
InitSystemThreads;
|
||||||
initvariantmanager;
|
initvariantmanager;
|
||||||
initwidestringmanager;
|
initwidestringmanager;
|
||||||
End.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user