function y = samepath(path1, path2)
arguments
  path1 (1,1) string
  path2 (1,1) string
end

y = false;

if ~stdlib.exists(path1) || ~stdlib.exists(path2)
  return
end

if ispc()
  y = stdlib.sys.device(path1) == stdlib.sys.device(path2) && ...
      stdlib.sys.inode(path1) == stdlib.sys.inode(path2);
  return
end


if ismac()
  flag = '-f';
else
  flag = '-c';
end

cmd1 = sprintf('stat %s %%d:%%i "%s"', flag, path1);
cmd2 = sprintf('stat %s %%d:%%i "%s"', flag, path2);

cmd = cmd1 + " && " + cmd2;

[s, m] = system(cmd);
if s ~= 0
  warning("stdlib:sys:samepath:RuntimeError", "stdlib.sys.samepath(%s, %s) failed: %s", path1, path2, m)
  return
end

m = splitlines(m);
assert(length(m) >= 2, "samepath(%s, %s) failed: unexpected output", path1, path2);

y = strcmp(m{1}, m{2});

end