[fpc-pascal]Type question.

Marco van de Voort marcov at stack.nl
Wed Jul 25 10:11:20 CEST 2001


> G'day all,
> 
> I have implemented a native replacement for the linux shell chvt
> command, however, I don't like the way in which I pass the terminal 
> number paramater to the ioctl. I had to do some strange fudging to
> get this to work, as the last paramater of the ioctl routine in the
> linux unit must be a VOID_POINTER. 

Typical C notation. Long is guaranteed large enough to contain 
pointer.

> The ioctl in the kernel expects
> an unsigned_longint. This works, verified by both function and running
> an strace on the program. Is there a better way?

Probably this was done because Cardinal is newer as a type than pointer, and
because people pass pointers to it anyway ;-)

> Function ChVT(Terminal : Cardinal) : Boolean;
> Const
> 	VT_ACTIVATE = $5606;
> 	VT_WAITACTIVE= $5607;
> Var
> 	TTY : LongInt;
> 	test : Pointer;
> Begin
> TTY := fdOpen('/dev/tty',Open_RdWr);
> If TTY = 0 then Exit(False);
> Test := $0;
> Test := Test + Terminal;


> IOCTL(TTY,VT_ACTIVATE,Test);
> IOCTL(TTY,VT_WAITACTIVE,Test);

IOCtl(TTY,VT_Activate,Pointer(Test)); 






More information about the fpc-pascal mailing list