2
0
Эх сурвалжийг харах

--- Merging r26189 into '.':
U rtl/linux/termiosproc.inc
--- Merging r26199 into '.':
U rtl/linux/linux.pp

# revisions: 26189,26199
r26189 | marco | 2013-12-06 16:00:55 +0100 (Fri, 06 Dec 2013) | 3 lines
Changed paths:
M /trunk/rtl/linux/termiosproc.inc

* Initial FPC_USE_LIBC implementation of termios for Linux.
* Removed VER2_0 defines.
r26199 | marco | 2013-12-08 21:23:09 +0100 (Sun, 08 Dec 2013) | 3 lines
Changed paths:
M /trunk/rtl/linux/linux.pp

* fix FPC_USE_LIBC for inotify and clock* functions, and always link librt when this unit is used under FPC_USE_LIBC.
make all building failed otherwise because fppkg seems to import unit linux somewhere.

git-svn-id: branches/fixes_2_6@26268 -

marco 11 жил өмнө
parent
commit
8c5a8b1889
2 өөрчлөгдсөн 131 нэмэгдсэн , 20 устгасан
  1. 15 9
      rtl/linux/linux.pp
  2. 116 11
      rtl/linux/termiosproc.inc

+ 15 - 9
rtl/linux/linux.pp

@@ -18,6 +18,9 @@
 unit Linux;
 
 {$packrecords c}
+{$ifdef FPC_USE_LIBC} 
+ {$linklib rt} // for clock* functions
+{$endif}
 
 interface
 
@@ -408,17 +411,19 @@ Type
                     or IN_OPEN or IN_MOVE or IN_CREATE or IN_DELETE 
                     or IN_DELETE_SELF or IN_MOVE_SELF;    
                     
+
+// these have _THROW in the header.
 { Create and initialize inotify instance.   }
-function inotify_init: cint;
+function inotify_init: cint;  {$ifdef FPC_USE_LIBC} cdecl; external name 'inotify_init'; {$ENDIF}
 { Create and initialize inotify instance.   }
-function inotify_init1(flags:cint):cint;
+function inotify_init1(flags:cint):cint;  {$ifdef FPC_USE_LIBC} cdecl; external name 'inotify_init1'; {$ENDIF}
 
 { Add watch of object NAME to inotify instance FD.  
   Notify about events specified by MASK.   }
-function inotify_add_watch(fd:cint; name:Pchar; mask:cuint32):cint;
+function inotify_add_watch(fd:cint; name:Pchar; mask:cuint32):cint;  {$ifdef FPC_USE_LIBC} cdecl; external name 'inotify_add_watch'; {$ENDIF}
 
 { Remove the watch specified by WD from the inotify instance FD.   }
-function inotify_rm_watch(fd:cint; wd: cint):cint;
+function inotify_rm_watch(fd:cint; wd: cint):cint;  {$ifdef FPC_USE_LIBC} cdecl; external name 'inotify_rm_watch'; {$ENDIF}
 
 { clock_gettime, clock_settime, clock_getres }
 
@@ -441,9 +446,10 @@ Const
 Type
   clockid_t = cint;
 
-function clock_getres(clk_id : clockid_t; res : ptimespec) : cint;
-function clock_gettime(clk_id : clockid_t; tp: ptimespec) : cint;
-function clock_settime(clk_id : clockid_t; tp : ptimespec) : cint;
+// FPC_USE_LIBC unchecked, just to get it compiling again.
+function clock_getres(clk_id : clockid_t; res : ptimespec) : cint; {$ifdef FPC_USE_LIBC} cdecl; external name 'clock_getres'; {$ENDIF}
+function clock_gettime(clk_id : clockid_t; tp: ptimespec) : cint;  {$ifdef FPC_USE_LIBC} cdecl; external name 'clock_gettime'; {$ENDIF}
+function clock_settime(clk_id : clockid_t; tp : ptimespec) : cint; {$ifdef FPC_USE_LIBC} cdecl; external name 'clock_settime'; {$ENDIF}
   
 implementation
 
@@ -669,7 +675,7 @@ begin
   FUTEX_OP := ((op and $F) shl 28) or ((cmp and $F) shl 24) or ((oparg and $FFF) shl 12) or (cmparg and $FFF);
 end;
 
-
+{$ifndef FPC_USE_LIBC}
 function inotify_init:cint;
 
 begin
@@ -711,5 +717,5 @@ function clock_settime(clk_id : clockid_t; tp : ptimespec) : cint;
 begin
   clock_settime:=do_SysCall(syscall_nr_clock_settime,tsysparam(clk_id),tsysparam(tp));
 end;
-
+{$endif}
 end.

+ 116 - 11
rtl/linux/termiosproc.inc

@@ -5,7 +5,9 @@
                          IOCtl and Termios calls
 ******************************************************************************}
 
-Function TCGetAttr(fd:cint;var tios:TermIOS):cint; {$ifdef VER2_0}inline;{$endif}
+{$ifndef FPC_USE_LIBC}
+
+Function TCGetAttr(fd:cint;var tios:TermIOS):cint; inline;
 begin
   TCGetAttr:=fpIOCtl(fd,TCGETS,@tios);
 end;
@@ -30,13 +32,13 @@ begin
 end;
 
 
-Procedure CFSetISpeed(var tios:TermIOS;speed:Cardinal); {$ifdef VER2_0}inline;{$endif}
+Procedure CFSetISpeed(var tios:TermIOS;speed:Cardinal); inline;
 begin
   tios.c_cflag:=(tios.c_cflag and (not CBAUD)) or speed;
 end;
 
 
-Procedure CFSetOSpeed(var tios:TermIOS;speed:Cardinal); {$ifdef VER2_0}inline;{$endif}
+Procedure CFSetOSpeed(var tios:TermIOS;speed:Cardinal); inline;
 begin
    CFSetISpeed(tios,speed);
 end;
@@ -58,35 +60,35 @@ begin
 end;
 
 
-Function TCSendBreak(fd,duration:cint):cint;  {$ifdef VER2_0}inline;{$endif}
+Function TCSendBreak(fd,duration:cint):cint;  inline;
 begin
   TCSendBreak:=fpIOCtl(fd,TCSBRK,pointer(ptrint(duration)));
 end;
 
 
-Function TCSetPGrp(fd,id:cint):cint;  {$ifdef VER2_0}inline;{$endif}
+Function TCSetPGrp(fd,id:cint):cint;  inline;
 begin
   TCSetPGrp:=fpIOCtl(fd,TIOCSPGRP,pointer(ptrint(id)));
 end;
 
 
-Function TCGetPGrp(fd:cint;var id:cint):cint;  {$ifdef VER2_0}inline;{$endif}
+Function TCGetPGrp(fd:cint;var id:cint):cint;  inline;
 begin
   TCGetPGrp:=fpIOCtl(fd,TIOCGPGRP,@id);
 end;
 
-Function TCDrain(fd:cint):cint;  {$ifdef VER2_0}inline;{$endif}
+Function TCDrain(fd:cint):cint;  inline;
 begin
   TCDrain:=fpIOCtl(fd,TCSBRK,pointer(1));
 end;
 
 
-Function TCFlow(fd,act:cint):cint; {$ifdef VER2_0}inline;{$endif}
+Function TCFlow(fd,act:cint):cint; inline;
 begin
    TCFlow:=fpIOCtl(fd,TCXONC,pointer(ptrint(act)));
 end;
 
-Function TCFlush(fd,qsel:cint):cint;  {$ifdef VER2_0}inline;{$endif}
+Function TCFlush(fd,qsel:cint):cint;  inline;
 begin
   TCFlush:=fpIOCtl(fd,TCFLSH,pointer(ptrint(qsel)));
 end;
@@ -104,8 +106,7 @@ begin
     IsAtty:=0;
 end;
 
-
-Function IsATTY(var f: text):cint;  {$ifdef VER2_0}inline;{$endif}
+Function IsATTY(var f: text):cint;  inline;
 {
   Idem as previous, only now for text variables.
 }
@@ -113,3 +114,107 @@ begin
   IsATTY:=IsaTTY(textrec(f).handle);
 end;
 
+{$else}
+// We plan to use FPC_USE_LIBC for Debian/kFreeBSD. This means that we need
+// to avoid IOCTLs, since those go to the kernel and need to be FreeBSD specific.
+// -> reroute as much as possible to libc.
+
+function real_tcsendbreak(fd,duration: cint): cint; cdecl; external name 'tcsendbreak';
+function real_tcdrain(fd: cint): cint; cdecl; external name 'tcdrain';
+function real_tcflow(fd,act:cint): cint; cdecl; external name 'tcflow';
+function real_tcflush(fd,qsel: cint): cint; cdecl; external name 'tcflush';
+Function real_TCSetAttr(fd:cint;OptAct:cint;constref tios:TermIOS):cint; cdecl; external name 'tcsetattr';
+Function real_TCGetAttr(fd:cint;var tios:TermIOS):cint; cdecl; external name 'tcgetattr';
+
+function real_tcgetpgrp(fd:cint):pid_t; cdecl; external name 'tcgetpgrp';
+function real_tcsetpgrp(fd: cint; pgrp: pid_t): cint; cdecl; external name 'tcsetpgrp';
+
+Function TCGetAttr(fd:cint;var tios:TermIOS):cint; inline;
+begin
+  TCGetAttr:=real_tcgetattr(fd,tios);
+end;
+
+Function TCSetAttr(fd:cint;OptAct:cint;const tios:TermIOS):cint;
+begin
+  TCSetAttr:=Real_TCSetAttr(fd,OptAct,tios);
+end;
+
+Procedure CFSetISpeed(var tios:TermIOS;speed:Cardinal); inline;
+begin
+  tios.c_cflag:=(tios.c_cflag and (not CBAUD)) or speed;
+end;
+
+
+Procedure CFSetOSpeed(var tios:TermIOS;speed:Cardinal); inline;
+begin
+   CFSetISpeed(tios,speed);
+end;
+
+{ checked against glibc 2.3.3 (FK) }
+Procedure CFMakeRaw(var tios:TermIOS);
+begin
+  with tios do
+   begin
+     c_iflag:=c_iflag and (not (IGNBRK or BRKINT or PARMRK or ISTRIP or
+                                INLCR or IGNCR or ICRNL or IXON));
+     c_oflag:=c_oflag and (not OPOST);
+     c_lflag:=c_lflag and (not (ECHO or ECHONL or ICANON or ISIG or IEXTEN));
+     c_cflag:=(c_cflag and (not (CSIZE or PARENB))) or CS8;
+     c_cc[VMIN]:=1;
+     c_cc[VTIME]:=0;
+   end;
+end;
+
+Function TCSendBreak(fd,duration:cint):cint;  inline;
+begin
+  TCSendBreak:=real_tcsendbreak(fd,duration);
+end;
+
+Function TCSetPGrp(fd,id:cint):cint;  inline;
+begin
+  TCSetPGrp:=real_tcsetpgrp(fd,id);;
+end;
+
+Function TCGetPGrp(fd:cint;var id:cint):cint;  inline;
+begin
+  id:=real_tcgetpgrp(fd);
+  tcgetpgrp:=id;  
+end;
+
+Function TCDrain(fd:cint):cint;  inline;
+begin
+  TCDrain:=real_TCDrain(fd);
+end;
+
+
+Function TCFlow(fd,act:cint):cint; inline;
+begin
+  TCFlow:=real_tcflow(fd,act);
+end;
+
+Function TCFlush(fd,qsel:cint):cint;  inline;
+begin
+  TCFlush:=real_tcflush(fd,qsel);
+end;
+
+Function IsATTY (Handle:cint):cint;
+{
+  Check if the filehandle described by 'handle' is a TTY (Terminal)
+}
+var
+  t : Termios;
+begin
+  if TCGetAttr(Handle,t)=0 then
+    IsAtty:=1
+  else
+    IsAtty:=0;
+end;
+
+Function IsATTY(var f: text):cint;  inline;
+{
+  Idem as previous, only now for text variables.
+}
+begin
+  IsATTY:=IsaTTY(textrec(f).handle);
+end;
+{$endif}