1 //===-- FileSystem.cpp ------------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Host/FileSystem.h"
14 #include <sys/mount.h>
15 #include <sys/param.h>
17 #include <sys/types.h>
19 #if defined(__NetBSD__)
20 #include <sys/statvfs.h>
24 #include "lldb/Host/Host.h"
25 #include "lldb/Utility/Status.h"
26 #include "lldb/Utility/StreamString.h"
28 #include "llvm/Support/Errno.h"
29 #include "llvm/Support/FileSystem.h"
32 using namespace lldb_private;
34 const char *FileSystem::DEV_NULL = "/dev/null";
36 Status FileSystem::Symlink(const FileSpec &src, const FileSpec &dst) {
38 if (::symlink(dst.GetCString(), src.GetCString()) == -1)
39 error.SetErrorToErrno();
43 Status FileSystem::Readlink(const FileSpec &src, FileSpec &dst) {
46 ssize_t count = ::readlink(src.GetCString(), buf, sizeof(buf) - 1);
48 error.SetErrorToErrno();
50 buf[count] = '\0'; // Success
51 dst.SetFile(buf, FileSpec::Style::native);
56 Status FileSystem::ResolveSymbolicLink(const FileSpec &src, FileSpec &dst) {
57 char resolved_path[PATH_MAX];
58 if (!src.GetPath(resolved_path, sizeof(resolved_path))) {
59 return Status("Couldn't get the canonical path for %s", src.GetCString());
62 char real_path[PATH_MAX + 1];
63 if (realpath(resolved_path, real_path) == nullptr) {
65 err.SetErrorToErrno();
69 dst = FileSpec(real_path);
74 FILE *FileSystem::Fopen(const char *path, const char *mode) {
75 return llvm::sys::RetryAfterSignal(nullptr, ::fopen, path, mode);
78 int FileSystem::Open(const char *path, int flags, int mode) {
79 return llvm::sys::RetryAfterSignal(-1, ::open, path, flags, mode);