package frama-c

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Functions manipulating filepaths. In these functions, references to the current working directory refer to the result given by function Sys.getcwd.

NOTE: Prefer using the Normalized module whenever possible.

type existence =
  1. | Must_exist
    (*

    File must exist.

    *)
  2. | Must_not_exist
    (*

    File must not exist.

    *)
  3. | Indifferent
    (*

    No requirement.

    *)

Existence requirement on a file.

exception No_file

Raised whenever no file exists and existence is Must_exist.

exception File_exists

Raised whenever some file exists and existence is Must_not_exist.

val normalize : ?existence:existence -> ?base_name:string -> string -> string

Returns an absolute path leading to the given file. The result is similar to realpath --no-symlinks. Some special behaviors include:

  • normalize "" (empty string) returns "" (realpath returns an error);
  • normalize preserves multiple sequential '/' characters, unlike realpath;
  • non-existing directories in realpath may lead to ENOTDIR errors, but normalize may accept them.
  • before 21.0-Scandium

    no existence argument.

val relativize : ?base_name:string -> string -> string

relativize base_name file_name returns a relative path name of file_name w.r.t. base_name, if base_name is a prefix of file; otherwise, returns file_name unchanged. The default base name is the current working directory name.

  • since Aluminium-20160501
module Normalized : sig ... end

The Normalized module is simply a wrapper that ensures that paths are always normalized. Used by Datatype.Filepath.

val is_relative : ?base_name:Normalized.t -> Normalized.t -> bool

returns true if the file is relative to base (that is, it is prefixed by base_name), or to the current working directory if no base is specified.

  • since Aluminium-20160501
  • before 23.0-Vanadium

    argument types were string instead of Normalized.t.

val add_symbolic_dir : string -> Normalized.t -> unit

add_symbolic_dir name dir indicates that the (absolute) path dir must be replaced by name when pretty-printing paths. This alias ensures that system-dependent paths such as FRAMAC_SHARE are printed identically in different machines.

val add_symbolic_dir_list : string -> Normalized.t list -> unit
val reset_symbolic_dirs : unit -> unit

Remove all symbolic dirs that have been added earlier.

  • since 23.0-Vanadium
val all_symbolic_dirs : unit -> (string * Normalized.t) list

Returns the list of symbolic dirs added via add_symbolic_dir, plus preexisting ones (e.g. FRAMAC_SHARE), as pairs (name, dir).

  • since 22.0-Titanium
type position = {
  1. pos_path : Normalized.t;
  2. pos_lnum : int;
  3. pos_bol : int;
  4. pos_cnum : int;
}

Describes a position in a source file.

  • since 18.0-Argon
val pp_pos : Format.formatter -> position -> unit

Pretty-prints a position, in the format file:line.

  • since 18.0-Argon
val pwd : unit -> string

Return the current working directory. Currently uses the environment's PWD instead of Sys.getcwd () because OCaml has no function in its stdlib to resolve symbolic links (e.g. realpath) for a given path. 'getcwd' always resolves them, but if the user supplies a path with symbolic links, this may cause issues. Instead of forcing the user to always provide resolved paths, we currently choose to never resolve them. We only resort to getcwd() to avoid issues when PWD does not exist. Note that this function does not validate that PWD has not been tampered with.

  • since 25.0-Manganese
OCaml

Innovation. Community. Security.