Which OS?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Which OS?

Thomas Zastrow
Hello,

how can I test - at runtime - under which OS (Linux, Windows and so on)
a FPC-program is running?

Greetings,

Tom


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Which OS?

Michael Van Canneyt


On Mon, 11 Jul 2005, Thomas Zastrow wrote:

> Hello,
>
> how can I test - at runtime - under which OS (Linux, Windows and so on) a
> FPC-program is running?

Try

Var
   ThisOS : String;

begin
   ThisOS := {$I %FPCTARGET%};



results in a string of the form i386-linux or i386-win32.

Michael.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Which OS?

Mailing-Listen
Am Monday, dem 11. Jul 2005 schrieb Michael Van Canneyt:

> >Hello,
> >
> >how can I test - at runtime - under which OS (Linux, Windows and so on) a
> >FPC-program is running?
>
> Try
>
> Var
>   ThisOS : String;
>
> begin
>   ThisOS := {$I %FPCTARGET%};
>
> results in a string of the form i386-linux or i386-win32.

But it is also just the platform the program is compiled for.
It doesn't work when you run with an ABI for a different system,
ie. you run a FreeBSD binary on NetBSD.

--
AKFoerster

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Which OS?

Michael Van Canneyt


On Mon, 11 Jul 2005, Andres K. Foerster wrote:

> Am Monday, dem 11. Jul 2005 schrieb Michael Van Canneyt:
>
>>> Hello,
>>>
>>> how can I test - at runtime - under which OS (Linux, Windows and so on) a
>>> FPC-program is running?
>>
>> Try
>>
>> Var
>>   ThisOS : String;
>>
>> begin
>>   ThisOS := {$I %FPCTARGET%};
>>
>> results in a string of the form i386-linux or i386-win32.
>
> But it is also just the platform the program is compiled for.
> It doesn't work when you run with an ABI for a different system,
> ie. you run a FreeBSD binary on NetBSD.

That shouldn't matter to the program. If I run a Windows binary on Linux
under wine, the binary will assume it is running on Windows. Similarly,
a linux binary running on BSD will assume it runs on Linux. It's up to
the emulator to be 'perfect'.

In other words, an emulator should not be detected, and the program can
be assumed to be running on the OS it was compiled for...

Michael.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

RE: Which OS?

Jeff Pohlmeyer
In reply to this post by Thomas Zastrow
> how can I test - at runtime - under which OS (Linux, Windows and so on)
> a FPC-program is running?

  {$IFDEF unix}
     http://www.freepascal.org/docs-html/rtl/baseunix/fpuname.html
  {$ELSE}
    {IFDEF WIN32}
      http://msdn.microsoft.com/library/en-us/sysinfo/base/getversionex.asp
    {$ENDIF}
  {$ENDIF}

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: RE: Which OS?

Tomas Hajny
On Tue, July 12, 2005 13:07, Jeff Pohlmeyer said:
>> how can I test - at runtime - under which OS (Linux, Windows and so on)
>> a FPC-program is running?
>
>   {$IFDEF unix}
>      http://www.freepascal.org/docs-html/rtl/baseunix/fpuname.html
>   {$ELSE}
>     {IFDEF WIN32}
>       http://msdn.microsoft.com/library/en-us/sysinfo/base/getversionex.asp

      {$ELSE WIN32}
        {$IFDEF OS2}
http://www.warpspeed.com.au/cgi-bin/inf2html.cmd?..\html\book\Toolkt40\CP1.INF+1372

 (or use Dos.DosVersion providing the same information)
           {$ELSE OS2}
             {$IFDEF GO32V2}
 int 21h/3000h & int 21h/3306h (not very reliable, but better than
nothing; the first one is provided in Dos.DosVersion)
             {$ELSE GO32V2}
               {$IFDEF NETWARE}
 Use Dos.DosVersion
               {$ENDIF NETWARE}
             {$ENDIF GO32V2}
        {$ENDIF OS2}

>     {$ENDIF}
>   {$ENDIF}


OK - I'm not sure if this is what the original author asked for, but this
is my extension for some more platforms.

Tomas


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal