Browse Source

* First working POSIX *BSD system unit.

marco 23 years ago
parent
commit
e2367dfb42
10 changed files with 952 additions and 503 deletions
  1. 78 0
      rtl/bsd/bsdmacro.inc
  2. 549 0
      rtl/bsd/bsdsysc.inc
  3. 49 0
      rtl/bsd/bsdtypes.inc
  4. 9 9
      rtl/bsd/i386/syscall.inc
  5. 38 484
      rtl/bsd/osposix.inc
  6. 5 2
      rtl/bsd/osposixh.inc
  7. 18 0
      rtl/bsd/readme.txt
  8. 1 0
      rtl/bsd/sysbsd.pp
  9. 7 8
      rtl/bsd/sysctl.pp
  10. 198 0
      rtl/bsd/system.pp

+ 78 - 0
rtl/bsd/bsdmacro.inc

@@ -0,0 +1,78 @@
+{
+    $Id$
+    Copyright (c) 2000-2002 by Marco van de Voort
+
+    The *BSD POSIX macro's that are used both in the POSIX 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 S_ISDIR(m : mode_t): boolean;
+      
+begin
+ S_ISDIR:=((m and %001111000000000000) = %100000000000000);
+end;
+
+function S_ISCHR(m : mode_t): boolean;
+begin
+ S_ISCHR:=((m and %001111000000000000) = %10000000000000);
+end;
+
+function S_ISBLK(m : mode_t): boolean;
+begin
+ S_ISBLK:=((m and %001111000000000000) = %110000000000000);
+end;
+    
+function S_ISREG(m : mode_t): boolean;
+begin
+ S_ISREG:=((m and %001111000000000000) = %1000000000000000);
+end;
+
+function S_ISFIFO(m : mode_t): boolean;
+begin
+ S_ISFIFO:=((m and %001111000000000000) = %1000000000000);
+end;
+    
+function wifexited(status : cint): cint;
+begin
+ wifexited:=cint((status AND %1111111) =0);
+end;
+
+function wexitstatus(status : cint): cint;
+begin
+ wexitstatus:=(status and %1111111) shl 8;  	
+end;
+
+function wstopsig(status : cint): cint;
+begin
+ wstopsig:=(status and %1111111) shl 8;  	
+end;
+
+function wifsignaled(status : cint): cint;
+begin
+ wifsignaled:=cint(((status and %1111111)<>%1111111) and ((status and %1111111)<>0));
+end;
+
+{
+  $Log$
+  Revision 1.1  2002-08-19 12:29:11  marco
+   * First working POSIX *BSD system unit.
+
+
+}

+ 549 - 0
rtl/bsd/bsdsysc.inc

@@ -0,0 +1,549 @@
+{
+    $Id$
+    Copyright (c) 2001 by Carl Eric Codere
+
+    The base *BSD syscalls required to implement the system unit. These
+    are aliased for use in other units (to avoid poluting the system units
+    interface)
+
+    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.
+
+ ****************************************************************************
+}
+
+{$ifdef uselibc}
+  {$Linklib c}
+
+{   var
+     Errno : cint; external name 'errno';}
+
+    function sys_time(var tloc:time_t): time_t; cdecl; external name 'time';
+    function sys_open(const path: pchar; flags : cint; mode: mode_t):cint; cdecl; external name 'open';
+    function sys_close(fd : cint): cint; cdecl; external name 'close';
+    function sys_lseek(fd : cint; offset : off_t; whence : cint): off_t; cdecl; external name 'lseek';
+    function sys_read(fd: cint; buf: pchar; nbytes : size_t): ssize_t; cdecl; external name 'read';
+    function sys_write(fd: cint;const buf:pchar; nbytes : size_t): ssize_t; cdecl; external name 'write';
+    function sys_unlink(const path: pchar): cint; cdecl; external name 'unlink';
+    function sys_rename(const old : pchar; const newpath: pchar): cint; cdecl;external name 'rename';
+    function sys_stat(const path: pchar; var buf : stat): cint; cdecl; external name 'stat';
+    function sys_chdir(const path : pchar): cint; cdecl; external name 'chdir';
+    function sys_mkdir(const path : pchar; mode: mode_t):cint; cdecl; external name 'mkdir';
+    function sys_rmdir(const path : pchar): cint; cdecl; external name 'rmdir';
+    function sys_opendir(const dirname : pchar): pdir; cdecl; external name 'opendir';
+    function sys_readdir(dirp : pdir) : pdirent;cdecl; external name 'readdir';
+    function sys_closedir(dirp : pdir): cint; cdecl; external name 'closedir';
+    procedure sys_exit(status : cint); cdecl; external name '_exit';
+    function sys_sigaction(sig: cint; var act : sigactionrec; var oact : sigactionrec): cint; cdecl; external name 'sigaction';
+    function sys_ftruncate(fd : cint; flength : off_t): cint; cdecl; external name 'ftruncate';
+    function sys_rename(const old : pchar; const newpath: pchar): cint; cdecl;external name 'rename';
+    function sys_fstat(fd : cint; var sb : stat): cint; cdecl; external name 'fstat';
+    function sys_fork : pid_t; cdecl; external name 'fork';
+    function sys_execve(const path : pchar; const argv : ppchar; const envp: ppchar): cint; cdecl; external name 'execve';
+    function sys_waitpid(pid : pid_t; var stat_loc : cint; options: cint): pid_t; cdecl; external name 'waitpid';
+    function sys_access(const pathname : pchar; amode : cint): cint; cdecl; external name 'access';
+
+//    function sys_uname(var name: utsname): cint; cdecl; external name 'uname';
+
+    function sys_Dup(oldd:cint):cint; cdecl; external name 'dup';
+    function sys_Dup2(oldd:cint;newd:cint):cint; cdecl; external name 'dup2';
+
+
+{$else}
+
+{*****************************************************************************
+                     --- Main:The System Call Self ---
+*****************************************************************************}
+
+{ The system designed for Linux can't be used for *BSD so easily, since
+  *BSD pushes arguments, instead of loading them to registers.}
+
+// Var ErrNo : Longint;
+
+{$I syscall.inc}
+{$I sysnr.inc}
+{$I bsdmacro.inc}
+{$I bsdtypes.inc}
+
+// Should be moved to a FreeBSD specific unit in the future.
+
+function sys_time(var tloc:time_t): time_t; [public, alias : 'FPC_SYSC_TIME'];
+
+VAR tv     : timeval;
+    tz     : timezone;
+    retval : longint;
+
+begin
+  Retval:=do_syscall(syscall_nr_gettimeofday,longint(@tv),longint(@tz));
+  If retval=-1 then
+   sys_time:=-1
+  else
+   Begin
+//    If Assigned(tloc) Then
+     TLoc:=tv.sec;
+    sys_time:=tv.sec;
+   End;
+End;
+
+{*****************************************************************************
+               --- File:File handling related calls ---
+*****************************************************************************}
+
+function sys_open(const path: pchar; flags : cint; mode: mode_t):cint; [public, alias : 'FPC_SYSC_OPEN'];
+
+Begin
+ sys_open:=do_syscall(syscall_nr_open,longint(path),longint(flags),longint(mode));
+End;
+
+function sys_close(fd : cint): cint;  
+
+begin
+ sys_close:=do_syscall(syscall_nr_close,fd);
+end;
+
+function sys_lseek(fd : cint; offset : off_t; whence : cint): off_t; [public, alias : 'FPC_SYSC_LSEEK'];
+{
+this one is special for the return value being 64-bit..
+hi/lo offset not yet tested.
+
+NetBSD: ok, but implicit return value in edx:eax
+FreeBSD: same implementation as NetBSD.
+}
+
+begin
+  {ugly implicit returnvalue}
+  do_syscall(syscall_nr___syscall,syscall_nr_lseek,0,longint(fd),0,lo(Offset),{0} hi(offset),Whence);
+end;
+
+function sys_read(fd: cint; buf: pchar; nbytes : size_t): ssize_t; [public, alias : 'FPC_SYSC_READ'];
+
+begin
+  sys_read:=do_syscall(syscall_nr_read,Fd,longint(buf),nbytes);
+end;
+
+function sys_write(fd: cint;const buf:pchar; nbytes : size_t): ssize_t; [public, alias : 'FPC_SYSC_WRITE'];
+
+begin
+ sys_write:=do_syscall(syscall_nr_write,Fd,longint(buf),nbytes);
+end;
+
+function sys_unlink(const path: pchar): cint; [public, alias : 'FPC_SYSC_UNLINK'];
+
+begin
+  sys_unlink:=do_syscall(syscall_nr_unlink,longint(path));
+end;
+
+function sys_rename(const old : pchar; const newpath: pchar): cint; [public, alias : 'FPC_SYSC_RENAME'];
+
+begin
+  sys_rename:=do_syscall(syscall_nr_rename,longint(old),longint(newpath));
+end;
+
+function sys_stat(const path: pchar; var buf : stat):cint; [public, alias : 'FPC_SYSC_STAT'];
+
+begin
+ sys_stat:=do_syscall(syscall_nr_stat,longint(path),longint(@buf));
+end;
+
+
+{*****************************************************************************
+               --- Directory:Directory related calls ---
+*****************************************************************************}
+
+function sys_chdir(const path : pchar): cint; [public, alias : 'FPC_SYSC_CHDIR'];
+
+begin
+ sys_chdir:=do_syscall(syscall_nr_chdir,longint(path));
+end;
+
+function sys_mkdir(const path : pchar; mode: mode_t):cint; [public, alias : 'FPC_SYSC_MKDIR'];
+
+begin {Mode is 16-bit on F-BSD}
+  sys_mkdir:=do_syscall(syscall_nr_mkdir,longint(path),mode);
+end;
+
+function sys_rmdir(const path : pchar): cint;  [public, alias : 'FPC_SYSC_RMDIR'];
+
+begin
+ sys_rmdir:=do_syscall(syscall_nr_rmdir,longint(path));
+end;
+
+{$ifndef NewReaddir}
+
+const DIRBLKSIZ=1024;
+
+ 
+function sys_opendir(const dirname : pchar): pdir;  [public, alias : 'FPC_SYSC_OPENDIR'];
+
+var
+  fd:longint;
+  st:stat;
+  ptr:pdir;
+begin
+  sys_opendir:=nil;
+  if sys_stat(dirname,st)<0 then
+   exit;
+{ Is it a dir ? }
+  if not((st.st_mode and $f000)=$4000)then
+   begin
+     errno:=sys_enotdir;
+     exit
+   end;
+{ Open it}
+  fd:=sys_open(dirname,O_RDONLY,438);
+  if fd<0 then
+   Begin
+    Errno:=-1;
+    exit;
+   End;
+  new(ptr);
+  if ptr=nil then
+   Begin
+    Errno:=1;
+    exit;
+   End;
+  Getmem(ptr^.dd_buf,2*DIRBLKSIZ);
+  if ptr^.dd_buf=nil then
+   exit;
+  ptr^.dd_fd:=fd;
+  ptr^.dd_loc:=-1;
+  ptr^.dd_rewind:=longint(ptr^.dd_buf);
+  ptr^.dd_size:=0;
+//  ptr^.dd_max:=sizeof(ptr^.dd_buf^);
+  sys_opendir:=ptr;
+end;
+
+function sys_closedir(dirp : pdir): cint; [public, alias : 'FPC_SYSC_CLOSEDIR'];
+
+begin
+  sys_closedir:=sys_close(dirp^.dd_fd);
+  Freemem(dirp^.dd_buf);
+  dispose(dirp);
+end;
+
+function sys_readdir(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?}
+
+function readbuffer:longint;
+
+var retval :longint;
+
+begin
+ Retval:=do_syscall(syscall_nr_getdents,longint(dirp^.dd_fd),longint(@dirp^.dd_buf^),DIRBLKSIZ {sizeof(getdentsbuffer)});
+   dirp^.dd_rewind:=longint(dirp^.dd_buf);
+   if retval=0 then
+    begin
+     dirp^.dd_rewind:=0;
+     dirp^.dd_loc:=0;
+    end
+   else
+    dirP^.dd_loc:=retval;
+ readbuffer:=retval;
+end;
+
+var
+    FinalEntry     : pdirent;
+    novalid        : boolean;
+    Reclen	   : Longint;
+    CurEntry	   : PDirent;
+
+begin
+ if (dirp^.dd_buf=nil) or (dirp^.dd_loc=0) THEN
+  exit(nil);
+ if (dirp^.dd_loc=-1)   OR     {First readdir on this pdir. Initial fill of buffer}
+   (dirp^.dd_rewind>=(longint(dirp^.dd_buf)+dirblksiz)) then  {no more entries left?}
+  Begin
+    if readbuffer=0 then        {succesful read?}
+     Exit(NIL);			{No more data}
+  End;
+ FinalEntry:=NIL;
+ CurEntry:=nil;
+ repeat
+  novalid:=false;
+  CurEntry:=pdirent(dirp^.dd_rewind);
+  RecLen:=CurEntry^.d_reclen;
+  if RecLen<>0 Then
+   begin {valid direntry?}
+    if CurEntry^.d_fileno<>0 then
+     FinalEntry:=CurEntry;
+    inc(dirp^.dd_rewind,Reclen);
+   end
+  else
+   begin {block entirely searched or reclen=0}
+    Novalid:=True;
+    if dirp^.dd_loc<>0 THEN             {blocks left?}
+     if readbuffer()<>0 then        {succesful read?}
+      novalid:=false;
+   end;
+ until (FinalEntry<>nil) or novalid;
+ If novalid then
+  FinalEntry:=nil;
+ Sys_ReadDir:=FinalEntry;
+end;
+{$endif}
+
+{*****************************************************************************
+        --- Process:Process & program handling - related calls ---
+*****************************************************************************}
+
+procedure sys_exit(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 sys_sigaction(sig: cint; var act : sigactionrec; var oact : sigactionrec): 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,longint(sig),longint(@act),longint(@oact));
+end;
+
+(*=================== MOVED from sysunix.inc ========================*)
+
+function sys_ftruncate(fd : cint; flength : off_t): cint; [public, alias : 'FPC_SYSC_FTRUNCATE'];
+{ See notes lseek. This one is completely similar.
+
+}
+begin
+ Do_syscall(syscall_nr___syscall,syscall_nr_ftruncate,0,fd,0,lo(flength),hi(flength));
+end;
+
+function sys_fstat(fd : cint; var sb : stat): cint;  [public, alias : 'FPC_SYSC_FSTAT'];
+
+begin
+  Sys_FStat:=do_SysCall(syscall_nr_fstat,fd,longint(@sb));
+end;
+
+{$ifdef NewReaddir} 
+{$I readdir.inc}
+{$endif}
+
+function sys_fork : 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
+ sys_fork:=Do_syscall(SysCall_nr_fork);
+End;
+
+{
+function sys_execve(const path : pathstr; const argv : ppchar; const 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,longint(@path[1]),longint(Argv),longint(envp));
+End;
+}
+
+function sys_execve(const path : pchar; const argv : ppchar; const 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,longint(path),longint(Argv),longint(envp));
+End;
+
+function sys_waitpid(pid : pid_t; var stat_loc : cint; 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
+ sys_WaitPID:=do_syscall(syscall_nr_WaitPID,PID,longint(Stat_loc),options,0);
+end;
+
+function sys_access(const 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
+ sys_Access:=do_syscall(syscall_nr_access,longint(pathname),amode);
+end;
+{
+function sys_access(const 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, longint(@pathname[1]),mode)=0;
+end;
+}
+
+function sys_Dup(oldd:cint):cint; [public, alias : 'FPC_SYSC_DUP'];
+{
+  Copies the filedescriptor oldfile to newfile
+}
+
+begin
+  sys_dup:=Do_syscall(syscall_nr_dup,oldd);
+end;
+
+function sys_Dup2(oldd:cint;newd:cint):cint; [public, alias : 'FPC_SYSC_DUP2'];
+{
+  Copies the filedescriptor oldfile to newfile
+}
+
+begin
+ sys_dup2:=do_syscall(syscall_nr_dup2,oldd,newd);
+end;
+
+CONST
+ { Constansts for MMAP }
+  MAP_PRIVATE   =2;
+  MAP_ANONYMOUS =$1000;
+
+
+Function Sys_mmap(adr,len,prot,flags,fdes,off:longint):longint;  [public, alias : 'FPC_SYSC_MMAP'];
+begin
+  Sys_mmap:=do_syscall(syscall_nr_mmap,Adr,Len,Prot,Flags,fdes,off,0);
+end;
+
+Function sbrk(size : longint) : Longint;
+begin
+  sbrk:=Sys_mmap(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.
+}
+Function Sys_IOCtl(Handle,Ndx: Longint;Data: Pointer):LongInt;  [public, alias : 'FPC_SYSC_IOCTL'];
+// This was missing here, instead hardcoded in Do_IsDevice
+begin
+  Sys_IOCtl:=do_SysCall(syscall_nr_ioctl,handle,Ndx,longint(data));
+end;
+
+CONST
+  IOCtl_TCGETS=$5401;
+
+Function Do_IsDevice(Handle:Longint):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:=(sys_ioctl(handle,IOCTL_TCGETS,@data)<>-1);
+end;
+
+
+
+{$endif}
+
+{
+ $Log$
+ Revision 1.1  2002-08-19 12:29:11  marco
+  * First working POSIX *BSD system unit.
+
+
+ Revision 1.2  2002/08/04 04:29:34  marco
+  * More POSIX updates. Small changes to lseek and ftruncate in osposix.inc
+    Initial versions of the type includefiles
+
+ Revision 1.1  2002/08/03 19:34:19  marco
+  * Initial *BSD versions. Seems that OpenBSD doesn't need much change,
+     NetBSD may need some fixes to stat record and ftruncate and lseek.
+     It is all close together, and it should be doable to have just one copy
+     of these for *BSD.
+
+ Revision 1.1.2.5  2001/12/09 03:31:50  carl
+ + wifsignaled() added
+
+ Revision 1.1.2.4  2001/12/03 03:13:30  carl
+ * fix ftruncate prototype
+ * fix rename prototype
+ * change readdir / closedir prototype
+
+ Revision 1.1.2.3  2001/11/30 03:50:43  carl
+ + int -> cint
+ + missing prototypes added
+
+ Revision 1.1.2.2  2001/11/28 03:08:29  carl
+ * int -> cint
+ + several other stuff renamed
+
+ Revision 1.1.2.1  2001/08/15 00:15:04  carl
+ - renamed
+
+}

+ 49 - 0
rtl/bsd/bsdtypes.inc

@@ -0,0 +1,49 @@
+{
+    $Id$
+    Copyright (c) 2000-2002 by Marco van de Voort
+    
+    Some non POSIX BSD types used internally in the system unit.
+
+    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.
+
+ ****************************************************************************
+}
+
+Type
+  timeval  = packed record
+    sec,usec:clong;
+  end;
+  ptimeval = ^timeval;
+  TTimeVal = timeval;
+
+  timespec = packed record
+    tv_sec   : time_t;
+    tv_nsec  : clong;
+  end;
+
+  timezone = packed record
+    minuteswest,
+    dsttime  : cint;
+  end;
+  ptimezone =^timezone;
+  TTimeZone = timezone;
+
+{
+ $Log$
+ Revision 1.1  2002-08-19 12:29:11  marco
+  * First working POSIX *BSD system unit.
+
+
+}

+ 9 - 9
rtl/bsd/i386/syscall.inc

@@ -41,7 +41,7 @@ procedure actualsyscall; assembler; {inline requires a dummy push IIRC}
          mov $-1,%eax
          mov $-1,%eax
    end;
    end;
 
 
-function Do_SysCall(sysnr:LONGINT):longint; assembler;
+function Do_SysCall(sysnr:LONGINT):longint; assembler; [public,alias:'FPC_DOSYS0'];
 
 
 asm
 asm
   movl  sysnr,%eax
   movl  sysnr,%eax
@@ -53,7 +53,7 @@ asm
 {$endif}
 {$endif}
 end;
 end;
 
 
-function Do_SysCall(sysnr,param1:longint):longint; assembler;
+function Do_SysCall(sysnr,param1:longint):longint; assembler;[public,alias:'FPC_DOSYS1'];
 
 
  asm
  asm
   movl  sysnr,%eax
   movl  sysnr,%eax
@@ -67,7 +67,7 @@ function Do_SysCall(sysnr,param1:longint):longint; assembler;
 {$endif}
 {$endif}
  end;
  end;
 
 
-function Do_SysCall(sysnr,param1:integer):longint; assembler;
+function Do_SysCall(sysnr,param1:integer):longint; assembler;[public,alias:'FPC_DOSYS1w'];
 
 
  asm
  asm
   movl  sysnr,%eax
   movl  sysnr,%eax
@@ -81,7 +81,7 @@ function Do_SysCall(sysnr,param1:integer):longint; assembler;
 {$endif}
 {$endif}
  end;
  end;
 
 
-function Do_SysCall(sysnr,param1,param2:LONGINT):longint; assembler;
+function Do_SysCall(sysnr,param1,param2:LONGINT):longint; assembler; [public,alias:'FPC_DOSYS2'];
 
 
  asm
  asm
    movl  sysnr,%eax
    movl  sysnr,%eax
@@ -96,7 +96,7 @@ function Do_SysCall(sysnr,param1,param2:LONGINT):longint; assembler;
 {$endif}
 {$endif}
  end;
  end;
 
 
-function Do_SysCall(sysnr,param1,param2,param3:LONGINT):longint; assembler;
+function Do_SysCall(sysnr,param1,param2,param3:LONGINT):longint; assembler;[public,alias:'FPC_DOSYS3'];
 
 
  asm
  asm
    movl  sysnr,%eax
    movl  sysnr,%eax
@@ -112,7 +112,7 @@ function Do_SysCall(sysnr,param1,param2,param3:LONGINT):longint; assembler;
 {$endif}
 {$endif}
 end;
 end;
 
 
-function Do_SysCall(sysnr,param1,param2,param3,param4:LONGINT):longint; assembler;
+function Do_SysCall(sysnr,param1,param2,param3,param4:LONGINT):longint; assembler;[public,alias:'FPC_DOSYS4'];
 
 
 asm
 asm
    movl  sysnr,%eax
    movl  sysnr,%eax
@@ -130,7 +130,7 @@ asm
 end;
 end;
 
 
 
 
-function Do_SysCall(sysnr,param1,param2,param3,param4,param5:LONGINT):longint;  assembler;
+function Do_SysCall(sysnr,param1,param2,param3,param4,param5:LONGINT):longint;  assembler;[public,alias:'FPC_DOSYS5'];
 
 
  asm
  asm
    movl  sysnr,%eax
    movl  sysnr,%eax
@@ -148,7 +148,7 @@ function Do_SysCall(sysnr,param1,param2,param3,param4,param5:LONGINT):longint;
 {$endif}
 {$endif}
 end;
 end;
 
 
-function Do_SysCall(sysnr,param1,param2,param3,param4,param5,param6:LONGINT):longint;  assembler;
+function Do_SysCall(sysnr,param1,param2,param3,param4,param5,param6:LONGINT):longint;  assembler;[public,alias:'FPC_DOSYS6'];
 
 
 asm
 asm
    movl  sysnr,%eax
    movl  sysnr,%eax
@@ -167,7 +167,7 @@ asm
 {$endif}
 {$endif}
 end;
 end;
 
 
-function Do_SysCall(sysnr,param1,param2,param3,param4,param5,param6,param7:LONGINT):longint;  assembler;
+function Do_SysCall(sysnr,param1,param2,param3,param4,param5,param6,param7:LONGINT):longint;  assembler; [public,alias:'FPC_DOSYS7'];
 
 
 asm
 asm
    movl  sysnr,%eax
    movl  sysnr,%eax

+ 38 - 484
rtl/bsd/osposix.inc

@@ -1,8 +1,13 @@
 {
 {
     $Id$
     $Id$
-    Copyright (c) 2001 by Carl Eric Codere
+    Copyright (c) 2002 by Marco van de Voort.
 
 
-    Implements roughly POSIX 1003.1 conforming interface for *BSD
+    Declarations to import basic syscalls declarations into other base
+    units.
+
+    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.
 
 
     This program is free software; you can redistribute it and/or modify
     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
     it under the terms of the GNU General Public License as published by
@@ -21,6 +26,9 @@
  ****************************************************************************
  ****************************************************************************
 }
 }
 
 
+{$I bsdstruct.inc}
+{$I bsdmacro.inc}
+
 {$ifdef uselibc}
 {$ifdef uselibc}
   {$Linklib c}
   {$Linklib c}
 
 
@@ -51,13 +59,10 @@
     function sys_execve(const path : pchar; const argv : ppchar; const envp: ppchar): cint; cdecl; external name 'execve';
     function sys_execve(const path : pchar; const argv : ppchar; const envp: ppchar): cint; cdecl; external name 'execve';
     function sys_waitpid(pid : pid_t; var stat_loc : cint; options: cint): pid_t; cdecl; external name 'waitpid';
     function sys_waitpid(pid : pid_t; var stat_loc : cint; options: cint): pid_t; cdecl; external name 'waitpid';
     function sys_access(const pathname : pchar; amode : cint): cint; cdecl; external name 'access';
     function sys_access(const pathname : pchar; amode : cint): cint; cdecl; external name 'access';
-
-//    function sys_uname(var name: utsname): cint; cdecl; external name 'uname';
-
+//  function sys_uname(var name: utsname): cint; cdecl; external name 'uname';
     function sys_Dup(oldd:cint):cint; cdecl; external name 'dup';
     function sys_Dup(oldd:cint):cint; cdecl; external name 'dup';
     function sys_Dup2(oldd:cint;newd:cint):cint; cdecl; external name 'dup2';
     function sys_Dup2(oldd:cint;newd:cint):cint; cdecl; external name 'dup2';
 
 
-
 {$else}
 {$else}
 
 
 {*****************************************************************************
 {*****************************************************************************
@@ -67,490 +72,39 @@
 { The system designed for Linux can't be used for FreeBSD so easily, since
 { The system designed for Linux can't be used for FreeBSD so easily, since
   FreeBSD pushes arguments, instead of loading them to registers.}
   FreeBSD pushes arguments, instead of loading them to registers.}
 
 
-Var ErrNo : Longint;
-
-{$I syscall.inc}
-{$I sysnr2.inc}
-
-// Should be moved to a FreeBSD specific unit in the future.
-
-Type
-  timeval  = packed record
-    sec,usec:clong;
-  end;
-  ptimeval = ^timeval;
-  TTimeVal = timeval;
-
-  timespec = packed record
-    tv_sec   : time_t;
-    tv_nsec  : clong;
-  end;
-
-  timezone = packed record
-    minuteswest,
-    dsttime  : cint;
-  end;
-  ptimezone =^timezone;
-  TTimeZone = timezone;
-
-function sys_time(var tloc:time_t): time_t; 
-
-VAR tv     : timeval;
-    tz     : timezone;
-    retval : longint;
-
-begin
-  Retval:=do_syscall(syscall_nr_gettimeofday,longint(@tv),longint(@tz));
-  If retval=-1 then
-   sys_time:=-1
-  else
-   Begin
-//    If Assigned(tloc) Then
-     TLoc:=tv.sec;
-    sys_time:=tv.sec;
-   End;
-End;
-
-{*****************************************************************************
-               --- File:File handling related calls ---
-*****************************************************************************}
-
-function sys_open(const path: pchar; flags : cint; mode: mode_t):cint; 
-
-Begin
- sys_open:=do_syscall(syscall_nr_open,longint(path),longint(flags),longint(mode));
-End;
-
-function sys_close(fd : cint): cint; 
-
-begin
- sys_close:=do_syscall(syscall_nr_close,fd);
-end;
-
-function sys_lseek(fd : cint; offset : off_t; whence : cint): off_t;
-{
-this one is special for the return value being 64-bit..
-hi/lo offset not yet tested.
-
-NetBSD: ok, but implicit return value in edx:eax
-FreeBSD: same implementation as NetBSD.
-}
-
-begin
-  {ugly implicit returnvalue}
-  do_syscall(syscall_nr___syscall,syscall_nr_lseek,0,longint(fd),0,lo(Offset),{0} hi(offset),Whence);
-end;
-
-function sys_read(fd: cint; buf: pchar; nbytes : size_t): ssize_t;
-
-begin
-  sys_read:=do_syscall(syscall_nr_read,Fd,longint(buf),nbytes);
-end;
-
-function sys_write(fd: cint;const buf:pchar; nbytes : size_t): ssize_t; 
-
-begin
- sys_write:=do_syscall(syscall_nr_write,Fd,longint(buf),nbytes);
-end;
-
-function sys_unlink(const path: pchar): cint;
-
-begin
-  sys_unlink:=do_syscall(syscall_nr_unlink,longint(path));
-end;
-
-function sys_rename(const old : pchar; const newpath: pchar): cint; 
-
-begin
-  sys_rename:=do_syscall(syscall_nr_rename,longint(old),longint(newpath));
-end;
-
-function sys_stat(const path: pchar; var buf : stat):cint;
-
-begin
- sys_stat:=do_syscall(syscall_nr_stat,longint(path),longint(@buf));
-end;
-
-
-{*****************************************************************************
-               --- Directory:Directory related calls ---
-*****************************************************************************}
-
-function sys_chdir(const path : pchar): cint;
-
-begin
- sys_chdir:=do_syscall(syscall_nr_chdir,longint(path));
-end;
-
-function sys_mkdir(const path : pchar; mode: mode_t):cint; 
-
-begin {Mode is 16-bit on F-BSD}
-  sys_mkdir:=do_syscall(syscall_nr_mkdir,longint(path),mode);
-end;
-
-function sys_rmdir(const path : pchar): cint; 
-
-begin
- sys_rmdir:=do_syscall(syscall_nr_rmdir,longint(path));
-end;
-
-{$ifndef NewReaddir}
-
-const DIRBLKSIZ=1024;
-
- 
-function sys_opendir(const dirname : pchar): pdir; 
-
-var
-  fd:longint;
-  st:stat;
-  ptr:pdir;
-begin
-  sys_opendir:=nil;
-  if sys_stat(dirname,st)<0 then
-   exit;
-{ Is it a dir ? }
-  if not((st.st_mode and $f000)=$4000)then
-   begin
-     errno:=sys_enotdir;
-     exit
-   end;
-{ Open it}
-  fd:=sys_open(dirname,O_RDONLY,438);
-  if fd<0 then
-   Begin
-    Errno:=-1;
-    exit;
-   End;
-  new(ptr);
-  if ptr=nil then
-   Begin
-    Errno:=1;
-    exit;
-   End;
-  Getmem(ptr^.dd_buf,2*DIRBLKSIZ);
-  if ptr^.dd_buf=nil then
-   exit;
-  ptr^.dd_fd:=fd;
-  ptr^.dd_loc:=-1;
-  ptr^.dd_rewind:=longint(ptr^.dd_buf);
-  ptr^.dd_size:=0;
-//  ptr^.dd_max:=sizeof(ptr^.dd_buf^);
-  sys_opendir:=ptr;
-end;
-
-function sys_closedir(dirp : pdir): cint;
-
-begin
-  sys_closedir:=sys_close(dirp^.dd_fd);
-  Freemem(dirp^.dd_buf);
-  dispose(dirp);
-end;
-
-function sys_readdir(dirp : pdir) : pdirent;
-
-{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?}
-
-function readbuffer:longint;
-
-var retval :longint;
-
-begin
- Retval:=do_syscall(syscall_nr_getdents,longint(dirp^.dd_fd),longint(@dirp^.dd_buf^),DIRBLKSIZ {sizeof(getdentsbuffer)});
-   dirp^.dd_rewind:=longint(dirp^.dd_buf);
-   if retval=0 then
-    begin
-     dirp^.dd_rewind:=0;
-     dirp^.dd_loc:=0;
-    end
-   else
-    dirP^.dd_loc:=retval;
- readbuffer:=retval;
-end;
-
-var
-    FinalEntry     : pdirent;
-    novalid        : boolean;
-    Reclen	   : Longint;
-    CurEntry	   : PDirent;
-
-begin
- if (dirp^.dd_buf=nil) or (dirp^.dd_loc=0) THEN
-  exit(nil);
- if (dirp^.dd_loc=-1)   OR     {First readdir on this pdir. Initial fill of buffer}
-   (dirp^.dd_rewind>=(longint(dirp^.dd_buf)+dirblksiz)) then  {no more entries left?}
-  Begin
-    if readbuffer=0 then        {succesful read?}
-     Exit(NIL);			{No more data}
-  End;
- FinalEntry:=NIL;
- CurEntry:=nil;
- repeat
-  novalid:=false;
-  CurEntry:=pdirent(dirp^.dd_rewind);
-  RecLen:=CurEntry^.d_reclen;
-  if RecLen<>0 Then
-   begin {valid direntry?}
-    if CurEntry^.d_fileno<>0 then
-     FinalEntry:=CurEntry;
-    inc(dirp^.dd_rewind,Reclen);
-   end
-  else
-   begin {block entirely searched or reclen=0}
-    Novalid:=True;
-    if dirp^.dd_loc<>0 THEN             {blocks left?}
-     if readbuffer()<>0 then        {succesful read?}
-      novalid:=false;
-   end;
- until (FinalEntry<>nil) or novalid;
- If novalid then
-  FinalEntry:=nil;
- Sys_ReadDir:=FinalEntry;
-end;
+function sys_time(var tloc:time_t): time_t; external name 'FPC_SYSC_TIME';
+function sys_open(const path: pchar; flags : cint; mode: mode_t):cint;  external name 'FPC_SYSC_OPEN';
+function sys_close(fd : cint): cint;  external name 'FPC_SYSC_CLOSE';
+function sys_lseek(fd : cint; offset : off_t; whence : cint): off_t; external name 'FPC_SYSC_LSEEK';
+function sys_read(fd: cint; buf: pchar; nbytes : size_t): ssize_t; external name 'FPC_SYSC_READ';
+function sys_write(fd: cint;const buf:pchar; nbytes : size_t): ssize_t;  external name 'FPC_SYSC_WRITE';
+function sys_unlink(const path: pchar): cint;  external name 'FPC_SYSC_UNLINK';
+function sys_rename(const old : pchar; const newpath: pchar): cint;  external name 'FPC_SYSC_RENAME';
+function sys_stat(const path: pchar; var buf : stat):cint;  external name 'FPC_SYSC_STAT';
+function sys_chdir(const path : pchar): cint; external name 'FPC_SYSC_CHDIR';
+function sys_mkdir(const path : pchar; mode: mode_t):cint; external name 'FPC_SYSC_MKDIR';
+function sys_rmdir(const path : pchar): cint; external name 'FPC_SYSC_RMDIR';
+function sys_opendir(const dirname : pchar): pdir; external name 'FPC_SYSC_OPENDIR';
+function sys_closedir(dirp : pdir): cint; external name 'FPC_SYSC_CLOSEDIR';
+function sys_readdir(dirp : pdir) : pdirent; external name 'FPC_SYSC_READDIR';
+procedure sys_exit(status : cint); external name 'FPC_SYSC_EXIT';
+function sys_sigaction(sig: cint; var act : sigactionrec; var oact : sigactionrec): cint;  external name 'FPC_SYSC_SIGACTION';
+function sys_ftruncate(fd : cint; flength : off_t): cint; external name 'FPC_SYSC_FTRUNCATE';
+function sys_fstat(fd : cint; var sb : stat): cint; external name 'FPC_SYSC_FSTAT'; 
+function sys_fork : pid_t; external name 'FPC_SYSC_FORK';
+function sys_execve(const path : pchar; const argv : ppchar; const envp: ppchar): cint; external name 'FPC_SYSC_EXECVE';
+function sys_waitpid(pid : pid_t; var stat_loc : cint; options: cint): pid_t; external name 'FPC_SYSC_WAITPID';
+function sys_access(const pathname : pchar; amode : cint): cint;external name 'FPC_SYSC_ACCESS'; 
+function sys_Dup(oldd:cint):cint;  external name 'FPC_SYSC_DUP';
+function sys_Dup2(oldd:cint;newd:cint):cint; external name 'FPC_SYSC_DUP2';
 {$endif}
 {$endif}
 
 
-{*****************************************************************************
-        --- Process:Process & program handling - related calls ---
-*****************************************************************************}
-
-procedure sys_exit(status : cint);
-
-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 sys_sigaction(sig: cint; var act : sigactionrec; var oact : sigactionrec): cint; 
-
-{
-  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,longint(sig),longint(@act),longint(@oact));
-end;
-
-(*=================== MOVED from sysunix.inc ========================*)
-
-function sys_ftruncate(fd : cint; flength : off_t): cint; 
-{ See notes lseek. This one is completely similar.
-
-}
-begin
- Do_syscall(syscall_nr___syscall,syscall_nr_ftruncate,0,fd,0,lo(flength),hi(flength));
-end;
-
-function sys_fstat(fd : cint; var sb : stat): cint; 
-
-begin
-  Sys_FStat:=do_SysCall(syscall_nr_fstat,fd,longint(@sb));
-end;
-
-{$ifdef NewReaddir} 
-{$I readdir.inc}
-{$endif}
-
-function sys_fork : pid_t; 
-{
-  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
- sys_fork:=Do_syscall(SysCall_nr_fork);
-End;
-
-{
-function sys_execve(const path : pathstr; const argv : ppchar; const 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,longint(@path[1]),longint(Argv),longint(envp));
-End;
-}
-
-function sys_execve(const path : pchar; const argv : ppchar; const 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
-  do_syscall(syscall_nr_Execve,longint(path),longint(Argv),longint(envp));
-End;
-
-function sys_waitpid(pid : pid_t; var stat_loc : cint; options: 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
- sys_WaitPID:=do_syscall(syscall_nr_WaitPID,PID,longint(Stat_loc),options,0);
-end;
-
-function sys_access(const pathname : pchar; 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
- sys_Access:=do_syscall(syscall_nr_access,longint(pathname),amode);
-end;
-{
-function sys_access(const 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, longint(@pathname[1]),mode)=0;
-end;
-}
-
-function sys_Dup(oldd:cint):cint; 
-{
-  Copies the filedescriptor oldfile to newfile
-}
-
-begin
-  sys_dup:=Do_syscall(syscall_nr_dup,oldd);
-end;
-
-function sys_Dup2(oldd:cint;newd:cint):cint;
-{
-  Copies the filedescriptor oldfile to newfile
-}
-
-begin
- sys_dup2:=do_syscall(syscall_nr_dup2,oldd,newd);
-end;
-
-{$endif}
-
-function S_ISDIR(m : mode_t): boolean;
-      
-begin
- S_ISDIR:=((m and %001111000000000000) = %100000000000000);
-end;
-
-function S_ISCHR(m : mode_t): boolean;
-begin
- S_ISCHR:=((m and %001111000000000000) = %10000000000000);
-end;
-
-function S_ISBLK(m : mode_t): boolean;
-begin
- S_ISBLK:=((m and %001111000000000000) = %110000000000000);
-end;
-    
-function S_ISREG(m : mode_t): boolean;
-begin
- S_ISREG:=((m and %001111000000000000) = %1000000000000000);
-end;
-
-function S_ISFIFO(m : mode_t): boolean;
-begin
-  S_ISFIFO:=((m and %001111000000000000) = %1000000000000);
-end;
-
-    function wifexited(status : cint): cint;
-      begin
-       wifexited:=cint((status AND %1111111) =0);
-      end;
-
-    function wexitstatus(status : cint): cint;
-     begin
-       wexitstatus:=(status and %1111111) shl 8;  	
-     end;
-
-    function wstopsig(status : cint): cint;
-     begin
-       wstopsig:=(status and %1111111) shl 8;  	
-     end;
-
-    function wifsignaled(status : cint): cint;
-     begin
-       wifsignaled:=cint(((status and %1111111)<>%1111111) and ((status and %1111111)<>0));
-     end;
-
 
 
 {
 {
  $Log$
  $Log$
- Revision 1.2  2002-08-04 04:29:34  marco
-  * More POSIX updates. Small changes to lseek and ftruncate in osposix.inc
-    Initial versions of the type includefiles
-
- Revision 1.1  2002/08/03 19:34:19  marco
-  * Initial *BSD versions. Seems that OpenBSD doesn't need much change,
-     NetBSD may need some fixes to stat record and ftruncate and lseek.
-     It is all close together, and it should be doable to have just one copy
-     of these for *BSD.
-
- Revision 1.1.2.5  2001/12/09 03:31:50  carl
- + wifsignaled() added
-
- Revision 1.1.2.4  2001/12/03 03:13:30  carl
- * fix ftruncate prototype
- * fix rename prototype
- * change readdir / closedir prototype
-
- Revision 1.1.2.3  2001/11/30 03:50:43  carl
- + int -> cint
- + missing prototypes added
+ Revision 1.3  2002-08-19 12:29:11  marco
+  * First working POSIX *BSD system unit.
 
 
- Revision 1.1.2.2  2001/11/28 03:08:29  carl
- * int -> cint
- + several other stuff renamed
 
 
- Revision 1.1.2.1  2001/08/15 00:15:04  carl
- - renamed
 
 
 }
 }

+ 5 - 2
rtl/bsd/osposixh.inc

@@ -135,11 +135,14 @@ CONST
     {                               SIGNALS                                   }
     {                               SIGNALS                                   }
     {*************************************************************************}
     {*************************************************************************}
     
     
-    {$i signal2.inc}
+{$i signal.inc}
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.1  2002-08-03 19:34:19  marco
+  Revision 1.2  2002-08-19 12:29:11  marco
+   * First working POSIX *BSD system unit.
+
+  Revision 1.1  2002/08/03 19:34:19  marco
    * Initial *BSD versions. Seems that OpenBSD doesn't need much change,
    * Initial *BSD versions. Seems that OpenBSD doesn't need much change,
       NetBSD may need some fixes to stat record and ftruncate and lseek.
       NetBSD may need some fixes to stat record and ftruncate and lseek.
       It is all close together, and it should be doable to have just one copy
       It is all close together, and it should be doable to have just one copy

+ 18 - 0
rtl/bsd/readme.txt

@@ -0,0 +1,18 @@
+
+Common *BSD files:
+
+bsdmacro.inc		The POSIX IS_DIR etc macro's.
+bsdsysc.inc		The base syscalls for *BSD system unit.
+			  including a few that are _not_ posix, but still
+			  req'ed in the system unit.
+bsdtypes.inc		some non POSIX BSD types required for the
+			syscalls
+bsduname.inc		The Uname implementation. Requires unit sysctl
+osposix.inc		The implementation of unit posix, redirects to libc
+			 or bsdtypes.inc (via aliases)
+osposixh.inc		The headers of unit posix.
+sysctl.pp		Some basic sysctl headers.
+sysposix.inc		BSD specific part of the implementation
+i386/syscall.inc	The primitives for performing syscalls
+i386/syscallh.inc	Headers to syscall.inc
+

+ 1 - 0
rtl/bsd/sysbsd.pp

@@ -0,0 +1 @@
+{$i system.pp}

+ 7 - 8
rtl/bsd/sysctl.pp

@@ -81,18 +81,14 @@ function sys_sysctlnametomib (Name: pchar; mibp:plongint;sizep:psize_t):cint;
 
 
 Implementation
 Implementation
 
 
-{$ifdef VER1_0}
-Uses Linux;	// yuck, I know.
-{$else}
-Uses Unix;  {Syscall functions}
-{$endif}
-
 {temporarily}
 {temporarily}
-
 {$ifdef FreeBSD}
 {$ifdef FreeBSD}
 CONST  syscall_nr___sysctl                    = 202;
 CONST  syscall_nr___sysctl                    = 202;
 {$endif}
 {$endif}
 
 
+{$I sysnr.inc}
+{$I syscallh.inc}
+
 function sys_sysctl (Name: pchar; namelen:cuint; oldp:pointer;oldlenp:psize_t; newp:pointer;newlen:size_t):cint;
 function sys_sysctl (Name: pchar; namelen:cuint; oldp:pointer;oldlenp:psize_t; newp:pointer;newlen:size_t):cint;
 
 
 Begin
 Begin
@@ -142,7 +138,10 @@ end.
 
 
 { 
 { 
   $Log$
   $Log$
-  Revision 1.1  2002-08-08 11:39:30  marco
+  Revision 1.2  2002-08-19 12:29:11  marco
+   * First working POSIX *BSD system unit.
+
+  Revision 1.1  2002/08/08 11:39:30  marco
    * Initial versions, to allow support for uname in posix.pp
    * Initial versions, to allow support for uname in posix.pp
 
 
 
 

+ 198 - 0
rtl/bsd/system.pp

@@ -0,0 +1,198 @@
+{
+    $Id$
+    This file is part of the Free Pascal run time librar~y.
+    Copyright (c) 2000 by Marco van de Voort
+    member of the Free Pascal development team.
+
+    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.
+
+ **********************************************************************}
+
+{ These things are set in the makefile, }
+{ But you can override them here.}
+
+{ If you use an aout system, set the conditional AOUT}
+{ $Define AOUT}
+
+Unit {$ifdef VER1_0}SysBSD{$else}System{$endif};
+Interface
+
+{$I sysunixh.inc}
+
+Implementation
+
+Var Errno : longint;
+
+function geterrno:longint; [public, alias: 'FPC_SYS_GETERRNO'];
+
+begin
+ GetErrno:=Errno;
+end;
+
+{ OS independant parts}
+
+{$I system.inc}
+{ OS dependant parts  }
+
+{$I errno.inc}
+{$I osposixh.inc}
+{$I bsdsysc.inc} 
+{$I sysposix.inc}
+{$I text.inc}      
+{$I heap.inc}
+
+
+
+{*****************************************************************************
+                           UnTyped File Handling
+*****************************************************************************}
+
+
+{$i file.inc}
+
+{*****************************************************************************
+                           Typed File Handling
+*****************************************************************************}
+
+{$i typefile.inc}
+
+
+
+Begin
+  IsConsole := TRUE;
+  IsLibrary := FALSE;
+  StackBottom := Sptr - StackLength;
+{ 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-08-19 12:29:11  marco
+   * First working POSIX *BSD system unit.
+
+  Revision 1.1  2000/10/15 08:19:48  peter
+    * system unit rename for 1.1 branch
+
+  Revision 1.2  2000/09/18 13:42:35  marco
+   * FreeBSD support into 1.1
+
+  Revision 1.1.2.1  2000/09/16 11:19:08  marco
+   * Moved files from BSD to FreeBSD directory, with some small changes
+
+  Revision 1.1.2.4  2000/09/16 11:10:43  marco
+   * Introduced using sysunix and sysunixh
+
+  Revision 1.1.2.3  2000/09/10 16:12:40  marco
+  The rearrangement to linux for
+
+  Revision 1.1.2.2  2000/08/05 18:33:29  peter
+    * paramstr(0) fix for linux 2.0 kernels
+
+  Revision 1.1.2.1  2000/07/14 07:33:15  michael
+  + Fixed do_open call. Directory checking must not be performed
+
+  Revision 1.1  2000/07/13 06:30:54  michael
+  + Initial import
+
+  Revision 1.49  2000/07/08 18:02:39  peter
+    * do_open checks for directory, if directory then ioerror 2
+
+  Revision 1.48  2000/06/30 22:14:03  peter
+    * removed obsolete crtlib code
+    * support EINTR for read/write to restart the syscall
+
+  Revision 1.47  2000/05/11 17:55:13  peter
+    * changed order of fpustate checking to first check the more
+      specific states
+
+  Revision 1.46  2000/05/08 14:27:36  peter
+    * released newsignal
+    * newsignal gives now better backtraces using the sigcontext eip/ebp
+      fields
+
+  Revision 1.45  2000/04/16 16:07:58  marco
+   * BSD fixes
+
+  Revision 1.44  2000/04/14 13:04:53  marco
+   * Merged bsd/syslinux.pp and 1.43 linux/syslinux.pp to this file with ifdefs
+
+  Revision 1.43  2000/04/07 14:56:36  peter
+    * switch to direct asm if not correctfldcw defined
+
+  Revision 1.42  2000/03/31 23:26:32  pierre
+   * FPU needs reset for all SIGFPE even from integer division by zero
+
+  Revision 1.41  2000/03/31 23:21:19  pierre
+    * multiple exception handling works
+      (for linux only if syslinux is compiled with -dnewsignal)
+
+  Revision 1.40  2000/03/31 13:24:28  jonas
+    * signal handling using sigaction when compiled with -dnewsignal
+      (allows multiple signals to be received in one run)
+
+  Revision 1.39  2000/03/25 12:28:37  peter
+    * patch for getdir from Pierre
+
+  Revision 1.38  2000/03/23 15:24:18  peter
+    * remove handle check for do_close
+
+  Revision 1.37  2000/02/09 16:59:32  peter
+    * truncated log
+
+  Revision 1.36  2000/02/09 12:17:51  peter
+    * moved halt to system.inc
+    * syslinux doesn't use direct asm anymore
+
+  Revision 1.35  2000/02/08 11:47:09  peter
+    * paramstr(0) support
+
+  Revision 1.34  2000/01/20 23:38:02  peter
+    * support fm_inout as stdoutput for assign(f,'');rewrite(f,1); becuase
+      rewrite opens always with filemode 2
+
+  Revision 1.33  2000/01/16 22:25:38  peter
+    * check handle for file closing
+
+  Revision 1.32  2000/01/07 16:41:41  daniel
+    * copyright 2000
+
+  Revision 1.31  2000/01/07 16:32:28  daniel
+    * copyright 2000 added
+
+  Revision 1.30  1999/12/01 22:57:31  peter
+    * cmdline support
+
+  Revision 1.29  1999/11/06 14:39:12  peter
+    * truncated log
+
+  Revision 1.28  1999/10/28 09:50:06  peter
+    * use mmap instead of brk
+
+  Revision 1.27  1999/09/10 15:40:35  peter
+    * fixed do_open flags to be > $100, becuase filemode can be upto 255
+
+  Revision 1.26  1999/09/08 16:14:43  peter
+    * pointer fixes
+
+  Revision 1.25  1999/07/28 23:18:36  peter
+    * closedir fixes, which now disposes the pdir itself
+
+}