Lazarus

Programming => General => Topic started by: QEnnay on July 12, 2020, 07:46:24 pm

Title: [SOLVED] Linux, GetUsername( I can't get it!
Post by: QEnnay on July 12, 2020, 07:46:24 pm
Mint 20.0, Lazarus 2.0.8

Hi,
Must be missing something here, but I need the User name or Home-Folder Path. I checked the "users.pas" and plenty of options, but they all seem to need the User-name to start with.

Code: Pascal  [Select][+][-]
  1.   GetUserName( UserName : String) : String;
  2.  

If I know the name to put in there, why would I need "GetUserName(" ?

Is there some way to get the current User-name with first knowing it and hard coding it in?
Title: Re: Linux, GetUsername( I can't get it!
Post by: JuhaManninen on July 12, 2020, 07:55:40 pm
Code: Pascal  [Select][+][-]
  1.   GetUserName( UserName : String) : String;
  2.  
Whare did you find that?
This should work :
Code: Pascal  [Select][+][-]
  1. UserName:=GetEnvironmentVariable('USER');
You need SysUtils in uses section then.
Title: Re: Linux, GetUsername( I can't get it!
Post by: rvk on July 12, 2020, 08:07:18 pm
Or
Code: Pascal  [Select][+][-]
  1. uses users,baseunix;
  2. begin
  3.   Writeln(GetUserName(fpgetuid));
  4. end.

The string parameter you are referring to is not the username but the user uid (which you can get with fpgetuid).

Not sure why the parameter name would be username which is confusing.
Title: Re: Linux, GetUsername( I can't get it!
Post by: JuhaManninen on July 12, 2020, 09:13:12 pm
Code: Pascal  [Select][+][-]
  1. uses users,baseunix;
  2. begin
  3.   Writeln(GetUserName(fpgetuid));
  4. end.
The string parameter you are referring to is not the username but the user uid (which you can get with fpgetuid).
Not sure why the parameter name would be username which is confusing.
Ok, I did not remember the GetUserName() function. Actually its signature is :
Code: Pascal  [Select][+][-]
  1. function GetUserName(UID : TUID) : String;
Parameter name UID is quite descriptive.

GetEnvironmentVariable('USER') has an advantage because it is cross-platform. IIRC it works on Windows, too. (is it so ?)
Title: Re: Linux, GetUsername( I can't get it!
Post by: rvk on July 12, 2020, 09:28:01 pm
GetEnvironmentVariable('USER') has an advantage because it is cross-platform. IIRC it works on Windows, too. (is it so ?)
On Windows it should be USERNAME so you would still need to do IFDEFs.

And the environment variables can be manipulated easily. I can make myself root  8)

So sometimes the api is preferred (although also not bulletproof).
Title: Re: Linux, GetUsername( I can't get it!
Post by: JuhaManninen on July 12, 2020, 09:53:18 pm
On Windows it should be USERNAME so you would still need to do IFDEFs.
Ok, I have not done much WinAPI programming.
However I found a function for Lazarus IDE's internal use, in unit ide/IDEProcs :
Code: Pascal  [Select][+][-]
  1. function GetCurrentUserName: string;
  2. begin
  3.   Result:=GetEnvironmentVariableUTF8('USER');
  4. end;
GetEnvironmentVariableUTF8 is just a wrapper for GetEnvironmentVariableWide (Windows) or GetEnvironmentVariable (other systems).
GetCurrentUserName is used for inserting your name in editor from menu : Source -> Insert General -> Current Username
Can you please test if it works on Windows. My guess is that recent Windows versions have 'USER' as an alternative env.variable. If not, then we have a bug and must add IFDEFs to the function.
Title: Re: Linux, GetUsername( I can't get it!
Post by: rvk on July 12, 2020, 10:18:19 pm
Can you please test if it works on Windows. My guess is that recent Windows versions have 'USER' as an alternative env.variable. If not, then we have a bug and must add IFDEFs to the function.
Nope, it's just USERNAME on Windows. Not USER.
Quote
C:\Users\Rik>echo %USERNAME%
Rik

C:\Users\Rik>echo %USER%
%USER%

C:\Users\Rik>set user
USERDOMAIN=XPS420
USERDOMAIN_ROAMINGPROFILE=XPS420
USERNAME=Rik
USERPROFILE=C:\Users\Rik

This:
Code: Pascal  [Select][+][-]
  1. uses lazutf8;
  2.  
  3. function GetCurrentUserName1: string;
  4. begin
  5.   Result := GetEnvironmentVariableUTF8('USER');
  6. end;
  7.  
  8. function GetCurrentUserName2: string;
  9. begin
  10.   Result := GetEnvironmentVariableUTF8('USERNAME');
  11. end;
  12.  
  13. procedure TForm1.Button1Click(Sender: TObject);
  14. begin
  15.   Memo1.Lines.Add('1 - ' + GetCurrentUserName1);
  16.   Memo1.Lines.Add('2 - ' + GetCurrentUserName2);
  17. end;
Results in
Quote
1 -
2 - Rik

So yes, the GetCurrentUserName in ideprocs.pp is really wrong.
But it isn't really used much in the IDE code anyway.
Title: Re: Linux, GetUsername( I can't get it!
Post by: JuhaManninen on July 12, 2020, 11:13:17 pm
Ok. I fixed it in r63547.
Now Source -> Insert General -> "Current Username" should work also on Windows.
Title: Re: Linux, GetUsername( I can't get it!
Post by: rvk on July 12, 2020, 11:38:16 pm
Ok. I fixed it in r63547.
Now Source -> Insert General -> "Current Username" should work also on Windows.
Fix confirmed on Windows.

There is also a GetCurrentMailAddress which uses GetCurrentUser in combination with HOSTNAME environment variable.
But there is no such thing on Windows 10 professional (there is a COMPUTERNAME though).

And from the other recent topic... there might also not be a HOSTNAME environment variable on Linux Debian either (there might be on other Linux versions). It's a bash/shell variable on Debian. https://forum.lazarus.freepascal.org/index.php/topic,50533.0.html

So on Windows and Linux Debian/Raspberry pi etc...
Quote
Source -> Insert General -> "ChangeLog Entry"
results in:
Quote
12-07-2020   Rik <Rik@>

Not very critical. I've never used those options anyway (and with me probably nobody on Windows and Debian  ;D ).
Title: Re: Linux, GetUsername( I can't get it!
Post by: JuhaManninen on July 13, 2020, 09:58:50 am
Ok. If there is a sensible way to fix it, I can apply a patch. However it sounds like COMPUTERNAME would not be very useful in GetCurrentMailAddress.
Title: Re: Linux, GetUsername( I can't get it!
Post by: rvk on July 13, 2020, 10:21:52 am
Ok. If there is a sensible way to fix it, I can apply a patch. However it sounds like COMPUTERNAME would not be very useful in GetCurrentMailAddress.
HOSTNAME (of a linux machine) is also not very sensible in a emailaddress.
On linux it's the local machinename which is not a mailserver to receive email at all.

The only place GetCurrentMailAddress is used, I think, is in that insert ChangeLog Entry.
So GetCurrentMailAddress is a wrongly named procedure anyway.

I can't comment on what's sensible because I wouldn't even know what that "insert ChangeLog Entry" is used for. If it needs the real email address then the function is flawed in linux too. If it needs username@computername it needs COMPUTERNAME for Windows and HOSTNAME for linux (with the notice that Debian doesn't have HOSTNAME in the env).
Title: Re: Linux, GetUsername( I can't get it!
Post by: JuhaManninen on July 13, 2020, 11:23:16 am
In r63552 I renamed the function as GetCurrentChangeLog and added COMPUTERNAME for Windows.
Not perfect but better than earlier.
I don't know the history of this function. It has been there forever.
Title: Re: Linux, GetUsername( I can't get it!
Post by: rvk on July 13, 2020, 12:48:20 pm
In r63552 I renamed the function as GetCurrentChangeLog and added COMPUTERNAME for Windows.
Fix confirmed on Windows
Code: [Select]
13-07-2020   Rik <Rik@XPS8500>
Title: Re: Linux, GetUsername( I can't get it!
Post by: JuhaManninen on July 13, 2020, 01:35:33 pm
Code: [Select]
13-07-2020   Rik <Rik@XPS8500>
Strange. In my Manjaro Linux the ChangeLog Entry gives :
Code: [Select]
13.07.2020   juha <juha@>It means HOSTNAME gives an empty string. However it works in console :
Code: [Select]
$ echo $HOSTNAME
juha-fp30
USER works as expected in both cases :
Code: [Select]
$ echo $USER
juha
Title: Re: Linux, GetUsername( I can't get it!
Post by: rvk on July 13, 2020, 01:42:28 pm
Code: [Select]
13-07-2020   Rik <Rik@XPS8500>
Strange. In my Manjaro Linux the ChangeLog Entry gives :
Code: [Select]
13.07.2020   juha <juha@>It means HOSTNAME gives an empty string. However it works in console :
Code: [Select]
$ echo $HOSTNAME
juha-fp30
USER works as expected in both cases :
Code: [Select]
$ echo $USER
juha
That was discussed in a recent topic.
https://forum.lazarus.freepascal.org/index.php/topic,50533.0.html

On some Linux/Unix systems, the HOSTNAME is NOT a environment variable, but a bash/shell variable. There is a difference.

If you do env | grep HOSTNAME you get nothing (because on Debian and apparently Manjaro there no environment variable HOSTNAME).
But if you do set | grep HOSTNAME you'll see the HOSTNAME. (set gives all the shell variables)
(and echo does both substitution for environment and shell variables)

Only way to reliably get the hostname is using the GetHostName from baseunix or unix unit.
Or pulling it out of /proc/sys/kernel/hostname pseudo-file.
Title: Re: Linux, GetUsername( I can't get it!
Post by: winni on July 13, 2020, 02:05:16 pm
Hi!

For Debian and all it's children:

They break the conventions that the hostname is in the environment.

So we have to nurse that baby.

Code: Bash  [Select][+][-]
  1. env HOSTNAME=MySweetRaspi

Now you can proceed like in every other Linux.

Winni
Title: Re: Linux, GetUsername( I can't get it!
Post by: rvk on July 13, 2020, 02:10:09 pm
Code: Bash  [Select][+][-]
  1. env HOSTNAME=MySweetRaspi
Now you can proceed like in every other Linux.
And that works with any user?

BTW, it doesn't work for me on a RPI.
You should probably need export to make it stick.
And if you want it to survive a reboot you'll even need to do more (set it in .profile).
And for what profile?
How do you set this systemwide???

Code: [Select]
root@sonarr:~# env HOSTNAME=MySweetRaspi
SHELL=/bin/bash
SUDO_GID=1000
SUDO_COMMAND=/bin/bash
SUDO_USER=pi
NO_AT_BRIDGE=1
PWD=/root
LOGNAME=root
HOME=/root
LANG=en_GB.UTF-8
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:
TERM=xterm
USER=root
SHLVL=1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
SUDO_UID=1000
MAIL=/var/mail/root
TEXTDOMAIN=Linux-PAM
_=/usr/bin/env
HOSTNAME=MySweetRaspi

root@sonarr:~# env | grep HOST
root@sonarr:~#

It's generally better to just use gethostname().

BTW. HOSTNAME is not a posix-compliance. So other UNIX system might also not have it. But some Linux systems do.
https://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html
Title: Re: Linux, GetUsername( I can't get it!
Post by: winni on July 13, 2020, 02:18:29 pm
Hi!

No - if you make changes in the environment then you should be of course

Code: Bash  [Select][+][-]
  1. root

Winni
Title: Re: Linux, GetUsername( I can't get it!
Post by: rvk on July 13, 2020, 02:24:09 pm
No - if you make changes in the environment then you should be of course
Code: Bash  [Select][+][-]
  1. root
Which is why it's better to use gethostname().

Manjaro is based on Arch Linux. So that's the second we've found.
I'm sure there are more where HOSTNAME isn't defined as environment variable.
Title: Re: Linux, GetUsername( I can't get it!
Post by: winni on July 13, 2020, 02:26:59 pm

Which is why it's better to use gethostname().

/quote]

I think it is better to have somehthing like a default Linux.

But as you like .....

Winni
Title: Re: Linux, GetUsername( I can't get it!
Post by: Warfley on July 13, 2020, 02:31:51 pm
Hi!

No - if you make changes in the environment then you should be of course

Code: Bash  [Select][+][-]
  1. root

Winni
So this is actually quite a problem, because not everyone has root access. One could go into his user profile and set there HOSTNAME=$(cat /proc/sys/kernel/hostname), but again thats just a hack.

For linux it is pretty simple, if something is not part of the kernel or the posix standard, you should probably not rely on it. Everything else is distro dependend.

The other option is to document it as a dependency and for example say: This program is only guaranteed to work on OpenSuse. Which of course means that most linux users won't be able to use it (fact is debian derivates are the most common distros) or "This program needs the HOSTNAME variable to be set" but this might alienate not so tech savy users.
Title: Re: Linux, GetUsername( I can't get it!
Post by: rvk on July 13, 2020, 02:32:05 pm
I think it is better to have somehthing like a default Linux.
But as you like .....
I would like that too.
But it's simply not the case.
And on UNIX systems (are they still used?) it's also not usually a env-variable.

Requiring users to set the HOSTNAME is a big ask.
If at all, it should be done by Lazarus itself automatically.
But if the requirement is root, the Lazarus IDE might not always run as root.

So... that's why IMHO the gethostname() is just the better choice at the moment.
Title: Re: Linux, GetUsername( I can't get it!
Post by: winni on July 13, 2020, 02:38:14 pm
Hi!

It is old habit since UNIX days that the hostname is initialized in a system startup script.

The reasons why Debian and Arch dont do that is a miracle.

Suse Linux and a lot of others posess the hostname inside the environment.

Winni
Title: Re: Linux, GetUsername( I can't get it!
Post by: Warfley on July 13, 2020, 02:41:06 pm
I think it is better to have somehthing like a default Linux.

But as you like .....

Winni

There is not such a thing, because Linux is only a kernel, you could probably replace the NT kernel with the Linux kernel in Windows and to the end user it would not be noticable (maybe in performance but who cares). And effectively make windows a Linux distro.
Every Linux distro is it's own OS, and assuming that an environment variable is set between Linux distros is like assuming the environment variables on Windows have the same name.

But there is the POSIX standard. While many Linux distros don't have their compliance certified (because that costs money), nearly all Linux distros are fully compatible with the POSIX standard.

So if you want to have something relyable, check out what is part of the POSIX standard and what not (it's mentioned in the man pages if this is part of any standard). Because this is something you can assume of nearly all linux distros (even though my windows example from above would not be POSIX compatible).
Bonus points: BSD and MacOS and other UNIX systems are also POSIX complient, meaning if you restrict yourself to the POSIX APIs, your program will automatically be cross plattform compatible.

Then there are APIs provided by the Linux Kernel, these are also available under every Linux system, but might change with kernel versions. This includes all the pseudo files located at /proc, which you can use for example to get the hardware spec, process list and so on
Title: Re: Linux, GetUsername( I can't get it!
Post by: JuhaManninen on July 13, 2020, 02:42:21 pm
That was discussed in a recent topic.
https://forum.lazarus.freepascal.org/index.php/topic,50533.0.html
Right! I saw that thread but didn't read it carefully.
IDEProcs already depends on Unix and BaseUnix, used heavily in function BackupFileForWrite. I will add more Unix specific code. This works for me :

Code: Pascal  [Select][+][-]
  1. function GetCurrentChangeLog: string;
  2. begin
  3.   Result:='<'+GetCurrentUserName+'@'+
  4.   {$IF defined(MSWindows) or defined(HASAMIGA)}
  5.     GetEnvironmentVariableUTF8('COMPUTERNAME')
  6.   {$ELSE}
  7.     GetHostname
  8.   {$ENDIF}
  9.     + '>';
  10. end;

Question about Amiga: does it need special treatment? Does it have 'COMPUTERNAME'?
Title: Re: Linux, GetUsername( I can't get it!
Post by: winni on July 13, 2020, 03:27:17 pm
@Warfley

Code: Pascal  [Select][+][-]
  1. uses BGRAbitmap, BGRAdefaultBitmap, BGRAbitmapTypes;
  2. ....
  3.  
  4. procedure Foam (dest: TBGRABitmap);
  5. var i: integer;
  6.     radius, x,y : single;
  7.     col, border: TBGRAPixel;
  8. begin
  9.   col := BGRA (255, 255,200,128);
  10.   border := BGRA(160,160,160,160);
  11.   dest.FillRect(0,0,dest.width,dest.height,BGRAPixelTransparent,dmset);
  12.    for i := 0 to 5000 do
  13.      begin
  14.       x := random (dest.width;
  15.       y := random (dest.height);
  16.       radius := random (4)+ random;
  17.       dest.EllipseAntialias(x,y,radius,radius,border,0.75,col);
  18.       end;
  19. end;
             

Winni
Title: Re: Linux, GetUsername( I can't get it!
Post by: QEnnay on July 13, 2020, 04:17:19 pm
Whare did you find that?

Code: Pascal  [Select][+][-]
  1. users.pas
  2.  
  3. unit users;
  4.  
  5. Interface
  6. {$mode delphi}
  7. uses UnixType,BaseUnix,pwd,grp, {$ifdef Linux} shadow,{$endif}SysUtils,Classes;
  8.  
  9. Type
  10.   EUserLookupError = Class(Exception);
  11.   EGroupLookupError = Class(Exception);
  12.   EShadowLookupError = Class(Exception);
  13.   TPasswordRecord = Tpasswd;
  14.   PPasswordRecord = ^TPasswordRecord;
  15.  
  16. { User functions }
  17. Function  getpwnam(Const UserName: String) : PPasswordRecord;
  18. Procedure GetUserData(Const UserName : String; Var Data : TPasswordRecord); overload;
  19. Procedure GetUserData(Uid : TUID; Var Data : TPasswordRecord); overload;
  20. function  GetUserName(UID : TUID) : String;
  21. function  GetUserId(Const UserName : String) : TUID;
  22. function  GetUserGid(Const UserName : String) : TGID;
  23. function  GetUserDir(Const UserName : String): String;
  24. function  GetUserDescription(Const UserName : String): String;
  25. Procedure GetUserList(List : Tstrings);overload;
  26. Procedure GetUserList(List : TStrings; WithIDs : Boolean);overload;
  27. [code]
Title: Re: Linux, GetUsername( I can't get it!
Post by: rvk on July 13, 2020, 04:22:23 pm
Whare did you find that?

Code: Pascal  [Select][+][-]
  1. users.pas
  2.  
  3. unit users;
  4.  
  5. Interface
  6. {$mode delphi}
  7. uses UnixType,BaseUnix,pwd,grp, {$ifdef Linux} shadow,{$endif}SysUtils,Classes;
  8.  
  9. Type
  10.   EUserLookupError = Class(Exception);
  11.   EGroupLookupError = Class(Exception);
  12.   EShadowLookupError = Class(Exception);
  13.   TPasswordRecord = Tpasswd;
  14.   PPasswordRecord = ^TPasswordRecord;
  15.  
  16. { User functions }
  17. Function  getpwnam(Const UserName: String) : PPasswordRecord;
  18. Procedure GetUserData(Const UserName : String; Var Data : TPasswordRecord); overload;
  19. Procedure GetUserData(Uid : TUID; Var Data : TPasswordRecord); overload;
  20. function  GetUserName(UID : TUID) : String;
  21. function  GetUserId(Const UserName : String) : TUID;
  22. function  GetUserGid(Const UserName : String) : TGID;
  23. function  GetUserDir(Const UserName : String): String;
  24. function  GetUserDescription(Const UserName : String): String;
  25. Procedure GetUserList(List : Tstrings);overload;
  26. Procedure GetUserList(List : TStrings; WithIDs : Boolean);overload;
  27. [code]
I don't see
  GetUserName( UserName : String) : String;
there like you stated.
I do see the UID parameter I mentioned.
Title: Re: Linux, GetUsername( I can't get it!
Post by: QEnnay on July 13, 2020, 04:37:06 pm
Code: Pascal  [Select][+][-]
  1.   Writeln(GetUserName(fpgetuid));
  2.  

Thanks, that works perfectly for me. I got it from "users.pas" after a search here. I could not find anything else that alluded to getting the User-Name with out first knowing it. Not even the Wiki.

With the discussion that has followed my first post, I am not sure if I should mark it SOLVED or not. :)
Title: Re: [SOLVED] Linux, GetUsername( I can't get it!
Post by: JuhaManninen on July 13, 2020, 04:55:36 pm
I applied the function GetCurrentChangeLog change in r63554. I guess the GetHostName stuff was little out of topic in this GetUserName thread.
If somebody knows about Amiga HostName, please tell me (PM, mail).
Title: Re: [SOLVED] Linux, GetUsername( I can't get it!
Post by: lucamar on July 13, 2020, 05:41:09 pm
If somebody knows about Amiga HostName, please tell me (PM, mail).

I don't know about more modern implementations but the classic AmigaOS (up to the default OS of the 4000, I think) knows nothing about hostnames (tested on a 1200 and a 2000*). For networked Amigas I guess (and I might be wrong here) that it depends on the particular nettwork soft used.


* And what a trip to the past has been setting up and on again those venerable granpas! :D
Title: Re: [SOLVED] Linux, GetUsername( I can't get it!
Post by: winni on July 13, 2020, 06:55:18 pm
Hi!

Just looked through the  Amiga command reference and have not found anything about a hostname.

With the network I go with lucamar:

Amiga had by default no network interface and so every vendor build his own stuff.

Winni

PS https://wiki.amigaos.net/wiki/AmigaOS_Manual:_AmigaDOS_Command_Reference (https://wiki.amigaos.net/wiki/AmigaOS_Manual:_AmigaDOS_Command_Reference)
Title: Re: [SOLVED] Linux, GetUsername( I can't get it!
Post by: QEnnay on July 13, 2020, 09:29:01 pm
* And what a trip to the past has been setting up and on again those venerable granpas! :D

You young whipper snappers: When I started programming there was no Borland and no Turbo anything. Tandy Model I with 4K of memory and cassette recorder for 300-BAUD data. Livin' the fast life.
Title: Re: [SOLVED] Linux, GetUsername( I can't get it!
Post by: lucamar on July 13, 2020, 09:54:47 pm
* And what a trip to the past has been setting up and on again those venerable granpas! :D

You young whipper snappers: When I started programming there was no Borland and no Turbo anything. Tandy Model I with 4K of memory and cassette recorder for 300-BAUD data. Livin' the fast life.

I started in the early 1980s with a Sinclair Spectrum 48k, a B/W TV set we "forgot" to trash, and reading/writing tapes with my father's Hi-Fi tower. Fun and excitement all around! Except the full summer I had to work to get money for the thing, of course ;)
Title: Re: [SOLVED] Linux, GetUsername( I can't get it!
Post by: trev on July 14, 2020, 02:20:14 am
I started in the early 1980s with a Sinclair Spectrum 48k, a B/W TV set we "forgot" to trash, and reading/writing tapes with my father's Hi-Fi tower.

Commodore VIC-20 with 3.5 KB of RAM, cassette recorder and 12" B&W TV -- I had to build my own RS232 interface to connect my dumb (ie non-HAYES) 300 baud modem. Later I built a  3 KB RAM expander with point to point wiring for the six static RAM chips using telephone wire on Vero board which took me two days of soldering). Those were the days ;)
Title: Re: [SOLVED] Linux, GetUsername( I can't get it!
Post by: TRon on July 14, 2020, 04:41:50 am
I applied the function GetCurrentChangeLog change in r63554. I guess the GetHostName stuff was little out of topic in this GetUserName thread.
If somebody knows about Amiga HostName, please tell me (PM, mail).
As already mentioned by others, Amiga did not had hardware to connect to a network by default.

As such the implementation of the network stack depended on the hardware vendor, although there were some standard/default stacks available.

AmiTCP, Miami and BSDSocket are just a few names in relation to that subject and which might be able to get you the hostname using an environment variable (when setup correctly) or can be obtained by a library function. MorphOS for instance can make use of yet another stack, while AROS (and Amiga's using AROS kickstart) attempts to provide BSDSocket by default.

The best solution to that imho would be to solve it just as ApplicationName (https://www.freepascal.org/docs-html/rtl/sysutils/applicationname.html) and VendorName (https://www.freepascal.org/docs-html/rtl/sysutils/vendorname.html) do it by providing a custom override for the enduser, such as OnGetApplicationName (https://www.freepascal.org/docs-html/rtl/sysutils/ongetapplicationname.html) and OnGetVendorName (https://www.freepascal.org/docs-html/rtl/sysutils/vendorname.html)

That way you are able to provide a default implementation (depending on the platform), but at same time let the implementation details over to the end-user in case end-user environment requires it.

Would that be an option ?

edit, just noticed the first question
Question about Amiga: does it need special treatment? Does it have 'COMPUTERNAME'?
It does when that specific environment variable is set  ;) (e.g., no it does not have that environment variable by default. I am not aware of any software that does supply this particular name).
Title: Re: [SOLVED] Linux, GetUsername( I can't get it!
Post by: TRon on July 14, 2020, 08:41:02 am
Hi winni,

PS https://wiki.amigaos.net/wiki/AmigaOS_Manual:_AmigaDOS_Command_Reference (https://wiki.amigaos.net/wiki/AmigaOS_Manual:_AmigaDOS_Command_Reference)

Be careful with what you refer to, as that page is related to AmigaOS4. There is somewhat of a resemblance but that is about it.

Currently there is officially no support for that platform as there is (again officially) no maintainer. Support is offered for AmigaOS3.x, AROS and MorphOS. The classic AmigaOS1.x and modern AmigaOS4.x targets are officially not supported and should therefore be considered unmaintained. Current maintainers do try to keep things going, but only to a certain level and when time permits.
Title: Re: [SOLVED] Linux, GetUsername( I can't get it!
Post by: PascalDragon on July 14, 2020, 09:13:38 am
Currently there is officially no support for that platform as there is (again officially) no maintainer. Support is offered for AmigaOS3.x, AROS and MorphOS. The classic AmigaOS1.x and modern AmigaOS4.x targets are officially not supported and should therefore be considered unmaintained. Current maintainers do try to keep things going, but only to a certain level and when time permits.

Well, AmigaOS1.x is not yet supported. Charlie is improving the RTL step by step to get it working there as well.

Also we do have an official AmigaOS4.x release (https://freepascal.org/down/powerpc/amigaos-hungary.html). It's just that the target is not getting as much love as the other Amiga-likes and the X5000 is not supported.
Title: Re: [SOLVED] Linux, GetUsername( I can't get it!
Post by: JuhaManninen on July 14, 2020, 09:32:34 am
The best solution to that imho would be to solve it just as ApplicationName (https://www.freepascal.org/docs-html/rtl/sysutils/applicationname.html) and VendorName (https://www.freepascal.org/docs-html/rtl/sysutils/vendorname.html) do it by providing a custom override for the enduser, such as OnGetApplicationName (https://www.freepascal.org/docs-html/rtl/sysutils/ongetapplicationname.html) and OnGetVendorName (https://www.freepascal.org/docs-html/rtl/sysutils/vendorname.html)

That way you are able to provide a default implementation (depending on the platform), but at same time let the implementation details over to the end-user in case end-user environment requires it.

Would that be an option ?
I believe it is a good idea but not in the scope of the Lazarus IDEProcs helper function. It should probably be part of FPC's libs.
The helper function in IDEProcs is used only for a non-critical log info inserted into source editor. The Amiga target may have bigger issues than that.
I have understood that Lazarus really runs on Amiga which I find amazing! I don't know how many people are testing it.
Title: Re: [SOLVED] Linux, GetUsername( I can't get it!
Post by: TRon on July 14, 2020, 09:33:34 am
Well, AmigaOS1.x is not yet supported. Charlie is improving the RTL step by step to get it working there as well.
Yes, I know  ;)

If I recall correctly then this is about what Charlie told me with regards to 1.x: "Currently this is one big hack which requires much improvements".

I interpreted that as a understatement. There are a lot of things missing from those old kickstarts and OS, which makes life a bit miserable in order to get everything on par with the other amiganoid targets. Some things are simply not even possible to realise. On the other hand, the original idea came from wanting to have FPC also be able to bang some bits around for classic hardware. In that it is already a success.

Quote
Also we do have an official AmigaOS4.x release (https://freepascal.org/down/powerpc/amigaos-hungary.html). It's just that the target is not getting as much love as the other Amiga-likes and the X5000 is not supported.
I am aware there is a release. Reason there is not much love is (mostly) that there seems to be no interest from that camp and the hardware you mention is ridiculously expensive. Both Marcus and Charlie expressed not wanting to partake in that, at least last time I spoke them. Neither do I have any interest other then what I already contribute.

But, you probably know that already  ;D
Title: Re: [SOLVED] Linux, GetUsername( I can't get it!
Post by: TRon on July 14, 2020, 09:38:48 am
I believe it is a good idea but not in the scope of the Lazarus IDEProcs helper function. It should probably be part of FPC's libs.
Ah ok. I was already a bit lost on where to find this function. Yes, I agree that should belong to FPC, not Laz.

Quote
I have understood that Lazarus really runs on Amiga which I find amazing! I don't know how many people are testing it.
I do hope no-one  ;)

At least on classic Lazarus is really too resource-hungry for that (it barely runs on a beefed up Amiga). I was able to barely run it on AROS. It is amazing to see it running on those targets though. But, for those interested: stick to FPC or cross-compilation. Using native MUI/Zune for GUI is preferred.
Title: Re: [SOLVED] Linux, GetUsername( I can't get it!
Post by: PascalDragon on July 14, 2020, 09:39:34 am
But, you probably know that already  ;D

Correct. ;)
TinyPortal © 2005-2018