Core library for opam 2.1
Module OpamStd . Sys


val tty_out : bool

true if stdout is bound to a terminal

val tty_in : bool

true if stdin is bound to a terminal

val terminal_columns : unit -> int

Queried lazily, but may change on SIGWINCH

val home : unit -> string

The user's home directory. Queried lazily

val etc : unit -> string

The /etc directory

val system : unit -> string

The system directory (Windows only)

type os =
| Darwin
| Linux
| FreeBSD
| OpenBSD
| NetBSD
| DragonFly
| Cygwin
| Win32
| Unix
| Other of string
val os : unit -> os

Queried lazily

val uname : string -> string option

The output of the command "uname", with the given argument. Memoised.

val executable_name : string -> string

Append .exe (only if missing) to executable filenames on Windows

type shell =
| SH_sh
| SH_bash
| SH_zsh
| SH_csh
| SH_fish

The different families of shells we know about

val guess_shell_compat : unit -> shell

Guess the shell compat-mode

val guess_dot_profile : shell -> string

Guess the location of .profile

val path_sep : char

The separator character used in the PATH variable (varies depending on OS)

val split_path_variable : ?clean:bool -> string -> string list

Splits a PATH-like variable separated with path_sep. More involved than it seems, because there may be quoting on Windows. By default, it returns the path cleaned (remove trailing, leading, contiguous delimiters). Optional argument clean permits to keep those empty strings.

val is_cygwin_variant : string -> [ `Native | `Cygwin | `CygLinked ]

For native Windows builds, returns `Cygwin if the command is a Cygwin- compiled executable, `CygLinked if the command links to a library which is itself Cygwin-compiled or `Native otherwise.

Note that this returns `Native on a Cygwin-build of opam!

Both cygcheck and an unqualified command will be resolved using the current PATH.

Exit handling

val at_exit : ( unit -> unit ) -> unit

Like Stdlib.at_exit but with the possibility to call manually (eg. before exec())

val exec_at_exit : unit -> unit

Calls the functions registered in at_exit. Unneeded if exiting normally

exception Exit of int

Indicates intention to exit the program with given exit code

exception Exec of string * string array * string array

Indicates intention to exec() the given command (parameters as per Unix.execvpe), after proper finalisations. It's the responsibility of the main function to catch this, call exec_at_exit, and Unix.execvpe.

Raises Exit i

type exit_reason = [
| `Success
| `False
| `Bad_arguments
| `Not_found
| `Aborted
| `Locked
| `No_solution
| `File_error
| `Package_operation_error
| `Sync_error
| `Configuration_error
| `Solver_failure
| `Internal_error
| `User_interrupt
val exit_codes : (exit_reason * int) list
val get_exit_code : exit_reason -> int
val exit_because : exit_reason -> 'a

Raises Exit, with the code associated to the exit reason