Fuzion Logo
fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.

io/file/L_Stat.fz


# This file is part of the Fuzion language implementation.
#
# The Fuzion language implementation is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, version 3 of the License.
#
# The Fuzion language implementation is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with The
# Fuzion language implementation.  If not, see <https://www.gnu.org/licenses/>.


# -----------------------------------------------------------------------
#
#  Tokiwa Software GmbH, Germany
#
#  Source code of Fuzion standard library feature Stat
#
#  Author: Wael Youssfi (wael.youssfi@tokiwa.software)
#
# -----------------------------------------------------------------------


# L_Stat -- effect providing operations to retrieve file stats
#
public L_Stat ref : effect is

  # returns stats of the file/dir passed in the pathname
  # in success it will return a meta_data outcome storing stats regarding the file/dir
  # in case of failure an error will be returned
  # this feature does not resolve symbolic links and returns stats of the link itself
  #
  public stats(
    # the (relative or absolute) file name, using platform specific path separators
    path path) outcome io.file.meta_data => abstract


  # default implementation of L_Stat
  #
  # this will get instated automatically at startup
  #
  public redef fixed type.default_value option io.file.L_Stat =>
    _ : io.file.L_Stat is

      public redef stats(path path) outcome io.file.meta_data =>
        res := fuzion.sys.internal_array_init i64 9
        if fzE_lstat (fuzion.sys.c_string path.as_platform_string) res.data = 0
          path.as_absolute.bind p->
            io.file.meta_data p res[0] res[1] res[2] res[3] (res[4] = 1) (res[5] = 1) (res[6] = 1) res[7] res[8]
        else
          error "lstat error $(res[0]) for $(path)"

last changed: 2026-07-23