POSIX

An addition to Scala Native’s POSIX bindings. To use one of the POSIX bindings you must add the resolver and the dependency:

sbt
resolvers += Resolver.bintrayRepo("scala-native-bindgen", "maven")
libraryDependencies += "org.scala-native.bindgen" %%% "libposix" % "0.3.1"
Maven
<repositories>
  <repository>
    <id>maven</id>
    <url>http://dl.bintray.com/scala-native-bindgen/maven</url>
  </repository>
</repositories>

<dependencies>
  <dependency>
    <groupId>org.scala-native.bindgen</groupId>
    <artifactId>libposix_native0.3_2.11</artifactId>
    <version>0.3.1</version>
  </dependency>
</dependencies>
Gradle
repositories {
  maven {
    url "http://dl.bintray.com/scala-native-bindgen/maven"
  }
}

dependencies {
  compile group: 'org.scala-native.bindgen', name: 'libposix_native0.3_2.11', version: '0.3.1'
}

Binding objects are available under the package name `

Header Description
fnmatch.h Check if a file or path name matches a shell pattern
regex.h Regular expression library

Examples

Using fnmatch.h:

import scala.scalanative.native._
import org.scalanative.bindgen.bindings.posix.fnmatch._

assert(fnmatch(c"*.md", c"README.md", 0) == 0)
assert(fnmatch(c"*.[ch]", c"main.h", 0) == 0)
assert(fnmatch(c"*.[ch]", c"main.c", 0) == 0)
assert(fnmatch(c"*.md", c"README_md", 0) == defines.FNM_NOMATCH)
Full source at GitHub

Using regex.h:

import scala.scalanative.native._
import org.scalanative.bindgen.bindings.posix.regex._

val reg = stackalloc[regex_t]

val compResult =
  regcomp(reg, c"Scala \(J\(S\|VM\)\|Native\)", defines.REG_EXTENDED)
assert(compResult == 0)

assert(regexec(reg, c"Scala JVM", 0, null, 0) == 0)
assert(regexec(reg, c"Scala JS", 0, null, 0) == 0)
assert(regexec(reg, c"Scala Native", 0, null, 0) == 0)
assert(regexec(reg, c"Scala .NET", 0, null, 0) != 0)

regfree(reg)
Full source at GitHub