Frama-C API - Filepath
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.
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, unlikerealpath
;- non-existing directories in
realpath
may lead to ENOTDIR errors, butnormalize
may accept them.
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.
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.
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 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).
Describes a position in a source file.
val empty_pos : position
Empty position, used as 'dummy' for Cil_datatype.Position
.
val pp_pos : Stdlib.Format.formatter -> position -> unit
Pretty-prints a position, in the format file:line.
val is_empty_pos : position -> bool
Return true if the given position is the empty position.
val pwd : unit -> Normalized.t
Return the current working directory. Implicitly uses Unix.realpath
to normalize paths and avoid issues with symbolic links in directory names.
val exists : Normalized.t -> bool
Equivalent to Sys.file_exists
.
val is_dir : Normalized.t -> bool
Equivalent to Sys.is_directory
.
val readdir : Normalized.t -> string array
Equivalent to Sys.readdir
.
val remove : Normalized.t -> unit
Equivalent to Sys.remove
.
val rename : Normalized.t -> Normalized.t -> unit
Equivalent to Sys.rename
.
val basename : Normalized.t -> string
Equivalent to Filename.basename
.
val dirname : Normalized.t -> Normalized.t
Equivalent to Filename.dirname
.