package core_unix

  1. Overview
  2. Docs
Unix-specific portions of Core

Install

Dune Dependency

Authors

Maintainers

Sources

v0.14.0.tar.gz
md5=f9a74834f239874286d84ec99d75e5fa
sha512=d020db759cde35c0e9d9919dee2c0ea5bb5b7a5ee75515be922d816f28eb9f74dba37e6e424a636e362eab5120b2c1e672f4e5ba798f2dac7974c0e135f80faf

doc/core_unix.filename_unix/Filename_unix/index.html

Module Filename_unixSource

include module type of struct include Core.Filename end
include module type of Core_kernel.Filename
type t = Core_kernel__.Import.string
include Bin_prot.Binable.S with type t := t
val bin_size_t : t Bin_prot.Size.sizer
val bin_write_t : t Bin_prot.Write.writer
val bin_read_t : t Bin_prot.Read.reader
val __bin_read_t__ : (int -> t) Bin_prot.Read.reader
val bin_shape_t : Bin_prot.Shape.t
val bin_writer_t : t Bin_prot.Type_class.writer
val bin_reader_t : t Bin_prot.Type_class.reader
val bin_t : t Bin_prot.Type_class.t
include Ppx_sexp_conv_lib.Sexpable.S with type t := t
val t_of_sexp : Sexplib0__.Sexp.t -> t
val sexp_of_t : t -> Sexplib0__.Sexp.t
include Base.Comparable.S with type t := t with type comparator_witness = Core_kernel__.String.comparator_witness
val (>=) : t -> t -> bool
val (<=) : t -> t -> bool
val (=) : t -> t -> bool
val (>) : t -> t -> bool
val (<) : t -> t -> bool
val (<>) : t -> t -> bool
val equal : t -> t -> bool
val min : t -> t -> t
val max : t -> t -> t
val ascending : t -> t -> int

ascending is identical to compare. descending x y = ascending y x. These are intended to be mnemonic when used like List.sort ~compare:ascending and List.sort ~cmp:descending, since they cause the list to be sorted in ascending or descending order, respectively.

val descending : t -> t -> int
val between : t -> low:t -> high:t -> bool

between t ~low ~high means low <= t <= high

val clamp_exn : t -> min:t -> max:t -> t

clamp_exn t ~min ~max returns t', the closest value to t such that between t' ~low:min ~high:max is true.

Raises if not (min <= max).

val clamp : t -> min:t -> max:t -> t Base__.Or_error.t
type comparator_witness = Core_kernel__.String.comparator_witness
val comparator : (t, comparator_witness) Base__.Comparator.comparator
val validate_lbound : min:t Base__.Maybe_bound.t -> t Base__.Validate.check
val validate_ubound : max:t Base__.Maybe_bound.t -> t Base__.Validate.check
val validate_bound : min:t Base__.Maybe_bound.t -> max:t Base__.Maybe_bound.t -> t Base__.Validate.check
module Replace_polymorphic_compare = Core.Filename.Replace_polymorphic_compare
module Map = Core.Filename.Map
module Set = Core.Filename.Set
val compare : t -> t -> Core_kernel__.Import.int
val hash_fold_t : Ppx_hash_lib.Std.Hash.state -> t -> Ppx_hash_lib.Std.Hash.state
val hash : t -> Ppx_hash_lib.Std.Hash.hash_value
val hashable : t Base.Hashable.t
module Table = Core.Filename.Table
module Hash_set = Core.Filename.Hash_set
module Hash_queue = Core.Filename.Hash_queue
val root : Core_kernel__.Import.string

The path of the root.

Pathname resolution

val is_posix_pathname_component : Core_kernel__.Import.string -> Core_kernel__.Import.bool

is_posix_pathname_component f

  • returns

    true if f is a valid path component on a POSIX compliant OS

Note that this checks a path component, and not a full path.

http://www.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap03.html#tag_03_169

val temp_dir_name : Core_kernel__.Import.string

The name of the temporary directory:

Under Unix, the value of the TMPDIR environment variable, or "/tmp" if the variable is not set.

Under Windows, the value of the TEMP environment variable, or "." if the variable is not set.

val current_dir_name : Core_kernel__.Import.string

The conventional name for the current directory (e.g. . in Unix).

val parent_dir_name : Core_kernel__.Import.string

The conventional name for the parent of the current directory (e.g. .. in Unix).

val dir_sep : Core_kernel__.Import.string

The directory separator (e.g. / in Unix).

val concat : Core_kernel__.Import.string -> Core_kernel__.Import.string -> Core_kernel__.Import.string

concat p1 p2 returns a path equivalent to p1 ^ "/" ^ p2. In the resulting path p1 (resp. p2) has all its trailing (resp. leading) "." and "/" removed. eg: concat "a/." ".//b" => "a/b" concat "." "b" => "./b" concat "a" "." => "a/." concat "a" "/b" => "a/b"

@throws Failure if p1 is empty.

val is_relative : Core_kernel__.Import.string -> Core_kernel__.Import.bool

Return true if the file name is relative to the current directory, false if it is absolute (i.e. in Unix, starts with /).

val is_absolute : Core_kernel__.Import.string -> Core_kernel__.Import.bool
val is_implicit : Core_kernel__.Import.string -> Core_kernel__.Import.bool

Return true if the file name is relative and does not start with an explicit reference to the current directory (./ or ../ in Unix), false if it starts with an explicit reference to the root directory or the current directory.

val check_suffix : Core_kernel__.Import.string -> Core_kernel__.Import.string -> Core_kernel__.Import.bool

check_suffix name suff returns true if the filename name ends with the suffix suff.

val chop_suffix : Core_kernel__.Import.string -> Core_kernel__.Import.string -> Core_kernel__.Import.string

chop_suffix name suff removes the suffix suff from the filename name. The behavior is undefined if name does not end with the suffix suff.

val chop_extension : Core_kernel__.Import.string -> Core_kernel__.Import.string

Return the given file name without its extension. The extension is the shortest suffix starting with a period and not including a directory separator, .xyz for instance.

Raise Invalid_argument if the given name does not contain an extension.

val split_extension : Core_kernel__.Import.string -> Core_kernel__.Import.string * Core_kernel__.Import.string Core_kernel__.Import.option

split_extension fn return the portion of the filename before the extension and the (optional) extension. Example: split_extension "/foo/my_file" = ("/foo/my_file", None) split_extension "/foo/my_file.txt" = ("/foo/my_file", Some "txt") split_extension "/home/c.falls/my_file" = ("/home/c.falls/my_file", None)

val basename : Core_kernel__.Import.string -> Core_kernel__.Import.string

Respects the posix semantic.

Split a file name into directory name / base file name. concat (dirname name) (basename name) returns a file name which is equivalent to name. Moreover, after setting the current directory to dirname name (with Sys.chdir), references to basename name (which is a relative file name) designate the same file as name before the call to Sys.chdir.

The result is not specified if the argument is not a valid file name (for example, under Unix if there is a NUL character in the string).

val dirname : Core_kernel__.Import.string -> Core_kernel__.Import.string
val to_absolute_exn : Core_kernel__.Import.string -> relative_to:Core_kernel__.Import.string -> Core_kernel__.Import.string

Returns the absolute path by prepending relative_to if the path is not already absolute.

Using the result of Core.Unix.getcwd as relative_to is often a reasonable choice.

Note that to_absolute_exn may return a non-canonical path (e.g. /foo/bar/../baz).

Raises if relative_to is a relative path.

val split : Core_kernel__.Import.string -> Core_kernel__.Import.string * Core_kernel__.Import.string

split filename returns (dirname filename, basename filename)

val parts : Core_kernel__.Import.string -> Core_kernel__.Import.string Core_kernel__.Import.list

parts filename returns a list of path components in order. For instance: /tmp/foo/bar/baz -> "/"; "tmp"; "foo"; "bar"; "baz". The first component is always either "." for relative paths or "/" for absolute ones.

val of_parts : Core_kernel__.Import.string Core_kernel__.Import.list -> Core_kernel__.Import.string

of_parts parts joins a list of path components into a path. It does roughly the opposite of parts, but they fail to be precisely mutually inverse because of ambiguities like multiple consecutive slashes and . components.

Raises an error if given an empty list.

val quote : Core_kernel__.Import.string -> Core_kernel__.Import.string

Return a quoted version of a file name, suitable for use as one argument in a command line, escaping all meta-characters. Warning: under Windows, the output is only suitable for use with programs that follow the standard Windows quoting conventions.

See Sys.quote for an alternative implementation that is more human readable but less portable.

module Stable = Core.Filename.Stable
Sourceval realpath : string -> string

realpath path

  • returns

    the canonicalized absolute pathname of path.

  • raises Unix_error

    on errors.

Sourceval open_temp_file : ?perm:int -> ?in_dir:string -> string -> string -> string * Core__.Import.Out_channel.t

Same as Core_filename.temp_file, but returns both the name of a fresh temporary file, and an output channel opened (atomically) on this file. This function is more secure than temp_file: there is no risk that the temporary file will be modified (e.g. replaced by a symbolic link) before the program opens it.

Sourceval open_temp_file_fd : ?perm:int -> ?in_dir:string -> string -> string -> string * Caml_unix.file_descr

Similar to Core_filename.open_temp_file, but returns a Unix file descriptor open in read&write mode instead of an Out_channel.t.

temp_file ?perm ?in_dir_name prefix suffix

Returns the name of a fresh temporary file in the temporary directory. The base name of the temporary file is formed by concatenating prefix, then .tmp., then a 6-digit hex number, then suffix. The temporary file is created empty. The file is guaranteed to be fresh, i.e. not already existing in the directory.

  • parameter in_dir

    the directory in which to create the temporary file. The default is temp_dir_name

  • parameter perm

    the permission of the temporary file. The default value is 0o600 (readable and writable only by the file owner)

Note that prefix and suffix will be changed when necessary to make the final filename valid POSIX.

temp_dir is the same as temp_file but creates a temporary directory.

Sourceval temp_file : ?perm:int -> ?in_dir:string -> string -> string -> string
Sourceval temp_dir : ?perm:int -> ?in_dir:string -> string -> string -> string
Sourceval create_arg_type : ?key:'a Core_kernel.Univ_map.Multi.Key.t -> (string -> 'a) -> 'a Core_kernel.Command.Arg_type.t

create_arg_type's resulting Arg_type.t does bash autocompletion, via compgen.

arg_type is create_arg_type Fn.id

OCaml

Innovation. Community. Security.