瀏覽代碼

* new unix rtl, linux part.....

marco 22 年之前
父節點
當前提交
7dd70233f2

+ 451 - 0
rtl/linux/bunxfunc.inc

@@ -0,0 +1,451 @@
+{
+    $Id$
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2002 by Marco van de Voort
+
+    Calls needed for the baseunix unit, but not for system.
+    Some calls that can be used for both Linux and *BSD will be
+    moved to a /unix/ includedfile later.
+
+    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.
+
+ **********************************************************************}
+
+{$i syscallh.inc}	// do_syscall declarations themselves
+{$i sysnr.inc}		// syscall numbers.
+{$i ostypes.inc}
+{$i ossysch.inc}	// external interface to syscalls in system unit.
+{$i bunxmacr.inc}	// macro's.
+
+{$I gensigset.inc}     // general sigset funcs implementation. 
+
+Function fpKill(Pid:pid_t;Sig:cint):cint;
+{
+  Send signal 'sig' to a process, or a group of processes.
+  If Pid >  0 then the signal is sent to pid
+     pid=-1                         to all processes except process 1
+     pid < -1                         to process group -pid
+  Return value is zero, except for case three, where the return value
+  is the number of processes to which the signal was sent.
+}
+
+begin
+ fpkill:=do_syscall(syscall_nr_kill,TSysParam(pid),TSysParam(sig));
+// if kill<0 THEN
+//  Kill:=0;
+end;
+
+function fpSigProcMask(how:cint;nset : pSigSet; oset : pSigSet):cint; [public, alias : 'FPC_SYSC_SIGPROGMASK'];
+{
+  Change the list of currently blocked signals.
+  How determines which signals will be blocked :
+   SigBlock   : Add SSet to the current list of blocked signals
+   SigUnBlock : Remove the signals in SSet from the list of blocked signals.
+   SigSetMask : Set the list of blocked signals to SSet
+  if OldSSet is non-null, the old set will be saved there.
+}
+
+begin
+  fpsigprocmask:=do_syscall(syscall_nr_sigprocmask,longint(how),longint(nset),longint(oset));
+end;
+
+
+Function fpSigPending(var nset: TSigSet):cint;
+{
+  Allows examination of pending signals. The signal mask of pending
+  signals is set in SSet
+}
+begin
+  fpsigpending:=do_syscall(syscall_nr_sigpending,longint(@nset));
+end;
+
+function fpsigsuspend(const sigmask:TSigSet):cint;
+{
+ Set the signal mask with Mask, and suspend the program until a signal
+ is received.
+}
+
+begin
+  fpsigsuspend:= do_syscall(syscall_nr_sigsuspend,longint(@sigmask));
+end;
+
+Type
+  ITimerVal= Record
+              It_Interval,
+              It_Value      : TimeVal;
+             end;
+
+Const   ITimer_Real    =0;
+  	ITimer_Virtual =1;
+  	ITimer_Prof    =2;
+
+Function SetITimer(Which : Longint;Const value : ItimerVal; var VarOValue:ItimerVal):Longint;
+
+Begin
+  SetItimer:=Do_Syscall(syscall_nr_setitimer,Which,Longint(@Value),longint(@varovalue));
+End;
+
+Function GetITimer(Which : Longint;Var value : ItimerVal):Longint;
+
+Begin
+  GetItimer:=Do_Syscall(syscall_nr_getItimer,Which,Longint(@value));
+End;
+
+Function fpalarm(Seconds: cuint):cuint;
+
+Var it,oitv : Itimerval;
+    retval  : cuint;
+	
+Begin
+//      register struct itimerval *itp = &it;
+
+ it.it_interval.tv_sec:=0;
+ it.it_interval.tv_usec:=0;
+ it.it_value.tv_usec:=0;
+ it.it_value.tv_sec:=seconds;
+ If SetITimer(ITIMER_REAL,it,oitv)<0 Then
+   Exit(0);			// different from *BSD!
+
+ retval:= oitv.it_value.tv_usec;
+ if retval<>0 Then
+   inc(retval);
+ fpAlarm:=retval;
+End;
+
+// The following versions are for internal use _ONLY_
+// This because it works for the first 32 signals _ONLY_, but that 
+// is enough since they are depreciated, and for legacy applications
+// anyway.
+
+function sigblock(mask:cuint):cint;
+
+var nset,oset: TSigSet;
+
+begin
+ fpsigemptyset(nset); 
+ // fpsigaddset(nset,mask);   needs _mask_
+ nset[0]:=mask;
+ sigblock:= fpsigprocmask(SIG_BLOCK,@nset,@oset);   // SIG_BLOCK=1
+ if sigblock=0 Then
+  sigblock:=oset[0];
+end;
+
+function sigpause(sigmask:cint):cint;
+
+var nset: TSigSet;
+
+begin
+ fpsigemptyset(nset); 
+ nset[0]:=sigmask;
+ sigpause:= fpsigsuspend(nset);
+end;
+
+function fppause:cint;
+
+begin
+  fppause:=sigpause(sigblock(cuint(0)));
+end;
+
+function fpsleep(seconds:cuint):cuint;
+{see comments in libc}
+
+var time_to_sleep,time_remaining : timespec;
+    nset,oset  : TSigSet;
+    oerrno     : cint;
+    oact       : sigactionrec;
+
+begin
+	time_to_sleep.tv_sec := seconds;
+	time_to_sleep.tv_nsec := 0;
+	 fpsigemptyset(nset);
+         fpsigaddset  (nset,SIGCHLD);
+     	 if fpsigprocmask(SIG_BLOCK,@nset,@oset)=0 Then
+          exit(cuint(-1));
+	if fpsigismember(oset,SIGCHLD)<>0 Then
+          Begin
+	    fpsigemptyset(nset);
+            fpsigaddset  (nset,SIGCHLD);
+    	    if fpsigaction(SIGCHLD,NIL,@oact)<0 Then
+	      begin
+ 	        oerrno:=geterrno;	
+		fpsigprocmask(SIG_SETMASK,@oset,NIL);
+		seterrno(oerrno);
+		exit(cuint(-1));
+	      End;
+	    if oact.sa_handler=signalhandler(SIG_IGN) Then
+	     Begin
+	       fpsleep:=fpnanosleep(time_to_sleep, @time_remaining);
+	       oerrno:=geterrno;
+	       fpsigprocmask(SIG_SETMASK,@oset,NIL);
+	       seterrno(oerrno);
+	     End
+	    Else
+	     Begin
+	       fpsigprocmask(SIG_SETMASK,@oset,NIL);
+	       fpsleep:=fpnanosleep(time_to_sleep, @time_remaining)	       
+	     End;
+	  end
+	else
+            fpsleep:=fpnanosleep(time_to_sleep, @time_remaining);	       
+	if fpsleep<>0 Then
+	 if time_remaining.tv_nsec>=500000000 Then
+	  inc(fpsleep);
+End;
+
+function fpuname(var name:utsname):cint; [public,alias:'FPC_SYSC_UNAME'];
+
+begin
+  fpuname:=Do_Syscall(syscall_nr_uname,TSysParam(@name));
+end;
+
+Function fpGetDomainName(Name:PChar; NameLen:size_t):cint; 
+
+Var
+	srec  : utsname;
+	tsize : size_t;
+Begin
+        if fpuname(srec)<0 Then
+          exit(-1);
+        tsize:=strlen(@srec.domain[0]);
+        if tsize>(namelen-1) Then
+  	 tsize:=namelen-1;
+        move(srec.domain[0],name[0],tsize);
+        name[namelen-1]:=#0;
+        fpgetDomainName:=0;
+End;          
+
+function fpGetHostName(Name:PChar; NameLen:size_t):cint;
+
+Var
+ 	srec  : utsname;
+	tsize : size_t;
+begin
+        if fpuname(srec)<0 Then
+          exit(-1);
+        tsize:=strlen(@srec.nodename[0]);
+        if tsize>(namelen-1) Then
+  	 tsize:=namelen-1;
+        move(srec.nodename[0],name[0],tsize);
+        name[namelen-1]:=#0;
+        fpgethostName:=0;
+End;
+
+const WAIT_ANY = -1;
+
+function fpwait(var stat_loc:cint): pid_t;
+{
+  Waits until a child with PID Pid exits, or returns if it is exited already.
+  Any resources used by the child are freed.
+  The exit status is reported in the adress referred to by Status. It should
+  be a longint.
+}
+
+begin // actually a wait4() call with 4th arg 0.
+ fpWait:=do_syscall(syscall_nr_Wait4,WAIT_ANY,longint(@Stat_loc),0,0);
+end;
+
+//function fpgetpid : pid_t;
+
+// begin
+//  fpgetpid:=do_syscall(syscall_nr_getpid);
+// end;
+
+function fpgetppid : pid_t;
+
+begin
+ fpgetppid:=do_syscall(syscall_nr_getppid);
+end;
+
+function fpgetuid : uid_t;
+
+begin
+ fpgetuid:=do_syscall(syscall_nr_getuid);
+end;
+
+function fpgeteuid : uid_t;
+
+begin
+ fpgeteuid:=do_syscall(syscall_nr_geteuid);
+end;
+
+function fpgetgid : gid_t;
+
+begin
+ fpgetgid:=do_syscall(syscall_nr_getgid);
+end;
+
+function fpgetegid : gid_t;
+
+begin
+ fpgetegid:=do_syscall(syscall_nr_getegid);
+end;
+
+function fpsetuid(uid : uid_t): cint;
+
+begin
+ fpsetuid:=do_syscall(syscall_nr_setuid,uid);
+end;
+
+function fpsetgid(gid : gid_t): cint;
+
+begin
+ fpsetgid:=do_syscall(syscall_nr_setgid,gid);
+end;
+
+// type tgrparr=array[0..0] of gid_t;
+
+function fpgetgroups(gidsetsize : cint; var grouplist:tgrparr): cint;
+
+begin
+ fpgetgroups:=do_syscall(syscall_nr_getgroups,gidsetsize,longint(@grouplist));
+end;
+
+function fpgetpgrp : pid_t;
+
+begin
+ fpgetpgrp:=do_syscall(syscall_nr_getpgrp);
+end;
+
+function fpsetsid : pid_t;
+
+begin
+ fpsetsid:=do_syscall(syscall_nr_setsid);
+end;
+
+Function fpumask(cmask:mode_t):mode_t;
+{
+  Sets file creation mask to (Mask and 0777 (octal) ), and returns the
+  previous value.
+}
+begin
+ fpumask:=Do_syscall(syscall_nr_umask,cmask);
+end;
+
+Function fplink(existing:pchar;newone:pchar):cint;
+{
+  Proceduces a hard link from new to old.
+  In effect, new will be the same file as old.
+}
+begin
+  fpLink:=Do_Syscall(syscall_nr_link,longint(existing),longint(newone));
+end;
+
+Function fpmkfifo(path:pchar;mode:mode_t):cint;
+
+begin
+
+fpmkfifo:=do_syscall(syscall_nr_mknod,TSysParam(path),TSysParam(mode or _S_IFIFO),TSysParam(0));
+end;
+
+Function fpchmod(path:pchar;mode:mode_t):cint;
+
+begin
+  fpchmod:=do_syscall(syscall_nr_chmod,longint(path),longint(mode));
+end;
+
+Function fpchown(path:pchar;owner:uid_t;group:gid_t):cint;
+
+begin
+  fpChOwn:=do_syscall(syscall_nr_chown,longint(path),longint(owner),longint(group));
+end;
+
+Function fpUtime(path:pchar;times:putimbuf):cint;
+
+begin
+ fputime:=do_syscall(syscall_nr_utime,TSysParam(path),TSysParam(times));
+end;
+
+Function fppipe(var fildes : tfildes):cint;
+
+begin
+ fppipe:=do_syscall(syscall_nr_pipe,longint(@fildes));
+end;
+
+function fpfcntl(fildes:cint;Cmd:cint;Arg:cint):cint;
+
+begin
+ fpfcntl:=do_syscall(syscall_nr_fcntl,fildes,cmd,arg);
+end;
+
+function fpfcntl(fildes:cint;Cmd:cint;var Arg:flock):cint;
+
+begin
+ fpfcntl:=do_syscall(syscall_nr_fcntl,fildes,cmd,longint(@arg));
+end;
+
+function fpfcntl(fildes:cint;Cmd:cint):cint;
+
+begin
+ fpfcntl:=do_syscall(syscall_nr_fcntl,fildes,cmd);
+end;
+
+function fpexecve(path:pchar;argv:ppchar;envp:ppchar):cint;
+
+Begin
+  fpexecve:=do_syscall(syscall_nr_Execve,longint(path),longint(argv),longint(envp));
+End;
+
+function fpexecv(path:pchar;argv:ppchar):cint;
+
+Begin
+  fpexecv:=do_syscall(syscall_nr_Execve,longint(path),longint(argv),longint(envp));
+End;
+
+function fptimes(var buffer : tms):clock_t;
+begin
+  fptimes:=Do_syscall(syscall_nr_times,TSysParam(@buffer));
+end;
+
+function fpgetcwd(path : pchar; siz:size_t):pchar;
+
+begin
+
+fpgetcwd:=pchar(Do_Syscall(Syscall_nr_getcwd,TSysParam(Path),TSysParam(siz)));
+end;
+
+{
+ $Log$
+ Revision 1.1  2002-12-18 16:43:26  marco
+  * new unix rtl, linux part.....
+
+ Revision 1.1  2002/11/14 16:48:39  marco
+  * Initial version
+
+ Revision 1.10  2002/11/14 12:34:20  marco
+  * took out the generic sethandling.
+
+ Revision 1.9  2002/11/13 18:15:08  marco
+  * sigset functions more flexible, small changes to sys_time
+
+ Revision 1.8  2002/10/27 17:21:29  marco
+  * Only "difficult" functions + execvp + termios + rewinddir left to do
+
+ Revision 1.7  2002/10/27 11:58:29  marco
+  * Modifications from Saturday.
+
+ Revision 1.6  2002/10/26 18:27:51  marco
+  * First series POSIX calls commits. Including getcwd.
+
+ Revision 1.5  2002/10/25 15:46:48  marco
+  * Should be alias.
+
+ Revision 1.4  2002/09/08 16:20:27  marco
+  * Forgot external name's
+
+ Revision 1.3  2002/09/08 16:11:59  marco
+  * Added GetDomainName and that other one ..
+
+ Revision 1.2  2002/09/07 16:01:17  peter
+   * old logs removed and tabs fixed
+
+ Revision 1.1  2002/08/21 07:03:16  marco
+  * Fixes from Tuesday.
+
+ Revision 1.1  2002/08/08 11:39:30  marco
+  * Initial versions, to allow support for uname in posix.pp
+}

+ 91 - 0
rtl/linux/bunxmacr.inc

@@ -0,0 +1,91 @@
+{ 
+   $Id$ 
+    Copyright (c) 2000-2002 by Marco van de Voort
+
+    The "linux" posixy macro's that are used both in the Baseunx unit as the
+    system unit. Not aliased via public names because I want these to be
+    inlined as much as possible in the future.
+
+    This program is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.
+
+    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.  See the GNU
+    General Public License for more details.
+
+    You should have received a copy of the GNU General Public License along
+    with this program; if not, write to the Free Software Foundation, Inc.,
+    675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+
+function FpISDIR(m : TMode): boolean;
+
+begin
+  FpISDIR:=((m and _S_IFMT) = _S_IFDIR);
+end;
+
+function FpISCHR(m : TMode): boolean;
+begin
+  FpISCHR:=((m and _S_IFMT) = _S_IFCHR);
+end;
+
+function FpISBLK(m : TMode): boolean;
+begin
+ FpISBLK:=((m and _S_IFMT) = _S_IFBLK);
+end;
+
+function FpISREG(m : TMode): boolean;
+begin
+ FpISREG:=((m and _S_IFMT) = _S_IFREG);
+end;
+
+function FpISFIFO(m : TMode): boolean;
+begin
+ FpISFIFO:=((m and _S_IFMT) = _S_IFIFO);
+end;
+
+function wifexited(status : cint): cint;
+begin
+ wifexited:=cint((status AND $7f) =0);
+end;
+
+function wexitstatus(status : cint): cint;
+begin
+ wexitstatus:=(status and $FF00) shr 8;
+end;
+
+function wstopsig(status : cint): cint;
+begin
+ wstopsig:=(status and $FF00) shr 8;
+end;
+
+const wstopped=127;
+
+function wifsignaled(status : cint): cint;
+begin
+ wifsignaled:=cint(((status and $FF)<>wstopped) and ((status and 127)<>0));
+end;
+
+function wtermsig(status : cint):cint;
+
+begin
+ wtermsig:=cint(status and 127);
+end;
+
+{
+  $Log$
+  Revision 1.1  2002-12-18 16:43:26  marco
+   * new unix rtl, linux part.....
+
+  Revision 1.2  2002/11/12 15:31:33  marco
+   * Killed octal codes for 1.0.x compilability.
+
+  Revision 1.1  2002/11/12 14:37:59  marco
+   * Parts of new unix rtl
+
+}

+ 70 - 0
rtl/linux/bunxmain.inc

@@ -0,0 +1,70 @@
+{
+    $Id$
+    Copyright (c) 2002 by Marco van de Voort.
+
+    Implementation of the baseunix unit for *BSD^H^H^Hlinux. In practice only
+    includes other files, or specifies libc bindings.
+
+    The conditional uselibc can be used to switch from libc to syscall
+    usage for basic primitives, but it is best to use unit POSIX if
+    possible. Note that the system unit must also be compiled using uselibc.
+
+    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.
+
+ ****************************************************************************
+}
+
+{ $I ostypes.inc}
+{ $I posmacro.inc}
+
+{$ifdef uselibc}
+ {$I oscdecl.inc}
+{$else}
+
+function fptime		(var tloc:time_t): time_t; external name 'FPC_SYSC_TIME';
+function fpopen		(path: pchar; flags : cint; mode: TMode):cint;  external name 'FPC_SYSC_OPEN';
+function fpclose	(fd : cint): cint;  external name 'FPC_SYSC_CLOSE';
+function fplseek	(fd : cint; offset : TOff; whence : cint): TOff; external name 'FPC_SYSC_LSEEK';
+function fpread		(fd: cint; buf: pchar; nbytes : TSize): TSSize; external name 'FPC_SYSC_READ';
+function fpwrite	(fd: cint; buf:pchar; nbytes : TSize): TSSize;  external name 'FPC_SYSC_WRITE';
+function fpunlink	(path: pchar): cint;  external name 'FPC_SYSC_UNLINK';
+function fprename	(old : pchar; newpath: pchar): cint;  external name 'FPC_SYSC_RENAME';
+function fpstat		(path: pchar; var buf : stat):cint;  external name 'FPC_SYSC_STAT';
+function fpchdir	(path : pchar): cint; external name 'FPC_SYSC_CHDIR';
+function fpmkdir	(path : pchar; mode: TMode):cint; external name 'FPC_SYSC_MKDIR';
+function fprmdir	(path : pchar): cint; external name 'FPC_SYSC_RMDIR';
+function fpopendir	(dirname : pchar): pdir; external name 'FPC_SYSC_OPENDIR';
+function fpclosedir	(var dirp : dir): cint; external name 'FPC_SYSC_CLOSEDIR';
+function fpreaddir	(var dirp : dir) : pdirent; external name 'FPC_SYSC_READDIR';
+procedure fpexit	(status : cint); external name 'FPC_SYSC_EXIT';
+function fpsigaction	(sig: cint; act : psigactionrec; oact : psigactionrec): cint;  external name 'FPC_SYSC_SIGACTION';
+function fpftruncate	(fd : cint; flength : TOff): cint; external name 'FPC_SYSC_FTRUNCATE';
+function fpfstat	(fd : cint; var sb : stat): cint; external name 'FPC_SYSC_FSTAT';
+function fpfork       : pid_t; external name 'FPC_SYSC_FORK';
+// function fpexecve	(path : pchar; argv : ppchar;envp: ppchar): cint; external name 'FPC_SYSC_EXECVE';
+function fpwaitpid	(pid : pid_t; var stat_loc : cint; options: cint): pid_t; external name 'FPC_SYSC_WAITPID';
+function fpaccess	(pathname : pchar; amode : cint): cint;external name 'FPC_SYSC_ACCESS';
+function fpDup		(fildes:cint):cint;  external name 'FPC_SYSC_DUP';
+function fpDup2		(fildes:cint;fildes2:cint):cint; external name 'FPC_SYSC_DUP2';
+function geterrno     : cint; external name  'FPC_SYS_GETERRNO';
+procedure seterrno 	(i:cint); external name  'FPC_SYS_SETERRNO';
+
+{$endif}
+
+{$I bunxfunc.inc}
+{$I genfuncs.inc}
+
+{
+ $Log$
+ Revision 1.1  2002-12-18 16:43:26  marco
+  * new unix rtl, linux part.....
+
+ Revision 1.1  2002/11/12 14:37:59  marco
+  * Parts of new unix rtl
+
+}

+ 271 - 0
rtl/linux/bunxtype.inc

@@ -0,0 +1,271 @@
+{
+    $Id$
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2001 by Free Pascal development team
+
+    Types and structures for the BaseUnix 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.
+
+ ***********************************************************************}
+
+{***********************************************************************}
+{                         Base Unix Structures				}
+{***********************************************************************}
+
+{$i ptypes.inc}
+
+CONST
+    SYS_NMLM 		     = 65;
+    UTSNAME_LENGTH 	     = SYS_NMLM;
+    UTSNAME_NODENAME_LENGTH  = UTSNAME_LENGTH;
+    {$ifdef usedomain}
+    UTSNAME_DOMAIN_LENGTH    = UTSNAME_LENGTH;
+    {$endif}
+
+TYPE
+   Blksize_t  = cuint;
+   Blkcnt_t   = cuint;
+   Ino64_t    = cint64;
+   Off64_t    = cint64;
+
+   TBlkSize   = BlkSize_t;
+   PBlkSize   = ^BlkSize_t;
+   TBlkCnt    = Blkcnt_t;
+   PBlkCnt    = ^Blkcnt_t;
+   TIno64     = Ino64_t;
+   PIno64     = ^Ino64_t;
+   TOff64     = Off64_t;
+   POff64     = ^Off64_t;
+
+   { system information services }
+   UtsName   = Record
+                Sysname : Array[0..UTSNAME_LENGTH -1] OF Char;   // Name of this OS
+                Nodename: Array[0..UTSNAME_NODENAME_LENGTH-1] OF Char;   // Name of this network node.
+                Release : Array[0..UTSNAME_LENGTH -1] OF Char;   // Release level.
+                Version : Array[0..UTSNAME_LENGTH -1] OF Char;   // Version level.
+                Machine : Array[0..UTSNAME_LENGTH -1] OF Char;   // Hardware type.
+	       {$ifdef usedomain}
+	        Domain  : array[0..UTSNAME_DOMAIN_LENGTH-1] of char;  // Linux addition "Domain"           
+	       {$endif}
+	       end;
+  TUtsName   = UtsName;
+  PUtsName   = TUtsName;
+
+  Stat 	     = Packed Record  // No unix typing because of differences
+			      // kernel <->libc
+                st_dev     : word;
+                pad1       : word;
+                st_ino     : longint;
+                st_mode,
+                nlink,
+                uid,
+                gid        : word;
+                rdev       : word;
+                pad2       : word;
+                st_size,
+                blksze,
+                blocks,
+                atime,
+                unused1,
+                mtime,
+                unused2,
+                ctime,
+                unused3,
+                unused4,
+                unused5   : longint;
+  	       end;
+  TStat	     = Stat;
+  PStat	     = ^Stat;
+
+
+{$ifdef notused} // 64-bit support needs some work still :-)
+  { file characteristics services }
+   stat64    = record 
+        st_dev        : dev_t;             // inode's device
+	pad1	      : cushort;
+	{$ifdef 64bitfs}		   // ??
+	__st_ino      : ino_t;
+	{$else}
+        st_ino        : ino_t;             // inode's number
+	{$endif}
+        st_mode       : mode_t;            // inode protection mode
+        st_nlink      : nlink_t;           // number of hard links
+        st_uid        : uid_t;             // user ID of the file's owner
+        st_gid        : gid_t;             // group ID of the file's group
+        st_rdev       : dev_t;             // device type
+	pad2	      : cushort;
+	{$ifdef 64bitfs}
+        st_size       : off64_t;            // file size, in bytes
+	{$else}
+        st_size       : off_t;             // file size, in bytes
+ 	{$endif}
+        st_blksize    : blksize_t;           // optimal blocksize for I/O
+	{$ifdef 64bitfs}
+        st_blocks     : blkcnt64_t;            // blocks allocated for file
+	{$else}
+ 	st_blocks     : blkcnt_t;            // blocks allocated for file
+	{$endif}
+        st_atime      : time_t;            // time of last access
+	unused1	      : culong;
+        st_mtime      : time_t;            // time of last data modification
+	unused2	      : culong;
+        st_ctime      : time_t;            // time of last file status change
+	unused3	      : culong;
+	{$ifdef 64bitfs}
+	st_ino	      : ino64_t
+	{$else}
+	unused4	      : culong;	
+        unused5	      : culong;
+	{$endif}
+   end;
+{$endif}
+
+  { directory services }
+  
+  Dirent     = packed record
+	       {$ifndef 64bitfs}
+        	d_fileno      : ino_t;                          // file number of entry
+        	d_off         : off_t;     
+		{$else}
+        	d_fileno      : ino64_t;                        // file number of entry
+        	d_off         : off64_t;            
+	       {$endif}
+		d_reclen      : cushort;                        // length of string in d_name
+	       {$ifdef Uselibc}	// Libc different from kernel record!
+        	d_type        : cuchar;                         // file type, see below
+	       {$endif}
+        	d_name        : array[0..(255 + 1)-1] of char;  // name must be no longer than this
+   	       end;
+  TDirent    = Dirent;
+  pDirent    = ^Dirent;
+
+
+
+
+{$ifdef oldreaddir}
+	   { Still old one. This is a userland struct}
+
+   Dir       = packed record
+                fd     : integer;
+                loc    : longint;
+                size   : integer;
+                buf    : pdirent;
+                {The following are used in libc, but NOT in the linux kernel sources ??}
+                nextoff: longint;
+                dd_max : integer; {size of buf. Irrelevant, as buf is of type dirent}
+                lock   : pointer;
+               end;
+{$else}
+	// new libc one. NOTE that off_t must be real, so 64-bit ifdef
+	// 64bitsfs
+   Dir       = Record	// packing doesn't matter. This is a userland struct.
+	        fd  	: cint;
+	        data	: pchar;
+	        allocation: size_t;
+	        _size     : size_t;
+	        offset    : size_t;
+	        filepos   : off_t;
+	        end;
+{$endif}   
+
+   TDir	     = Dir;
+   pDir      = ^Dir;
+
+
+   UTimBuf   = Record
+	         actime  : time_t;
+	         modtime : time_t;
+	        end;
+
+   TUtimBuf  = UtimBuf;   
+   pUtimBuf  = ^UtimBuf;
+
+   FLock     = Record
+		l_type	: cshort;	{ lock type: read/write, etc. }
+		l_whence: cshort;	{ type of l_start }
+		{$ifdef 64bitfs}
+		l_start : off64_t;	{ starting offset }
+		l_len	: off64_t;	{ len = 0 means until end of file }
+		{$else}
+		l_start : off_t;	{ starting offset }
+		l_len	: off_t;	{ len = 0 means until end of file }
+		{$endif}
+		l_pid 	: pid_t;	{ lock owner }
+	       End;
+
+   tms       = packed Record
+	 	tms_utime  : clock_t;	{ User CPU time }
+	 	tms_stime  : clock_t;	{ System CPU time }
+	 	tms_cutime : clock_t;	{ User CPU time of terminated child procs }
+	 	tms_cstime : clock_t;	{ System CPU time of terminated child procs }
+	       end;
+   TTms      = tms;
+   PTms	     = ^tms;
+
+{***********************************************************************}
+{                  POSIX CONSTANT ROUTINE DEFINITIONS                   }
+{***********************************************************************}
+CONST
+    { access routine - these maybe OR'ed together }
+    F_OK      =          0;        { test for existence of file }
+    R_OK      =          4;        { test for read permission on file }
+    W_OK      =          2;        { test for write permission on file }
+    X_OK      =          1;        { test for execute or search permission }
+    { seek routine }
+    SEEK_SET  =          0;        { seek from beginning of file }
+    SEEK_CUR  =          1;        { seek from current position  }
+    SEEK_END  =          2;        { seek from end of file       }
+    { open routine                                 }
+    { File access modes for `open' and `fcntl'.    }
+    O_RDONLY  =          0;        { Open read-only.  }
+    O_WRONLY  =          1;        { Open write-only. }
+    O_RDWR    =          2;        { Open read/write. }
+    { Bits OR'd into the second argument to open.  }
+    O_CREAT   =        $40;        { Create file if it doesn't exist.  }
+    O_EXCL    =        $80;        { Fail if file already exists.      }
+    O_TRUNC   =       $200;        { Truncate file to zero length.     }
+    O_NOCTTY  =       $100;        { Don't assign a controlling terminal. }
+    { File status flags for `open' and `fcntl'.  }
+    O_APPEND  =       $400;        { Writes append to the file.        }
+    O_NONBLOCK=       $800;        { Non-blocking I/O.                 }
+
+    { mode_t possible values                                 }
+    S_IRUSR =  %0100000000;     { Read permission for owner   }
+    S_IWUSR =  %0010000000;     { Write permission for owner  }
+    S_IXUSR =  %0001000000;     { Exec  permission for owner  }
+    S_IRGRP =  %0000100000;     { Read permission for group   }
+    S_IWGRP =  %0000010000;     { Write permission for group  }
+    S_IXGRP =  %0000001000;     { Exec permission for group   }
+    S_IROTH =  %0000000100;     { Read permission for world   }
+    S_IWOTH =  %0000000010;     { Write permission for world  }
+    S_IXOTH =  %0000000001;     { Exec permission for world   }
+
+    { Used for waitpid }
+    WNOHANG   =          1;     { don't block waiting               }
+    WUNTRACED =          2;     { report status of stopped children }
+
+
+    {*************************************************************************}
+    {                               SIGNALS                                   }
+    {*************************************************************************}
+
+{$i signal.inc}
+
+// function geterrno:longint;
+// procedure seterrno(i:longint);
+
+{
+  $Log$
+  Revision 1.1  2002-12-18 16:43:26  marco
+   * new unix rtl, linux part.....
+
+  Revision 1.1  2002/11/12 14:37:59  marco
+   * Parts of new unix rtl
+
+}

+ 21 - 18
rtl/linux/ctypes.inc

@@ -26,41 +26,44 @@ Type
     { the following type definitions are compiler dependant }
     { and system dependant                                  }
 
-    cint8  = shortint;
-    cuint8 = byte;
-    cuint16= word;
-    cint16 = smallint;
-    cint32 = longint;
-    cuint32= cardinal;
-    cint64 = int64;
+    cInt8  = shortint;
+    cUInt8 = byte;
+    cUInt16= word;
+    cInt16 = smallint;
+    cInt32 = longint;
+    cUInt32= cardinal;
+    cInt64 = int64;
 {$ifndef VER_1_0}
-    cuint64= qword;
+    cUInt64= qword;
 {$else}
-    cuint64= int64;
+    cUInt64= int64;
 {$endif}
 
     cuchar = byte;
-    cint   = longint;           { minimum range is : 32-bit    }
-    cuint  = Cardinal;          { minimum range is : 32-bit    }
+    cInt   = longint;           { minimum range is : 32-bit    }
+    cUInt  = Cardinal;          { minimum range is : 32-bit    }
   {$ifdef 64bitarch}
-    clong  = int64;
+    cLong  = int64;
   {$ifdef VER_1_0}
-    culong = int64;
+    cuLong = int64;
   {$else}
-    culong = qword;
+    cuLong = qword;
    {$endif}
   {$else}
-    clong  = longint;
-    culong = Cardinal;
+    cLong  = longint;
+    cuLong = Cardinal;
   {$endif}
     cshort = integer;
     cushort= word;
 
-    pcint  = ^cint;
+    pcInt  = ^cInt;
 
 { 
    $Log$
-   Revision 1.1  2002-11-09 22:39:28  marco
+   Revision 1.2  2002-12-18 16:43:26  marco
+    * new unix rtl, linux part.....
+
+   Revision 1.1  2002/11/09 22:39:28  marco
     * first version
 
 

+ 56 - 0
rtl/linux/oscdeclh.inc

@@ -0,0 +1,56 @@
+{
+    $Id$
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2001 by Free Pascal development team
+
+    This file should become an alternative to the syscalls in due time,
+    to import the base calls from libc.
+    Be very careful though. Kernel types and libc types are often not the
+    same on Linux.
+
+    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.
+
+ ***********************************************************************}
+
+{   var
+     Errno : cint; external name 'errno';}
+
+    function  FpAccess  (pathname : pchar; amode : cint): cint; cdecl; external name 'access';
+    function  FpChdir	(path : pchar): cint; cdecl; external name 'chdir';
+    function  FpClose	(fd : cint): cint; cdecl; external name 'close';
+    function  FpClosedir(var dirp : dir): cint; cdecl; external name 'closedir';
+    function  FpDup	(oldd:cint):cint; cdecl; external name 'dup';
+    function  FpDup2	(oldd:cint;newd:cint):cint; cdecl; external name 'dup2';
+    function  FpExecve	(path : pchar; argv : ppchar; envp: ppchar): cint; cdecl; external name 'execve';
+    function  FpFork  : TPid; cdecl; external name 'fork';
+    function  FpFstat	(fd : cint; var sb : stat): cint; cdecl; external name 'fstat';
+    function  FpFtruncate(fd : cint; flength : TOff): cint; cdecl; external name 'ftruncate';
+    function  FpLseek	(fd : cint; offset : TOff; whence : cint): TOff; cdecl; external name 'lseek';
+    function  FpMkdir	(path : pchar; mode: TMode):cint; cdecl; external name 'mkdir';
+    function  FpOpen	(path: pchar; flags : cint; mode: TMode):cint; cdecl; external name 'open';
+    function  FpOpendir	(dirname : pchar): pdir; cdecl; external name 'opendir';
+    function  FpRead	(fd: cint; buf: pchar; nbytes : TSize): TSSize; cdecl; external name 'read';
+    function  FpReaddir	(var dirp : dir) : pdirent;cdecl; external name 'readdir';
+    function  FpRename	(old : pchar; newpath: pchar): cint; cdecl;external name 'rename';
+    function  FpRmdir	(path : pchar): cint; cdecl; external name 'rmdir';
+    function  FpSigaction(sig: cint; act : psigactionrec; oact : psigactionrec): cint; cdecl; external name 'sigaction';
+    function  FpStat	(path: pchar; var buf : stat): cint; cdecl; external name 'stat';
+    function  FpTime	(tloc:ptime_t): time_t; cdecl; external name 'time';
+    function  FpUname	(var name: utsname): cint; cdecl; external name 'uname';
+    function  FpUnlink	(path: pchar): cint; cdecl; external name 'unlink';
+    function  FpWaitpid	(pid : TPid; stat_loc : pcint; options: cint): TPid; cdecl; external name 'waitpid';
+    function  FpWrite	(fd: cint;buf:pchar; nbytes : TSize): TSSize; cdecl; external name 'write';
+    procedure FpExit	(status : cint); cdecl; external name '_exit';
+
+{
+   $Log$
+   Revision 1.1  2002-12-18 16:43:26  marco
+    * new unix rtl, linux part.....
+
+
+}

+ 688 - 0
rtl/linux/osmain.inc

@@ -0,0 +1,688 @@
+{
+    $Id$
+    This file is part of the Free Pascal run time library.
+
+    POSIX Interface to the system unit
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This is the core of the system unit *nix systems (now FreeBSD
+     and Unix).
+
+    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.
+
+ **********************************************************************}
+
+const
+     { Default creation mode for directories and files }
+
+     { read/write permission for everyone }
+     MODE_OPEN = S_IWUSR OR S_IRUSR OR
+                 S_IWGRP OR S_IRGRP OR
+                 S_IWOTH OR S_IROTH;
+     { read/write search permission for everyone }
+     MODE_MKDIR = MODE_OPEN OR
+                 S_IXUSR OR S_IXGRP OR S_IXOTH;
+
+
+{*****************************************************************************
+                         Stack check code
+*****************************************************************************}
+
+{
+{$IFOPT S+}
+{$DEFINE STACKCHECK}
+{$ENDIF}
+{$S-}
+procedure int_stackcheck(stack_size:longint);[public,alias:'FPC_STACKCHECK'];
+var
+ c: cardinal;
+begin
+ c := cardinal(Sptr) - cardinal(stack_size) - STACK_MARGIN;
+ if (c <= cardinal(StackBottom)) then
+     HandleError(202);
+end;
+{$IFDEF STACKCHECK}
+{$S+}
+{$ENDIF}
+{$UNDEF STACKCHECK}
+}
+
+{*****************************************************************************
+                       Misc. System Dependent Functions
+*****************************************************************************}
+
+procedure System_exit;
+begin
+   Fpexit(cint(ExitCode));
+End;
+
+
+Function ParamCount: Longint;
+Begin
+  Paramcount:=argc-1
+End;
+
+
+function BackPos(c:char; const s: shortstring): integer;
+var
+ i: integer;
+Begin
+  for i:=length(s) downto 0 do
+    if s[i] = c then break;
+  if i=0 then
+    BackPos := 0
+  else
+    BackPos := i;
+end;
+
+
+ { variable where full path and filename and executable is stored }
+ { is setup by the startup of the system unit.                    }
+var
+ execpathstr : shortstring;
+
+function paramstr(l: longint) : string;
+ var
+  s: string;
+  s1: string;
+ begin
+   { stricly conforming POSIX applications  }
+   { have the executing filename as argv[0] }
+   if l=0 then
+     begin
+       paramstr := execpathstr;
+     end
+   else
+     paramstr:=strpas(argv[l]);
+ end;
+
+Procedure Randomize;
+Begin
+  randseed:=longint(Fptime(nil));
+End;
+
+
+{*****************************************************************************
+                              Heap Management
+*****************************************************************************}
+
+var
+  _HEAP : longint;external name 'HEAP';
+  _HEAPSIZE : longint;external name 'HEAPSIZE';
+
+{$ifndef SYSTEM_HAS_GETHEAPSTART}
+function getheapstart:pointer;
+begin
+  getheapstart := @_HEAP;
+end;
+{$endif}
+
+
+{$ifndef SYSTEM_HAS_GETHEAPSIZE}
+function getheapsize:longint;
+begin
+  getheapsize := _HEAPSIZE;
+end;
+{$endif}
+
+
+{*****************************************************************************
+                          Low Level File Routines
+*****************************************************************************}
+
+{
+  The lowlevel file functions should take care of setting the InOutRes to the
+  correct value if an error has occured, else leave it untouched
+}
+
+Function PosixToRunError  (PosixErrno : longint) : longint;
+{
+  Convert ErrNo error to the correct Inoutres value
+}
+
+begin
+  if PosixErrNo=0 then { Else it will go through all the cases }
+   exit;
+  case PosixErrNo of
+   ESysENFILE,
+   ESysEMFILE : Inoutres:=4;
+   ESysENOENT : Inoutres:=2;
+    ESysEBADF : Inoutres:=6;
+   ESysENOMEM,
+   ESysEFAULT : Inoutres:=217;
+   ESysEINVAL : Inoutres:=218;
+    ESysEPIPE,
+    ESysEINTR,
+      ESysEIO,
+   ESysEAGAIN,
+   ESysENOSPC : Inoutres:=101;
+ ESysENAMETOOLONG : Inoutres := 3;
+    ESysEROFS,
+   ESysEEXIST,
+   ESysENOTEMPTY,
+   ESysEACCES : Inoutres:=5;
+   ESysEISDIR : InOutRes:=5;
+  else
+    begin
+       InOutRes := Integer(PosixErrno);
+    end;
+  end;
+ PosixToRunError:=InOutRes;
+end;
+
+Function Errno2InoutRes : longint;
+
+begin
+  Errno2InoutRes:=PosixToRunError(Errno);
+  InoutRes:=Errno2InoutRes;
+end;
+
+Procedure Do_Close(Handle:Longint);
+Begin
+  Fpclose(cint(Handle));
+End;
+
+Procedure Do_Erase(p:pchar);
+var
+ fileinfo : stat;
+Begin
+  { verify if the filename is actually a directory }
+  { if so return error and do nothing, as defined  }
+  { by POSIX                                       }
+  if Fpstat(p,fileinfo)<0 then
+   begin
+     Errno2Inoutres;
+     exit;
+   end;
+  if FpISDIR(fileinfo.st_mode) then
+   begin
+     InOutRes := 2;
+     exit;
+   end;
+  Fpunlink(p);
+  Errno2Inoutres;
+End;
+
+{ truncate at a given position }
+procedure do_truncate (handle,fpos:longint);
+begin
+  { should be simulated in cases where it is not }
+  { available.                                   }
+  If Fpftruncate(handle,fpos)<0 Then
+   Errno2Inoutres
+  Else
+   InOutRes:=0;
+end;
+
+
+
+Procedure Do_Rename(p1,p2:pchar);
+Begin
+  If Fprename(p1,p2)<0 Then
+   Errno2Inoutres
+  Else
+   InOutRes:=0;
+End;
+
+
+Function Do_Write(Handle,Addr,Len:Longint):longint;
+Begin
+  repeat
+    Do_Write:=Fpwrite(Handle,pchar(addr),len);
+  until ErrNo<>ESysEINTR;
+  If Do_Write<0 Then
+   Begin
+    Errno2InOutRes;
+    Do_Write:=0;
+   End
+  else
+   InOutRes:=0;
+End;
+
+
+Function Do_Read(Handle,Addr,Len:Longint):Longint;
+Begin
+  repeat
+    Do_Read:=Fpread(Handle,pchar(addr),len);
+  until ErrNo<>ESysEINTR;
+  If Do_Read<0 Then
+   Begin
+    Errno2InOutRes;
+    Do_Read:=0;
+   End
+  else
+   InOutRes:=0;
+End;
+
+function Do_FilePos(Handle: Longint):longint;
+Begin
+  do_FilePos:=Fplseek(Handle, 0, SEEK_CUR);
+  If Do_FilePos<0 Then
+    Errno2InOutRes
+  else
+   InOutRes:=0;
+End;
+
+Procedure Do_Seek(Handle,Pos:Longint);
+Begin
+  If Fplseek(Handle, pos, SEEK_SET)<0 Then
+   Errno2Inoutres
+  Else
+   InOutRes:=0;
+End;
+
+Function Do_SeekEnd(Handle:Longint): Longint;
+begin
+  Do_SeekEnd:=Fplseek(Handle,0,SEEK_END);
+  If Do_SeekEnd<0 Then
+   Errno2Inoutres
+  Else
+   InOutRes:=0;
+end;
+
+Function Do_FileSize(Handle:Longint): Longint;
+var
+  Info : Stat;
+  Ret  : Longint;
+Begin
+  Ret:=Fpfstat(handle,info);
+  If Ret=0 Then
+   Do_FileSize:=Info.st_size
+  else
+   Do_FileSize:=0;
+  If Ret<0 Then
+   Errno2InOutRes
+  Else
+   InOutRes:=0;
+End;
+
+Procedure Do_Open(var f;p:pchar;flags:longint);
+{
+  FileRec and textrec have both Handle and mode as the first items so
+  they could use the same routine for opening/creating.
+  when (flags and $100)   the file will be append
+  when (flags and $1000)  the file will be truncate/rewritten
+  when (flags and $10000) there is no check for close (needed for textfiles)
+}
+var
+  oflags : cint;
+Begin
+{ close first if opened }
+  if ((flags and $10000)=0) then
+   begin
+     case FileRec(f).mode of
+      fminput,fmoutput,fminout : Do_Close(FileRec(f).Handle);
+      fmclosed : ;
+     else
+      begin
+        inoutres:=102; {not assigned}
+        exit;
+      end;
+     end;
+   end;
+{ reset file Handle }
+  FileRec(f).Handle:=UnusedHandle;
+{ We do the conversion of filemodes here, concentrated on 1 place }
+  case (flags and 3) of
+   0 : begin
+         oflags :=O_RDONLY;
+         FileRec(f).mode:=fminput;
+       end;
+   1 : begin
+         oflags :=O_WRONLY;
+         FileRec(f).mode:=fmoutput;
+       end;
+   2 : begin
+         oflags :=O_RDWR;
+         FileRec(f).mode:=fminout;
+       end;
+  end;
+  if (flags and $1000)=$1000 then
+   oflags:=oflags or (O_CREAT or O_TRUNC)
+  else
+   if (flags and $100)=$100 then
+    oflags:=oflags or (O_APPEND);
+{ empty name is special }
+  if p[0]=#0 then
+   begin
+     case FileRec(f).mode of
+       fminput :
+         FileRec(f).Handle:=StdInputHandle;
+       fminout, { this is set by rewrite }
+       fmoutput :
+         FileRec(f).Handle:=StdOutputHandle;
+       fmappend :
+         begin
+           FileRec(f).Handle:=StdOutputHandle;
+           FileRec(f).mode:=fmoutput; {fool fmappend}
+         end;
+     end;
+     exit;
+   end;
+{ real open call }
+  FileRec(f).Handle:=Fpopen(p,oflags,MODE_OPEN);
+  if (ErrNo=ESysEROFS) and ((OFlags and O_RDWR)<>0) then
+   begin
+     Oflags:=Oflags and not(O_RDWR);
+     FileRec(f).Handle:=Fpopen(p,oflags,MODE_OPEN);
+   end;
+  If Filerec(f).Handle<0 Then
+   Errno2Inoutres
+  else
+   InOutRes:=0;
+End;
+
+
+
+{*****************************************************************************
+                           Directory Handling
+*****************************************************************************}
+
+Procedure MkDir(Const s: String);[IOCheck];
+Var
+  Buffer: Array[0..255] of Char;
+Begin
+  If (s='') or (InOutRes <> 0) then
+   exit;
+  Move(s[1], Buffer, Length(s));
+  Buffer[Length(s)] := #0;
+  If Fpmkdir(@buffer, MODE_MKDIR)<0 Then
+   Errno2Inoutres
+  Else
+   InOutRes:=0;
+End;
+
+
+Procedure RmDir(Const s: String);[IOCheck];
+Var
+  Buffer: Array[0..255] of Char;
+Begin
+  if (s = '.') then
+    InOutRes := 16;
+  If (s='') or (InOutRes <> 0) then
+   exit;
+  Move(s[1], Buffer, Length(s));
+  Buffer[Length(s)] := #0;
+  If Fprmdir(@buffer)<0 Then
+   Errno2Inoutres
+  Else
+   InOutRes:=0;
+End;
+
+
+Procedure ChDir(Const s: String);[IOCheck];
+Var
+  Buffer: Array[0..255] of Char;
+Begin
+  If (s='') or (InOutRes <> 0) then
+   exit;
+  Move(s[1], Buffer, Length(s));
+  Buffer[Length(s)] := #0;
+  If Fpchdir(@buffer)<0 Then
+   Errno2Inoutres
+  Else
+   InOutRes:=0;
+  { file not exists is path not found under tp7 }
+  if InOutRes=2 then
+   InOutRes:=3;
+End;
+
+{ // $define usegetcwd}
+
+procedure getdir(drivenr : byte;var dir : shortstring);
+var
+{$ifndef usegetcwd}
+  cwdinfo      : stat;
+  rootinfo     : stat;
+  thedir,dummy : string[255];
+  dirstream    : pdir;
+  d            : pdirent;
+  name         : string[255];
+  thisdir      : stat;
+{$endif}
+  tmp          : string[255];
+
+begin
+{$ifdef usegetcwd}
+ Fpgetcwd(@tmp[1],255);
+ dir:=tmp;		
+{$else}
+  dir:='';
+  thedir:='';
+  dummy:='';
+
+  { get root directory information }
+  tmp := '/'+#0;
+  if Fpstat(@tmp[1],rootinfo)<0 then
+      Begin
+      Errno2Inoutres;
+      Exit
+     End
+    Else
+     InOutRes:=0;
+  repeat
+    tmp := dummy+'.'+#0;
+    { get current directory information }
+    if Fpstat(@tmp[1],cwdinfo)<0 then
+      Begin
+        Errno2Inoutres;
+        Exit
+      End
+    Else
+      InOutRes:=0;
+    tmp:=dummy+'..'+#0;
+    { open directory stream }
+    { try to find the current inode number of the cwd }
+    dirstream:=Fpopendir(@tmp[1]);
+    if dirstream=nil then
+       exit;
+    repeat
+      name:='';
+      d:=Fpreaddir(dirstream);
+      { no more entries to read ... }
+      if not assigned(d) then
+        begin
+          break;
+        end;
+      tmp:=dummy+'../'+strpas(d^.d_name) + #0;
+      if Fpstat(@tmp[1],thisdir)<0 then
+        begin
+          Errno2Inoutres;
+          Exit
+        End
+      Else
+        InOutRes:=0;
+      { found the entry for this directory name }
+      if (cwdinfo.st_dev=thisdir.st_dev) and (cwdinfo.st_ino=thisdir.st_ino) then
+        begin
+          { are the filenames of type '.' or '..' ? }
+          { then do not set the name.               }
+          if (not ((d^.d_name[0]='.') and ((d^.d_name[1]=#0) or
+                  ((d^.d_name[1]='.') and (d^.d_name[2]=#0))))) then
+            begin
+              name:='/'+strpas(d^.d_name);
+            end;
+        end
+    until (name<>'');
+    If Fpclosedir(dirstream)<0 THen
+      Begin
+        Errno2Inoutres;
+        Exit
+      End
+    Else
+      InOutRes:=0;
+    thedir:=name+thedir;
+    dummy:=dummy+'../';
+    if ((cwdinfo.st_dev=rootinfo.st_dev) and (cwdinfo.st_ino=rootinfo.st_ino)) then
+      begin
+        if thedir='' then
+          dir:='/'
+        else
+          dir:=thedir;
+        exit;
+      end;
+  until false;
+ {$endif}
+end;
+
+
+{*****************************************************************************
+                         SystemUnit Initialization
+*****************************************************************************}
+
+
+procedure SignalToRunerror(signo: cint); cdecl;
+var
+  res : word;
+begin
+    res:=0;
+    if signo = SIGFPE then
+     begin
+        res := 200;
+     end
+    else
+    if (signo = SIGILL) or (signo = SIGBUS) or (signo = SIGSEGV) then
+      begin
+        res := 216;
+      end;
+  { give runtime error at the position where the signal was raised }
+  if res<>0 then
+   begin
+     HandleError(res);
+   end;
+end;
+
+
+var
+  act: SigActionRec;
+
+Procedure InstallSignals;
+var
+  oldact: SigActionRec;
+begin
+  { Initialize the sigaction structure }
+  { all flags and information set to zero }
+  FillChar(act, sizeof(SigActionRec),0);
+  { initialize handler                    }
+  act.sa_handler := @SignalToRunError;
+  FpSigAction(SIGFPE,@act,@oldact);
+  FpSigAction(SIGSEGV,@act,@oldact);
+  FpSigAction(SIGBUS,@act,@oldact);
+  FpSigAction(SIGILL,@act,@oldact);
+end;
+
+
+procedure SetupCmdLine;
+var
+  bufsize,
+  len,j,
+  size,i : longint;
+  found  : boolean;
+  buf    : pchar;
+
+  procedure AddBuf;
+  begin
+    reallocmem(cmdline,size+bufsize);
+    move(buf^,cmdline[size],bufsize);
+    inc(size,bufsize);
+    bufsize:=0;
+  end;
+
+begin
+  GetMem(buf,ARG_MAX);
+  size:=0;
+  bufsize:=0;
+  i:=0;
+  while (i<argc) do
+   begin
+     len:=strlen(argv[i]);
+     if len>ARG_MAX-2 then
+      len:=ARG_MAX-2;
+     found:=false;
+     for j:=1 to len do
+      if argv[i][j]=' ' then
+       begin
+         found:=true;
+         break;
+       end;
+     if bufsize+len>=ARG_MAX-2 then
+      AddBuf;
+     if found then
+      begin
+        buf[bufsize]:='"';
+        inc(bufsize);
+      end;
+     move(argv[i]^,buf[bufsize],len);
+     inc(bufsize,len);
+     if found then
+      begin
+        buf[bufsize]:='"';
+        inc(bufsize);
+      end;
+     if i<argc then
+      buf[bufsize]:=' '
+     else
+      buf[bufsize]:=#0;
+     inc(bufsize);
+     inc(i);
+   end;
+  AddBuf;
+  FreeMem(buf,ARG_MAX);
+end;
+
+(*
+Begin
+{ Set up signals handlers }
+   InstallSignals;
+{ Setup heap }
+  InitHeap;
+  InitExceptions;
+{ Arguments }
+  SetupCmdLine;
+{ Setup stdin, stdout and stderr }
+  OpenStdIO(Input,fmInput,StdInputHandle);
+  OpenStdIO(Output,fmOutput,StdOutputHandle);
+  OpenStdIO(StdOut,fmOutput,StdOutputHandle);
+  OpenStdIO(StdErr,fmOutput,StdErrorHandle);
+{ Reset IO Error }
+  InOutRes:=0;
+End.
+*)
+{
+ $Log$
+ Revision 1.1  2002-12-18 16:43:26  marco
+  * new unix rtl, linux part.....
+
+ Revision 1.7  2002/11/14 12:18:03  marco
+  * fixed Fptime call to (NIL)
+
+ Revision 1.6  2002/10/27 17:21:29  marco
+  * Only "difficult" functions + execvp + termios + rewinddir left to do
+
+ Revision 1.5  2002/10/26 18:27:52  marco
+  * First series POSIX calls commits. Including getcwd.
+
+ Revision 1.4  2002/09/07 16:01:26  peter
+   * old logs removed and tabs fixed
+
+ Revision 1.3  2002/08/20 12:50:22  marco
+  * New errno handling. Should be libc compatible.
+
+ Revision 1.2  2002/08/10 13:42:36  marco
+  * Fixes Posix dir copied to devel branch
+
+ Revision 1.1.2.18  2002/03/10 11:45:02  carl
+ * InOutRes := 16 with rmdir()
+ * InOutRes := 5 more checking
+
+ Revision 1.1.2.17  2002/03/03 15:11:51  carl
+ * erase() bugfix (erasing a directory is done via rmdir() only!)
+
+ Revision 1.1.2.16  2002/02/15 18:13:35  carl
+ * bugfix for paramstr(0)
+
+}

+ 441 - 0
rtl/linux/ossysc.inc

@@ -0,0 +1,441 @@
+{
+    $Id$
+    Copyright (c) 2002 by Marco van de Voort
+
+    The base Linux syscalls required to implement the system unit. These
+    are aliased for use in other units (to avoid poluting the system units
+    interface)
+
+    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.
+
+ ****************************************************************************
+}
+
+{$ifdef uselibc}
+{$else}
+
+{*****************************************************************************
+                     --- Main:The System Call Self ---
+*****************************************************************************}
+
+{$I ostypes.inc}
+{$I syscallh.inc}
+{$I syscall.inc}
+{$I sysnr.inc}
+{$I bunxmacr.inc}
+
+function Fptime(tloc:pTime): TTime; [public, alias : 'FPC_SYSC_TIME'];
+
+begin
+  Fptime:=do_syscall(syscall_nr_time,TSysParam(tloc));
+End;
+
+{*****************************************************************************
+               --- File:File handling related calls ---
+*****************************************************************************}
+
+function Fpopen(path: pchar; flags : cint; mode: mode_t):cint; [public, alias : 'FPC_SYSC_OPEN'];
+
+Begin
+ Fpopen:=do_syscall(syscall_nr_open,TSysParam(path),TSysParam(flags),TSysParam(mode));
+End;
+
+function Fpclose(fd : cint): cint;
+
+begin
+ Fpclose:=do_syscall(syscall_nr_close,fd);
+end;
+
+function Fplseek(fd : cint; offset : off_t; whence : cint): off_t; [public, alias : 'FPC_SYSC_LSEEK'];
+{
+Must be adapted/overloaded for 64-bit support, but that is a different call under
+Linux?
+}
+begin
+  Fplseek:=do_syscall(syscall_nr_lseek,tsysparam(fd),tsysparam(offset),tsysparam(whence));
+end;
+
+function Fpread(fd: cint; buf: pchar; nbytes : size_t): ssize_t; [public, alias : 'FPC_SYSC_READ'];
+
+begin
+  Fpread:=do_syscall(syscall_nr_read,Fd,TSysParam(buf),nbytes);
+end;
+
+function Fpwrite(fd: cint;buf:pchar; nbytes : size_t): ssize_t; [public, alias : 'FPC_SYSC_WRITE'];
+
+begin
+ Fpwrite:=do_syscall(syscall_nr_write,Fd,TSysParam(buf),nbytes);
+end;
+
+function Fpunlink(path: pchar): cint; [public, alias : 'FPC_SYSC_UNLINK'];
+
+begin
+  Fpunlink:=do_syscall(syscall_nr_unlink,TSysParam(path));
+end;
+
+function Fprename(old : pchar; newpath: pchar): cint; [public, alias : 'FPC_SYSC_RENAME'];
+
+begin
+  Fprename:=do_syscall(syscall_nr_rename,TSysParam(old),TSysParam(newpath));
+end;
+
+function Fpstat(path: pchar; var buf : stat):cint; [public, alias : 'FPC_SYSC_STAT'];
+
+begin
+ Fpstat:=do_syscall(syscall_nr_stat,TSysParam(path),TSysParam(@buf));
+end;
+
+
+{*****************************************************************************
+               --- Directory:Directory related calls ---
+*****************************************************************************}
+
+function Fpchdir(path : pchar): cint; [public, alias : 'FPC_SYSC_CHDIR'];
+
+begin
+ Fpchdir:=do_syscall(syscall_nr_chdir,TSysParam(path));
+end;
+
+function Fpmkdir(path : pchar; mode: mode_t):cint; [public, alias : 'FPC_SYSC_MKDIR'];
+
+begin 
+  Fpmkdir:=do_syscall(syscall_nr_mkdir,TSysParam(path),TSysParam(mode));
+end;
+
+function Fprmdir(path : pchar): cint;  [public, alias : 'FPC_SYSC_RMDIR'];
+
+begin
+ Fprmdir:=do_syscall(syscall_nr_rmdir,TSysParam(path));
+end;
+
+function Fpopendir(dirname : pchar): pdir;  [public, alias : 'FPC_SYSC_OPENDIR'];
+
+var
+  fd:integer;
+  st:stat;
+  ptr:pdir;
+
+begin
+  Fpopendir:=nil;
+  if Fpstat(dirname,st)<0 then
+   exit;
+{ Is it a dir ? }
+  if not((st.st_mode and $f000)=$4000)then
+   begin
+     errno:=ESysENOTDIR;
+     exit
+   end;
+{ Open it}
+  fd:=Fpopen(dirname,O_RDONLY,438);
+  if fd<0 then
+   exit;
+  new(ptr);
+  if ptr=nil then
+   exit;
+  getmem(ptr^.buf,sizeof(dirent));
+  if ptr^.buf=nil then
+   exit;
+  ptr^.fd:=fd;
+  ptr^.loc:=0;
+  ptr^.size:=0;
+  ptr^.dd_max:=sizeof(ptr^.buf^);
+  Fpopendir:=ptr;
+end;
+
+function Fpclosedir(dirp : pdir): cint; [public, alias : 'FPC_SYSC_CLOSEDIR'];
+
+begin
+  Fpclosedir:=Fpclose(dirp^.fd);
+  freemem(dirp^.buf,sizeof(dirent));
+  dispose(dirp);
+end;
+
+function Fpreaddir(dirp : pdir) : pdirent; [public, alias : 'FPC_SYSC_READDIR'];
+
+{Different from Linux, Readdir on BSD is based on Getdents, due to the
+missing of the readdir syscall.
+Getdents requires the buffer to be larger than the blocksize.
+This usually the sectorsize =512 bytes, but maybe tapedrives and harddisks
+with blockmode have this higher?}
+
+begin
+  if do_SysCall(SysCall_nr_readdir,TSysParam(dirp^.fd),TSysParam(dirp^.buf),TSysParam(1))=0 Then
+{ the readdir system call returns the number of bytes written }
+   Fpreaddir:=nil
+  else
+   Fpreaddir:=dirp^.buf
+end;
+
+{*****************************************************************************
+        --- Process:Process & program handling - related calls ---
+*****************************************************************************}
+
+procedure Fpexit(status : cint); [public, alias : 'FPC_SYSC_EXIT'];
+
+begin
+  do_syscall(syscall_nr_exit,status);
+end;
+
+{
+  Change action of process upon receipt of a signal.
+  Signum specifies the signal (all except SigKill and SigStop).
+  If Act is non-nil, it is used to specify the new action.
+  If OldAct is non-nil the previous action is saved there.
+}
+
+function Fpsigaction(sig: cint; act : psigactionrec; oact : psigactionrec): cint; [public, alias : 'FPC_SYSC_SIGACTION'];
+
+{
+  Change action of process upon receipt of a signal.
+  Signum specifies the signal (all except SigKill and SigStop).
+  If Act is non-nil, it is used to specify the new action.
+  If OldAct is non-nil the previous action is saved there.
+}
+
+begin
+  do_syscall(syscall_nr_sigaction,TSysParam(sig),TSysParam(act),TSysParam(oact));
+end;
+
+function Fpftruncate(fd : cint; flength : off_t): cint; [public, alias : 'FPC_SYSC_FTRUNCATE'];
+{ See notes lseek. This one is completely similar for the parameter (but
+doesn't have the returnvalue 64-bit problem)}
+
+begin
+ Fpftruncate:=Do_syscall(syscall_nr_ftruncate,TSysParam(fd),TSysParam(flength));
+end;
+
+function Fpfstat(fd : cint; var sb : stat): cint;  [public, alias : 'FPC_SYSC_FSTAT'];
+
+begin
+  FpFStat:=do_SysCall(syscall_nr_fstat,TSysParam(fd),TSysParam(@sb));
+end;
+
+
+function Fpfork : pid_t;  [public, alias : 'FPC_SYSC_FORK'];
+{
+  This function issues the 'fork' System call. the program is duplicated in memory
+  and Execution continues in parent and child process.
+  In the parent process, fork returns the PID of the child. In the child process,
+  zero is returned.
+  A negative value indicates that an error has occurred, the error is returned in
+  LinuxError.
+}
+
+Begin
+ Fpfork:=Do_syscall(SysCall_nr_fork);
+End;
+
+// Look at execve variants later, when overloaded is determined.
+{
+function Fpexecve(path : pathstr; argv : ppchar; envp: ppchar): cint;
+}
+{
+  Replaces the current program by the program specified in path,
+  arguments in args are passed to Execve.
+  environment specified in ep is passed on.
+}
+
+{
+Begin
+  path:=path+#0;
+  do_syscall(syscall_nr_Execve,TSysParam(@path[1]),TSysParam(Argv),TSysParam(envp));
+End;
+}
+{
+function Fpexecve(path : pchar; argv : ppchar; envp: ppchar): cint;  [public, alias : 'FPC_SYSC_EXECVE'];
+}
+{
+  Replaces the current program by the program specified in path,
+  arguments in args are passed to Execve.
+  environment specified in ep is passed on.
+}
+{
+Begin
+  do_syscall(syscall_nr_Execve,TSysParam(path),TSysParam(Argv),TSysParam(envp));
+End;
+}
+
+function Fpwaitpid(pid : pid_t; stat_loc : pcint; options: cint): pid_t; [public, alias : 'FPC_SYSC_WAITPID'];
+{
+  Waits until a child with PID Pid exits, or returns if it is exited already.
+  Any resources used by the child are freed.
+  The exit status is reported in the adress referred to by Status. It should
+  be a longint.
+}
+
+begin
+ FpWaitPID:=do_syscall(syscall_nr_WaitPID,PID,TSysParam(Stat_loc),options);
+end;
+
+function Fpaccess(pathname : pchar; amode : cint): cint; [public, alias : 'FPC_SYSC_ACCESS'];
+{
+  Test users access rights on the specified file.
+  Mode is a mask xosisting of one or more of R_OK, W_OK, X_OK, F_OK.
+  R,W,X stand for read,write and Execute access, simultaneously.
+  F_OK checks whether the test would be allowed on the file.
+  i.e. It checks the search permissions in all directory components
+  of the path.
+  The test is done with the real user-ID, instead of the effective.
+  If access is denied, or an error occurred, false is returned.
+  If access is granted, true is returned.
+  Errors other than no access,are reported in unixerror.
+}
+
+begin
+ FpAccess:=do_syscall(syscall_nr_access,TSysParam(pathname),amode);
+end;
+
+{ overloaded
+function Fpaccess(pathname : pathstr; amode : cint): cint;
+
+{
+  Test users access rights on the specified file.
+  Mode is a mask xosisting of one or more of R_OK, W_OK, X_OK, F_OK.
+  R,W,X stand for read,write and Execute access, simultaneously.
+  F_OK checks whether the test would be allowed on the file.
+  i.e. It checks the search permissions in all directory components
+  of the path.
+  The test is done with the real user-ID, instead of the effective.
+  If access is denied, or an error occurred, false is returned.
+  If access is granted, true is returned.
+  Errors other than no access,are reported in unixerror.
+}
+
+begin
+ pathname:=pathname+#0;
+ Access:=do_syscall(syscall_nr_access, TSysParam(@pathname[1]),mode)=0;
+end;
+}
+
+Function FpDup(fildes:cint):cint; [public, alias : 'FPC_SYSC_DUP'];
+
+begin
+  Fpdup:=Do_syscall(syscall_nr_dup,TSysParam(fildes));
+end;
+
+Function FpDup2(fildes,fildes2:cint):cint; [public, alias : 'FPC_SYSC_DUP2'];
+
+begin
+ Fpdup2:=do_syscall(syscall_nr_dup2,TSysParam(fildes),TSysParam(fildes2));
+end;
+
+CONST
+
+  { Constansts for MMAP }
+  MAP_PRIVATE   =2;
+  MAP_ANONYMOUS =$20;
+
+  {Constansts Termios/Ioctl (used in Do_IsDevice) }
+  IOCtl_TCGETS=$5401; // TCGETS is also in termios.inc, but the sysunix needs only this
+
+type
+  tmmapargs=packed record
+    address : longint;
+    size    : longint;
+    prot    : longint;
+    flags   : longint;
+    fd      : longint;
+    offset  : longint;
+  end;
+
+
+Function Fpmmap(adr:pointer;len:size_t;prot:cint;flags:cint;fd:cint;off:off_t):pointer;  [public, alias : 'FPC_SYSC_MMAP'];
+// OFF_T procedure, and returns a pointer, NOT cint.
+
+var
+  mmapargs : tmmapargs;
+begin
+  mmapargs.address:=TSysParam(adr);
+  mmapargs.size:=TSysParam(len);
+  mmapargs.prot:=TSysParam(prot);
+  mmapargs.flags:=TSysParam(flags);
+  mmapargs.fd:=TSysParam(fd);
+  mmapargs.offset:=TSysParam(off);
+  Fpmmap:=pointer(do_syscall(syscall_nr_mmap,TSysParam(@MMapArgs)));
+end;
+
+Function Fpmunmap(adr:pointer;len:size_t):cint; [public, alias :'FPC_SYSC_MUNMAP'];
+begin
+  Fpmunmap:=do_syscall(syscall_nr_munmap,TSysParam(Adr),TSysParam(Len));
+end;
+
+Function sbrk(size : longint) : longint;
+begin
+  sbrk:=longint(Fpmmap(0,Size,3,MAP_PRIVATE+MAP_ANONYMOUS,-1,0));
+  if sbrk<>-1 then
+   errno:=0;
+  {! It must be -1, not 0 as before, see heap.inc. Should be in sysmmap?}
+end;
+
+{
+  Interface to Unix ioctl call.
+  Performs various operations on the filedescriptor Handle.
+  Ndx describes the operation to perform.
+  Data points to data needed for the Ndx function. The structure of this
+  data is function-dependent.
+}
+
+// prototype is cint __P(cint,culong,....)
+// actual meaning of return value depends on request.
+
+Function FpIOCtl(fd:cint;request:culong;Data: Pointer):cint;  [public, alias : 'FPC_SYSC_IOCTL'];
+// This was missing here, instead hardcoded in Do_IsDevice
+begin
+  FpIOCtl:=do_SysCall(syscall_nr_ioctl,tsysparam(fd),tsysparam(Request),TSysParam(data));
+end;
+
+Function Do_IsDevice(Handle:cint):boolean;
+{
+  Interface to Unix ioctl call.
+  Performs various operations on the filedescriptor Handle.
+  Ndx describes the operation to perform.
+  Data points to data needed for the Ndx function. The structure of this
+  data is function-dependent.
+}
+
+var
+  Data : array[0..255] of byte; {Large enough for termios info}
+begin
+  Do_IsDevice:=(Fpioctl(handle,IOCTL_TCGETS,@data)<>-1);
+end;
+
+Function FpGetPid:pid_t;   [public, alias : 'FPC_SYSC_GETPID'];
+{
+  Get Process ID.
+}
+
+begin
+ FpGetPID:=do_syscall(syscall_nr_getpid);
+end;
+
+Function FpReadLink(name,linkname:pchar;maxlen:size_t):cint;  [public, alias : 'FPC_SYSC_READLINK'];
+
+begin
+  Fpreadlink:=do_syscall(syscall_nr_readlink, TSysParam(name),TSysParam(linkname),maxlen);
+end;
+
+Function FpNanoSleep(const req : timespec;rem : ptimespec) : longint; [public, alias : 'FPC_SYSC_NANOSLEEP'];
+begin
+  FpNanoSleep:=Do_SysCall(syscall_nr_nanosleep,TSysParam(@req),TSysParam(rem));
+end;
+
+// The following belongs here, but this should be researched more.
+// function Fpgetcwd(pt:pchar; _size:size_t):pchar;[public, alias :'FPC_SYSC_GETCWD'];
+
+{$endif}
+
+{
+ $Log$
+ Revision 1.1  2002-12-18 16:43:26  marco
+  * new unix rtl, linux part.....
+
+ Revision 1.1  2002/11/12 14:40:18  marco
+  * The syscall core of the new system unit.
+
+
+}

+ 31 - 0
rtl/linux/ossysch.inc

@@ -0,0 +1,31 @@
+{
+    $Id$
+    Copyright (c) 2002 by Marco van de Voort
+
+    Header file for calls used in System unit, but not exposed
+    in BaseUnix.
+
+    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.
+
+ ****************************************************************************
+}
+
+Function Fpmmap(adr:pointer;len:size_t;prot:cint;flags:cint;fd:cint;off:off_t):pointer;  external name 'FPC_SYSC_MMAP';
+Function Fpmunmap(adr:pointer;len:size_t):cint; external name 'FPC_SYSC_MUNMAP';
+Function FpIOCtl(fd:cint;request:culong;Data: Pointer):cint;  external name 'FPC_SYSC_IOCTL';
+Function FpGetPid:pid_t;   external name 'FPC_SYSC_GETPID';
+Function FpReadLink(name,linkname:pchar;maxlen:size_t):cint;  external name 'FPC_SYSC_READLINK';
+Function FpNanoSleep(const req : timespec;rem : ptimespec) : longint; external name 'FPC_SYSC_NANOSLEEP';
+
+{
+ $Log$
+ Revision 1.1  2002-12-18 16:43:26  marco
+  * new unix rtl, linux part.....
+
+
+}

+ 39 - 14
rtl/linux/ostypes.inc

@@ -4,7 +4,7 @@
     Copyright (c) 1999-2000 by Michael Van Canneyt,
     member of the Free Pascal development team.
     
-    OS dependant types internal to the Unix RTL.
+    OS dependant types internal to the Linux RTL.
 
     See the file COPYING.FPC, included in this distribution,
     for details about the copyright.
@@ -15,6 +15,7 @@
 
  **********************************************************************}
 
+Type
 
 {
  Linux system calls take arguments as follows :
@@ -31,22 +32,46 @@
   To make it processor independent, we don't give any system dependent
   names, but the rather abstract reg1,reg2 etc;
 }
-  SysCallRegs=record
-    reg1,reg2,reg3,reg4,reg5,reg6 : longint;
-  end;
-  PSysCallRegs=^SysCallRegs;
-  TSysCallRegs=SysCallRegs;
-
-  ptimespec= ^timespec;
-  timespec = packed record
-    tv_sec   : time_t;
-    tv_nsec  : clong;
-  end;
+
+  SysCallRegs = record
+    		 reg1,
+	 	 reg2,
+		 reg3,
+		 reg4,
+		 reg5,
+		 reg6   : longint;
+  		end;
+  PSysCallRegs= ^SysCallRegs;
+  TSysCallRegs= SysCallRegs;
+
+
+  ptimespec   = ^timespec;
+  timespec    = packed record
+    		 tv_sec   : time_t;
+    		 tv_nsec  : clong;
+ 		end;
+
+  timeval     = packed record
+    		 tv_sec,
+		 tv_usec:clong;
+  		end;
+  ptimeval    = ^timeval;
+  TTimeVal    = timeval;
+
+CONST 
+       _S_IFDIR = $4000;
+       _S_IFCHR = $2000;
+       _S_IFBLK = $6000;
+       _S_IFREG = $8000;
+       _S_IFMT  = $f000;
+       _S_IFIFO = $1000;
 
 {
  $Log$
- Revision 1.1  2002-11-12 14:37:59  marco
-  * Parts of new unix rtl
+ Revision 1.2  2002-12-18 16:43:26  marco
+  * new unix rtl, linux part.....
 
+ Revision 1.1  2002/11/12 14:37:59  marco
+  * Parts of new unix rtl
 
 }

+ 49 - 11
rtl/linux/ptypes.inc

@@ -34,15 +34,34 @@ introduction)
 
 Type
 
-{$ifndef VER_1_0}
+{$ifndef VER_1_0}		// maybe wrong (kernel vs libc)
     dev_t    = cuint64;         { used for device numbers      }
 {$else}
     dev_t    = int64;
 {$endif}
+    TDev     = dev_t;
+    pDev     = ^dev_t;
+
+    kDev_t   = cushort;		// Linux has two different device conventions
+    TkDev    = KDev_t;		// kernel and glibc. This is kernel.
+    pkDev    = ^kdev_t;
+
     gid_t    = cuint32;         { used for group IDs           }
+    TGid     = gid_t;
+    pGid     = ^gid_t;
+
     ino_t    = clong;           { used for file serial numbers }
+    TIno     = ino_t;
+    pIno     = ^ino_t;
+
     mode_t   = cuint32;         { used for file attributes     }
+    TMode    = mode_t;
+    pMode    = ^mode_t;
+
     nlink_t  = cuint32;         { used for link counts         }
+    TnLink   = nlink_t;
+    pnLink   = ^nlink_t;
+
   {$ifdef 64BitArch}
     off_t    = cint64;          { used for file sizes          }
   {$else}
@@ -50,26 +69,42 @@ Type
     off_t    = cint64;
    {$else}
     off_t    = cint;
-    pid_t    = cint32;          { used as process identifier   }
    {$endif}
   {$endif}
+    TOff     = off_t;
+    pOff     = ^off_t;
+
+    pid_t    = cint32;          { used as process identifier   }
+    TPid     = pid_t;
+    pPid     = ^pid_t;
+
    {$ifdef 64bitarch} 
     size_t   = cuint64;         { as definied in the C standard}
     ssize_t  = cint64;          { used by function for returning number of bytes }
+    clock_t  = cuint64;
+    time_t   = cint64;           { used for returning the time  }
    {$else}
     size_t   = cuint32;         { as definied in the C standard}
     ssize_t  = cint32;          { used by function for returning number of bytes }
-   {$endif}
-    uid_t    = cuint32;         { used for user ID type        }
-  {$ifdef 64bitarch}
-    clock_t  = cuint64;
-    time_t   = cint64;           { used for returning the time  }
-  {$else}
     clock_t  = culong;
     time_t   = clong;           { used for returning the time  }
-  {$endif}
-    ptime_t  = ^time_t;
+   {$endif}
+    TSize     = size_t;
+    pSize     = ^size_t;
+    TSSize    = ssize_t;
+    pSSize    = ^ssize_t;
+    TClock    = clock_t;
+    pClock    = ^clock_t;
+    TTime     = time_t;
+    pTime     = ^time_t;
+  
+    uid_t    = cuint32;         { used for user ID type        }
+    TUid     = uid_t;
+    pUid     = ^uid_t;
+
     socklen_t= cuint32;
+    TSockLen = socklen_t;
+    pSockLen = ^socklen_t;
 
 CONST
    { System limits, POSIX value in parentheses, used for buffer and stack allocation }
@@ -81,7 +116,10 @@ CONST
 
 {
    $Log$
-   Revision 1.2  2002-11-12 14:28:40  marco
+   Revision 1.3  2002-12-18 16:43:26  marco
+    * new unix rtl, linux part.....
+
+   Revision 1.2  2002/11/12 14:28:40  marco
     * some updates
 
    Revision 1.1  2002/10/29 16:47:17  marco

+ 20 - 2
rtl/linux/signal.inc

@@ -15,6 +15,15 @@
 
 {$packrecords C}
 
+
+Const 			// OS specific parameters for general sigset behaviour
+   SIG_MAXSIG      = 1024;	// highest signal version
+   wordsinsigset   = 32;	// words in sigset_t
+   ln2bitsinword   = 5;         { 32bit : ln(32)/ln(2)=5 } 
+
+   ln2bitmask	   = 2 shl ln2bitsinword - 1;
+
+
 {********************
       Signal
 ********************}
@@ -182,8 +191,13 @@ type
   PSignalRestorer = ^SignalRestorer;
   TSigAction = procedure(Sig: Longint; SigContext: SigContextRec);cdecl;
 
-  SigSet  = Longint;
+
+
+  SigSet  =  array[0..wordsinsigset-1] of Longint;
+  sigset_t= SigSet;
   PSigSet = ^SigSet;
+  psigset_t=psigset;
+  TSigSet = SigSet;
 
   SigActionRec = packed record  // this is temporary for the migration
    {$ifdef posixworkaround}
@@ -199,11 +213,15 @@ type
     Sa_Flags    : Longint;
     Sa_restorer : SignalRestorer; { Obsolete - Don't use }
   end;
+  TSigActionRec = SigActionRec;
   PSigActionRec = ^SigActionRec;
 
 {
   $Log$
-  Revision 1.7  2002-11-12 14:51:44  marco
+  Revision 1.8  2002-12-18 16:43:26  marco
+   * new unix rtl, linux part.....
+
+  Revision 1.7  2002/11/12 14:51:44  marco
    * signal.
 
   Revision 1.6  2002/09/07 16:01:19  peter

+ 5 - 2
rtl/linux/syscalls.inc

@@ -209,7 +209,7 @@ begin
 { Is it a dir ? }
   if not((st.mode and $f000)=$4000)then
    begin
-     errno:=sys_enotdir;
+     errno:=ESysENOTDIR;
      exit
    end;
 { Open it}
@@ -435,7 +435,10 @@ end;
 
 {
   $Log$
-  Revision 1.16  2002-11-11 21:40:26  marco
+  Revision 1.17  2002-12-18 16:43:26  marco
+   * new unix rtl, linux part.....
+
+  Revision 1.16  2002/11/11 21:40:26  marco
    * rename syscall.inc -> syscallo.inc
 
   Revision 1.15  2002/10/14 19:39:17  peter

+ 11 - 8
rtl/linux/unixsysc.inc

@@ -128,7 +128,7 @@ begin
    begin
      { We can save an interrupt here }
      getpriority:=0;
-     linuxerror:=Sys_einval;
+     linuxerror:=ESyseinval;
    end
   else
    begin
@@ -161,7 +161,7 @@ var
 begin
   errno:=0;
   if ((which<prio_process) or (which>prio_user)) or ((what<-20) or (what>20)) then
-   linuxerror:=Sys_einval  { We can save an interrupt here }
+   linuxerror:=ESyseinval  { We can save an interrupt here }
   else
    begin
      sr.reg2:=which;
@@ -311,7 +311,7 @@ Function Fcntl(Fd:longint;Cmd:longint):longint;
   Possible values for Cmd are :
     F_GetFd,F_GetFl,F_GetOwn
   Errors are reported in Linuxerror;
-  If Cmd is different from the allowed values, linuxerror=Sys_eninval.
+  If Cmd is different from the allowed values, linuxerror=ESyseninval.
 }
 var
   sr : Syscallregs;
@@ -334,7 +334,7 @@ begin
    end
   else
    begin
-     linuxerror:=Sys_einval;
+     linuxerror:=ESyseinval;
      Fcntl:=0;
    end;
 end;
@@ -347,7 +347,7 @@ Procedure Fcntl(Fd:longint;Cmd : longint;Arg:Longint);
   Possible values for Cmd are :
     F_setFd,F_SetFl,F_GetLk,F_SetLk,F_SetLkW,F_SetOwn;
   Errors are reported in Linuxerror;
-  If Cmd is different from the allowed values, linuxerror=Sys_eninval.
+  If Cmd is different from the allowed values, linuxerror=ESyseninval.
   F_DupFD is not allowed, due to the structure of Files in Pascal.
 }
 var
@@ -362,7 +362,7 @@ begin
      linuxerror:=errno;
    end
   else
-   linuxerror:=Sys_einval;
+   linuxerror:=ESyseinval;
 end;
 
 
@@ -755,7 +755,7 @@ Procedure SigSuspend(Mask:Sigset);
 Var
   sr : SyscallRegs;
 begin
-  sr.reg2:=mask;
+  sr.reg2:=mask[0];
   SysCall(Syscall_nr_sigsuspend,sr);
   linuxerror:=errno;
 end;
@@ -885,7 +885,10 @@ end;
 
 {
   $Log$
-  Revision 1.7  2002-09-07 16:01:20  peter
+  Revision 1.8  2002-12-18 16:43:26  marco
+   * new unix rtl, linux part.....
+
+  Revision 1.7  2002/09/07 16:01:20  peter
     * old logs removed and tabs fixed
 
   Revision 1.6  2002/03/05 20:04:25  michael