Module Os.Name

OS names.

type id = string

The type for OS identifiers. Unless you create them yourself these strings are normalized: non-empty and lowercase ASCII.

type t =
  1. | Bsd of id
  2. | Darwin of id
  3. | Linux of id
  4. | Windows of id
  5. | Other of id

The type for OS names.

Names are sorted into families. The datum of each family has the concrete OS identifier.

Warning. Minor versions of the library may add new family enumerants or attach a family to an identifier previously classified as Other (moving between families should not happen, except to fix the odd bug). As such:

  • Pattern matching on Other "…" constants is not recommended. If you need to select such an identifier spattern match on id.
  • Unless you want your code to be informed by the introduction of a new family, end your pattern match with a catch all branch _ rather than Other _.
val get : ?id_like:bool -> unit -> t

get () is the name of the operating system running the process. If id_like is true returns a possible parent name instead (e.g. "debian" instead of "ubuntu"), defaults to false. This is determined, along with Os.Version.get as follows:

  • On POSIX environments it depends on the lowercased sysname field returned by uname(2):

    • "linux", the file /etc/os-release is consulted. The lowercased ID or first element of ID_LIKE if id_like is true determines id and Name.Linux id is returned. The field VERSION_ID is used to determine version. If the file can't be found id is sysname and version "unknown".
    • "freebsd", behaves like the Linux case but Bsd id is returned.
    • "darwin", the file /System/Library/CoreServices/SystemVersion.plist is consulted. The lowercased ProductName key determines id and Name.Darwin id is returned. The ProductVersion key determines version. If the file can't be found id is sysname and version "unknown".
    • "netbsd" and "openbsd" then Name.Bsd sysname is returned and version is "unknown".
    • Starts with "cygwin_nt", then Name.Windows "cygwin" and version is determined like windows (see below).
    • Otherwise it returns Other sysname and version is "unknown"
  • On Windows this returns Windows "windows" and version uses the the caml_win32_* variables of the OCaml runtime system to format a version number
  • Otherwise it uses Name.Other "unknown" and version is "unknown"
val id : t -> id

id n is the identifier of n.

val family : t -> t

family n is the family of n. On Other _ values this is the value itsef, not the unknown value. Note that you don't need to apply this function to test for family equality.

val of_string : ?family:t -> string -> t

of_string s dermines an OS from s normalized by ASCII lowercasing. Unrecognized OS identifiers end up as Other with the normalized s. Strings printed by pp are guaranteed to parse (with the family as the identifier).

Identifiers returned by Os.Name.get and classified into a proper family may be classified as Other _ by this function, as the contextual information provided by uname(2) is not available. However if family is provided, s is simply normalized and the family of family is used in the result.

Family constants

val bsd : t

bsd is Bsd "bsd".

val darwin : t

darwin is Darwin "darwin".

val linux : t

linux is Linux "linux".

val windows : t

windows is Windows "windows".

val unknown : t

unknown is Other "unknown".

Predicates and comparisons

Warning. The standard comparisons functions assert families. If you want the finer grain you can use String equalities on id.

val equal : t -> t -> bool

equal asserts equality by family. Other id values are each their own distinct family.

val compare : t -> t -> int

compare is a total order compatible with equal.

Formatting

val pp : t Fmt.t

pp formats families for inspection. The concrete identifier is not printed use pp_id for that.

val pp_id : t Fmt.t

pp_id ppf n formats the id of n.