Make uses of /dev/null portable across OSes.

Most platforms have "/dev/null".  Windows has "nul".  Instead of
hardcoding the string /dev/null at various places, make a constant
that contains the correct value depending on the platform, and use
that everywhere instead.

llvm-svn: 250331
This commit is contained in:
Zachary Turner 2015-10-14 21:37:36 +00:00
parent efc23de4dd
commit 4eff2d3177
7 changed files with 19 additions and 7 deletions

View file

@ -22,6 +22,8 @@ namespace lldb_private
class FileSystem
{
public:
static const char *DEV_NULL;
static FileSpec::PathSyntax GetNativePathSyntax();
static Error MakeDirectory(const FileSpec &file_spec, uint32_t mode);

View file

@ -32,6 +32,9 @@
using namespace lldb;
using namespace lldb_private;
const char *
FileSystem::DEV_NULL = "/dev/null";
FileSpec::PathSyntax
FileSystem::GetNativePathSyntax()
{

View file

@ -19,6 +19,9 @@
using namespace lldb_private;
const char *
FileSystem::DEV_NULL = "nul";
FileSpec::PathSyntax
FileSystem::GetNativePathSyntax()
{

View file

@ -40,6 +40,7 @@
#include "lldb/Core/Timer.h"
#include "lldb/Core/Value.h"
#include "lldb/DataFormatters/FormatManager.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/HostThread.h"
#include "lldb/Host/StringConvert.h"
#include "lldb/Host/Symbols.h"
@ -1004,11 +1005,11 @@ ProcessGDBRemote::DoLaunch (Module *exe_module, ProcessLaunchInfo &launch_info)
{
// set to /dev/null unless redirected to a file above
if (!stdin_file_spec)
stdin_file_spec.SetFile("/dev/null", false);
stdin_file_spec.SetFile(FileSystem::DEV_NULL, false);
if (!stdout_file_spec)
stdout_file_spec.SetFile("/dev/null", false);
stdout_file_spec.SetFile(FileSystem::DEV_NULL, false);
if (!stderr_file_spec)
stderr_file_spec.SetFile("/dev/null", false);
stderr_file_spec.SetFile(FileSystem::DEV_NULL, false);
}
else if (platform_sp && platform_sp->IsHost())
{

View file

@ -34,6 +34,7 @@
#include "lldb/Core/ValueObject.h"
#include "lldb/DataFormatters/TypeSummary.h"
#include "lldb/Host/ConnectionFileDescriptor.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Host/Pipe.h"
#include "lldb/Interpreter/CommandInterpreter.h"
@ -809,9 +810,9 @@ ScriptInterpreterPython::ExecuteOneLine (const char *command, CommandReturnObjec
else
{
input_file_sp.reset (new StreamFile ());
input_file_sp->GetFile().Open("/dev/null", File::eOpenOptionRead);
input_file_sp->GetFile().Open(FileSystem::DEV_NULL, File::eOpenOptionRead);
output_file_sp.reset (new StreamFile ());
output_file_sp->GetFile().Open("/dev/null", File::eOpenOptionWrite);
output_file_sp->GetFile().Open(FileSystem::DEV_NULL, File::eOpenOptionWrite);
error_file_sp = output_file_sp;
}

View file

@ -21,6 +21,7 @@
#include "lldb/Expression/UserExpression.h"
#include "lldb/Expression/IRDynamicChecks.h"
#include "lldb/Host/ConnectionFileDescriptor.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Host/Pipe.h"
@ -478,7 +479,7 @@ ProcessLaunchCommandOptions::SetOptionValue (uint32_t option_idx, const char *op
case 'n': // Disable STDIO
{
FileAction action;
const FileSpec dev_null{"/dev/null", false};
const FileSpec dev_null{FileSystem::DEV_NULL, false};
if (action.Open(STDIN_FILENO, dev_null, true, false))
launch_info.AppendFileAction (action);
if (action.Open(STDOUT_FILENO, dev_null, false, true))

View file

@ -11,6 +11,7 @@
#include "lldb/Core/Debugger.h"
#include "lldb/Core/Log.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Target/ProcessLaunchInfo.h"
#include "lldb/Target/FileAction.h"
#include "lldb/Target/Target.h"
@ -129,7 +130,7 @@ bool
ProcessLaunchInfo::AppendSuppressFileAction (int fd, bool read, bool write)
{
FileAction file_action;
if (file_action.Open(fd, FileSpec{"/dev/null", false}, read, write))
if (file_action.Open(fd, FileSpec{FileSystem::DEV_NULL, false}, read, write))
{
AppendFileAction (file_action);
return true;