Hello,
can you please explain me how to use the stdin/stdout with gpc?
The compiler does not seem to know these.
I tried to declare some functions from libc, but it didn't work, too.
Here's my code:
----------------------
program passtrough;
function fopen(name:pChar; mode:integer):integer; asmname 'open';
function fclose(handle:integer):integer; asmname 'close';
function fread(handle:integer; VAR Buffer; length:integer):integer;
asmname 'read';
function fwrite(handle:integer; VAR Buffer; length:integer):integer;
asmname 'write';
CONST O_RDONLY = 00;
O_WRONLY = 01;
O_RDWR = 02;
O_CREAT = 0100;
O_EXCL = 0200;
O_NOCTTY = 0400;
O_TRUNC = 01000;
O_APPEND = 02000;
O_NONBLOCK = 04000;
O_NDELAY = O_NONBLOCK;
O_SYNC = 010000;
var fin,fout:integer;
buffer:array[1..1024] of byte;
bytesread:integer;
begin
fin := fopen('/dev/stdin',O_RDONLY);
fout:= fopen('/dev/stdout',O_WRONLY);
repeat
bytesread:=fread(fin,buffer,1024);
if bytesread=-1 then begin
writeln('read error'); Halt;
end;
if fwrite(fout,buffer,bytesread)=-1 then begin
writeln('write error'); Halt;
end;
until bytesread<>1024;
fclose(fin); fclose(fout);
end.
----------------------
It *does* work when stdin/stdout are connected to the terminal, but
when using pipes it seems not to work.
Any suggestions?
Bye
Andreas