Coverage Report

Created: 2023-09-30 09:22

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Host/posix/FileSystemPosix.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- FileSystemPosix.cpp -----------------------------------------------===//
2
//
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
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "lldb/Host/FileSystem.h"
10
11
// C includes
12
#include <dirent.h>
13
#include <fcntl.h>
14
#include <sys/mount.h>
15
#include <sys/param.h>
16
#include <sys/stat.h>
17
#include <sys/types.h>
18
#include <unistd.h>
19
#if defined(__NetBSD__)
20
#include <sys/statvfs.h>
21
#endif
22
23
// lldb Includes
24
#include "lldb/Host/Host.h"
25
#include "lldb/Utility/Status.h"
26
#include "lldb/Utility/StreamString.h"
27
28
#include "llvm/Support/Errno.h"
29
#include "llvm/Support/FileSystem.h"
30
31
using namespace lldb;
32
using namespace lldb_private;
33
34
const char *FileSystem::DEV_NULL = "/dev/null";
35
36
0
Status FileSystem::Symlink(const FileSpec &src, const FileSpec &dst) {
37
0
  Status error;
38
0
  if (::symlink(dst.GetPath().c_str(), src.GetPath().c_str()) == -1)
39
0
    error.SetErrorToErrno();
40
0
  return error;
41
0
}
42
43
2
Status FileSystem::Readlink(const FileSpec &src, FileSpec &dst) {
44
2
  Status error;
45
2
  char buf[PATH_MAX];
46
2
  ssize_t count = ::readlink(src.GetPath().c_str(), buf, sizeof(buf) - 1);
47
2
  if (count < 0)
48
0
    error.SetErrorToErrno();
49
2
  else {
50
2
    buf[count] = '\0'; // Success
51
2
    dst.SetFile(buf, FileSpec::Style::native);
52
2
  }
53
2
  return error;
54
2
}
55
56
120k
Status FileSystem::ResolveSymbolicLink(const FileSpec &src, FileSpec &dst) {
57
120k
  char resolved_path[PATH_MAX];
58
120k
  if (!src.GetPath(resolved_path, sizeof(resolved_path))) {
59
4.15k
    return Status("Couldn't get the canonical path for %s",
60
4.15k
                  src.GetPath().c_str());
61
4.15k
  }
62
63
116k
  char real_path[PATH_MAX + 1];
64
116k
  if (realpath(resolved_path, real_path) == nullptr) {
65
6
    Status err;
66
6
    err.SetErrorToErrno();
67
6
    return err;
68
6
  }
69
70
116k
  dst = FileSpec(real_path);
71
72
116k
  return Status();
73
116k
}
74
75
161
FILE *FileSystem::Fopen(const char *path, const char *mode) {
76
161
  return llvm::sys::RetryAfterSignal(nullptr, ::fopen, path, mode);
77
161
}
78
79
12.6k
int FileSystem::Open(const char *path, int flags, int mode) {
80
  // Call ::open in a lambda to avoid overload resolution in RetryAfterSignal
81
  // when open is overloaded, such as in Bionic.
82
12.6k
  auto lambda = [&]() { return ::open(path, flags, mode); };
83
12.6k
  return llvm::sys::RetryAfterSignal(-1, lambda);
84
12.6k
}