2014-08-16 06:04:21 +08:00
|
|
|
//===-- FileSystem.cpp ------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Host/FileSystem.h"
|
|
|
|
|
|
|
|
// C includes
|
2015-06-28 07:11:34 +08:00
|
|
|
#include <dirent.h>
|
2015-02-24 07:47:09 +08:00
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/param.h>
|
2014-08-16 06:04:21 +08:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2017-07-18 21:14:01 +08:00
|
|
|
#include <unistd.h>
|
2015-09-09 09:19:05 +08:00
|
|
|
#if defined(__NetBSD__)
|
|
|
|
#include <sys/statvfs.h>
|
|
|
|
#endif
|
2014-08-16 06:04:21 +08:00
|
|
|
|
|
|
|
// lldb Includes
|
|
|
|
#include "lldb/Host/Host.h"
|
2017-05-12 12:51:55 +08:00
|
|
|
#include "lldb/Utility/Status.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/StreamString.h"
|
2014-08-16 06:04:21 +08:00
|
|
|
|
2017-03-09 01:56:08 +08:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
|
|
|
|
2014-08-16 06:04:21 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const char *FileSystem::DEV_NULL = "/dev/null";
|
2015-10-15 05:37:36 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status FileSystem::Symlink(const FileSpec &src, const FileSpec &dst) {
|
|
|
|
Status error;
|
2016-09-07 04:57:50 +08:00
|
|
|
if (::symlink(dst.GetCString(), src.GetCString()) == -1)
|
|
|
|
error.SetErrorToErrno();
|
|
|
|
return error;
|
2014-08-16 06:04:21 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status FileSystem::Readlink(const FileSpec &src, FileSpec &dst) {
|
|
|
|
Status error;
|
2016-09-07 04:57:50 +08:00
|
|
|
char buf[PATH_MAX];
|
|
|
|
ssize_t count = ::readlink(src.GetCString(), buf, sizeof(buf) - 1);
|
|
|
|
if (count < 0)
|
|
|
|
error.SetErrorToErrno();
|
|
|
|
else {
|
|
|
|
buf[count] = '\0'; // Success
|
2018-06-14 06:08:14 +08:00
|
|
|
dst.SetFile(buf, false, FileSpec::Style::native);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
return error;
|
2014-08-16 06:04:21 +08:00
|
|
|
}
|
2015-02-24 07:47:09 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status FileSystem::ResolveSymbolicLink(const FileSpec &src, FileSpec &dst) {
|
2016-09-07 04:57:50 +08:00
|
|
|
char resolved_path[PATH_MAX];
|
|
|
|
if (!src.GetPath(resolved_path, sizeof(resolved_path))) {
|
2017-05-12 12:51:55 +08:00
|
|
|
return Status("Couldn't get the canonical path for %s", src.GetCString());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
char real_path[PATH_MAX + 1];
|
|
|
|
if (realpath(resolved_path, real_path) == nullptr) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status err;
|
2016-09-07 04:57:50 +08:00
|
|
|
err.SetErrorToErrno();
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
dst = FileSpec(real_path, false);
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
return Status();
|
2015-09-19 06:24:57 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
FILE *FileSystem::Fopen(const char *path, const char *mode) {
|
|
|
|
return ::fopen(path, mode);
|
2016-03-23 01:58:09 +08:00
|
|
|
}
|