[fpc-pascal]Crt unit, FreeBSD

Maarten Bekers elevator at wxs.nl
Sun Oct 28 16:01:44 CET 2001


hi,

Using the CRT unit of the FreeBSD port of FPC (1.1 compiler), I encountered
that programs take a very long time to startup when run over telnet.
This problem seems to be caused by TtyName() seemingly to loop endlessly.

Attached is a fix for this problem, but it might be just an fix for a
symptom and not the actual issue, anyways.

--snip--
function TTYName(Handle:Longint):string;
{
  Return the name of the current tty described by handle f.
  returns empty string in case of an error.
}
var
  mydev,
  myino     : longint;
  st        : stat;

  function mysearch(n:string): boolean;
  {searches recursively for the device in the directory given by n,
    returns true if found and sets the name of the device in ttyname}
  var dirstream : pdir;
      d         : pdirent;
      name      : string;
      st        : stat;
  begin
    dirstream:=opendir(n);
    if (linuxerror<>0) or (dirstream=nil) then
     exit;

    d:=Readdir(dirstream);
    while (d<>nil) do
     begin
       name:=n+'/'+strpas(@(d^.name));

       fstat(name,st);
       if linuxerror=0 then
        begin
          if ((st.mode and $E000)=$4000) and  { if it is a directory }
             (strpas(@(d^.name))<>'.') and    { but not ., .. and fd
subdirs }
             (strpas(@(d^.name))<>'..') and
             (strpas(@(d^.name))<>'') and
             (strpas(@(d^.name))<>'fd') then
           begin                      {we found a directory, search inside
it}
             if mysearch(name) then
              begin                 {the device is here}
                closedir(dirstream);  {then don't continue searching}
                mysearch:=true;
                exit;
              end;
           end
          else if (d^.ino=myino) and (st.dev=mydev) then
           begin
             closedir(dirstream);
             ttyname:=name;
             mysearch:=true;
             exit;
           end;
        end;
       d:=Readdir(dirstream);
     end;
    closedir(dirstream);
    mysearch:=false;
  end;
-cut-


The bug-form seems not to work,
Another thing i found is that i get a lot of error messages that typecasts
of a different size are not allowed, while the compiler runs in Delphi
compatibility mode.

groeten, Maarten.





More information about the fpc-pascal mailing list