Recent

Author Topic: Strange behavior from StringList on OpenBSD unix  (Read 644 times)

BSaidus

  • Hero Member
  • *****
  • Posts: 545
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Strange behavior from StringList on OpenBSD unix
« on: March 21, 2024, 11:03:04 pm »
Hello,
I have write a simple FPC/Laz CGI program, it consists of saving a hostname into /etc/myname & saving the domain part of the hostname in /etc/resolv.conf.
Here is the code
Code: Pascal  [Select][+][-]
  1. procedure llp_myname_resolv_conf(const Ahostname: String; const Adomain: String);
  2. {$ifdef UNIX}
  3. const
  4.   cResolv ='/etc/resolv.conf';
  5.   cMyname ='/etc/myname';
  6. begin
  7.   with TStringList.Create() do
  8.   begin
  9.     try
  10.       Clear();
  11.       Add( Trim( Ahostname ) );
  12.       SaveToFile(cMyname);
  13.  
  14.       Clear();
  15.       Add('search '+ Trim( Adomain ) );
  16.       Add('nameserver 127.0.0.1');
  17.       Add('lookup file bind');
  18.       SaveToFile(cResolv);
  19.  
  20.     finally
  21.       Free;
  22.     end;
  23.   end;
  24. {$else}
  25. begin
  26. {$endif}
  27. end;  
  28.  
  29.  

The strange thing is that for the /etc/myname, it convert the encoding from UTF-8 to UTF-8-BOM but for the /etc/resolv.conf it is OK.

I use TFPHttpClient to Post Form data.

I've deleted the /etc/myname & recreate on on the console to be sur that the encoding is correct (UTF8) but every time I resend data the problem raise again.

The big problem is the displaying on terminal is horrible.

See the screenshots















lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

paweld

  • Hero Member
  • *****
  • Posts: 1027
Re: Strange behavior from StringList on OpenBSD unix
« Reply #1 on: March 22, 2024, 07:43:12 am »
And have you tried forcing BOM off - something like this:
Code: Pascal  [Select][+][-]
  1. procedure llp_myname_resolv_conf(const Ahostname: String; const Adomain: String);
  2. {$ifdef UNIX}
  3. const
  4.   cResolv ='/etc/resolv.conf';
  5.   cMyname ='/etc/myname';
  6. begin
  7.   with TStringList.Create() do
  8.   begin
  9.     WriteBOM := False;
  10.     try
  11.       Clear();
  12.       Add( Trim( Ahostname ) );
  13.       SaveToFile(cMyname, Encoding.UTF8);
  14.  
  15.       Clear();
  16.       Add('search '+ Trim( Adomain ) );
  17.       Add('nameserver 127.0.0.1');
  18.       Add('lookup file bind');
  19.       SaveToFile(cResolv, Encoding.UTF8);
  20.  
  21.     finally
  22.       Free;
  23.     end;
  24.   end;
  25. {$else}
  26. begin
  27. {$endif}
  28. end;  
  29.  
Best regards / Pozdrawiam
paweld

BSaidus

  • Hero Member
  • *****
  • Posts: 545
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Re: Strange behavior from StringList on OpenBSD unix
« Reply #2 on: March 22, 2024, 09:15:35 am »
Thanks @paweld.
I'll try & feed back.
lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

 

TinyPortal © 2005-2018