Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Set os.name system property I noticed that scala.util.Properties.isMac didn't work because the "os.name" system property wasn't set. I added this functionality for OSX and Linux, but not windows because I don't know what it's supposed to run. I only set the version for Linux because uname can't reliably used to get the os.version string. I add support for that in a subsequent commit, but it requires adding objective c support to the toolchain, which I imagine may be contentious. Bonus: move up initializing of streams so that println may be used in loadProperties * Remove unused private method in java.io.File This was left behind in 40dd654. * Move platform specific code into platform.c We want to move away from having portable code implemented with runtime branching, so I moved the setting of the os.name (and version on linux) into platform.c. I also added the java.io.tmpdir system property on all platforms. The semantics are different than the jvm on osx (which uses a user specific path that can only be accessed using objective c apis in the foundation framework). Instead of the user specific temp directory, it just uses /tmp, which is probably fine for most applications. It also isn't possible to precisely determine the os version on osx without shelling out to the `sw_vers` command or using different objective c apis from the foundation framework. For now, we'll just leave the os version blank on osx (and windows -- there are different issues with getting this to work correctly on windows and right now there seem to be very few windows users of scala native).
- Loading branch information
Showing
8 changed files
with
132 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <sys/utsname.h> | ||
#include <string.h> | ||
|
||
#define NAMELEN 256 | ||
struct scalanative_utsname { | ||
char sysname[NAMELEN]; | ||
char nodename[NAMELEN]; | ||
char release[NAMELEN]; | ||
char version[NAMELEN]; | ||
char machine[NAMELEN]; | ||
}; | ||
#undef NAMELEN | ||
#define SET_FIELD(x, y) \ | ||
do { \ | ||
int len = strlen(y); \ | ||
memcpy(x, y, len); \ | ||
} while (0); | ||
|
||
int scalanative_uname(struct scalanative_utsname *scalanative_utsname) { | ||
struct utsname utsname; | ||
int res = uname(&utsname); | ||
if (res == 0) { | ||
SET_FIELD(&scalanative_utsname->sysname, utsname.sysname) | ||
SET_FIELD(&scalanative_utsname->nodename, utsname.nodename) | ||
SET_FIELD(&scalanative_utsname->release, utsname.release) | ||
SET_FIELD(&scalanative_utsname->version, utsname.version) | ||
SET_FIELD(&scalanative_utsname->machine, utsname.machine) | ||
} | ||
return res; | ||
} |
21 changes: 21 additions & 0 deletions
21
nativelib/src/main/scala/scala/scalanative/posix/sys/utsname.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package scala.scalanative.posix.sys | ||
|
||
import scala.scalanative.native._ | ||
|
||
@extern | ||
object utsname { | ||
type _256 = Nat.Digit[Nat._2, Nat.Digit[Nat._5, Nat._6]] | ||
private type str = CArray[Byte, _256] | ||
type utsname = CStruct5[str, str, str, str, str] | ||
@extern def uname(utsname: Ptr[utsname]): CInt = extern | ||
} | ||
|
||
object uname { | ||
implicit class utsnameOps(val c: Ptr[utsname.utsname]) { | ||
def sysname = fromCString(c._1.cast[Ptr[CChar]]) | ||
def nodename = fromCString(c._2.cast[Ptr[CChar]]) | ||
def release = fromCString(c._3.cast[Ptr[CChar]]) | ||
def version = fromCString(c._4.cast[Ptr[CChar]]) | ||
def machine = fromCString(c._5.cast[Ptr[CChar]]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters