program bdemo(output); {demonstrates binary file I/O in GNU Pascal,
using external C routines to help out}
label 9999;
const namelength=100;
type byte=integer(8);
bytefile=packed file of byte;
UNIXfilename=packed array[1..namelength] of char;
var fname:UNIXfilename;
bfile:bytefile;
k,l:integer;
argc:asmname '_p_argc' Integer;
#include "bdemo_ext.h"
procedure printstatus(n:integer);
var x:byte;
begin if testeof(bfile) then writeln('Byte ',n:1,' is EOF')
else begin
bread(bfile,x); writeln('Byte ',n:1,' is ',x:1);
end;
end;
begin if argc=1 then {no file name argument given on command line}
begin writeln('Creating test file btest');
fname:='btest ';
if not testwriteaccess(fname) then
begin writeln('I couldn''t create it!'); goto 9999;
end;
rewrite(bfile,fname);
for k:=-128 to 127 do write(bfile,k);
end
else if argv(1,fname) then
begin k:=1;
while fname[k]<>'