1. platform() and FREEBSD
- Posted by jeremy (admin) Apr 10, 2009
- 1029 views
In 3.x platform() returned 3 for both Linux and FreeBSD, however, there are major differences between the two platforms. In almost all cases in 4.x it's better to use ifdef, but some places still use platform(). In those cases, platform now returns 8 for FreeBSD. It use to return 3. The constant FREEBSD has been updated to reflect this change, so checks such as:
if platform() = FREEBSD then
will still work. However, checks like this:
if platform() = LINUX then -- We are on UNIX end if
will no longer work (even prior to this change, since we have added OSX, OpenBSD, NetBSD and SunOS). To check if your application is running on UNIX, use this:
ifdef UNIX then
or, the old method, which is not guaranteed to work in the future:
if platform() >= LINUX then
The reason it may not work in the future is because FREEBSD is now defined as 8. It's possible that we may add on a new operating system, say OS2 (for some silly reason), then OS2 would be 9 which is not UNIX.
Jeremy
2. Re: platform() and FREEBSD
- Posted by ChrisB (moderator) Apr 10, 2009
- 1008 views
Hi
Is LINUX still a reserved constant?
Is not Linux a subset of Unix?
Is not FreeBSD a subset of Unix?
(quote from the freebsd faq
1.1. What is FreeBSD?
Briefly, FreeBSD is a UNIX® like operating system for AMD64 and Intel® EM64T, i386â„¢ PC-98, IA-64, ARM®, PowerPC® and UltraSPARC® platforms based on U.C. Berkeley's “4.4BSD-Lite†release, with some “4.4BSD-Lite2†enhancements. It is also based indirectly on William Jolitz's port of U.C. Berkeley's “Net/2†to the i386, known as “386BSDâ€, though very little of the 386BSD code remains. A fuller description of what FreeBSD is and how it can work for you may be found on the FreeBSD home page.
)
In which case should not both Linux and FreeBSD return UNIX as true? Therefore should not LINUX, FREBSD, OSX WIN32 etc etc all be maintained for future compatability, each returning there own value, and each maintained by the programmer, and not the interpreter?
Admittedly UNIX could be returned if any of the UNIX like operating systems were detected, but they should also then return LINUX or FREBSD etc.
If you remove LINUX as a definition, then this will break cross compatible programs.
Chris
3. Re: platform() and FREEBSD
- Posted by jeremy (admin) Apr 10, 2009
- 951 views
No, Linux is still defined. Linux and FreeBSD are both decendents of Unix, however, two very different paths. Linux and FreeBSD are not at all the same and many decisions will be different per platform. I am not sure why platform() ever returned the same thing for the two.
Jeremy
4. Re: platform() and FREEBSD
- Posted by jimcbrown (admin) Apr 10, 2009
- 928 views
No, Linux is still defined. Linux and FreeBSD are both decendents of Unix, however, two very different paths. Linux and FreeBSD are not at all the same and many decisions will be different per platform. I am not sure why platform() ever returned the same thing for the two.
Jeremy
Originally it returned a separate value, however the two platforms (being both Unix) were similar enough that it was seen necessary to have platform() return the same value for both in order to avoid the equiv of a breaking change - the need to rewrite most of the established linux code base in the archives in order for them to run on both platforms.
Since 4.0 is full of breaking changes anyways, and platform() is obsoleted, none of the above applies anymore.
(Actually, out of all the unix platforms, I think OSX is the only one different enough to warrant a new platform() value. However, I also have better things to do than to spend time splitting hairs over a dead horse. With the ifdef system and uname() in std/os.e, new code should be able to avoid calling platform().)