blob: 68a8c0e2e218ff8a35d07cc6a2f4a09721b6f789 [file] [log] [blame]
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ash/authpolicy/data_pipe_utils.h"
#include "base/files/file_util.h"
#include "base/logging.h"
namespace ash {
namespace data_pipe_utils {
base::ScopedFD GetDataReadPipe(const std::string& data) {
int pipe_fds[2];
if (!base::CreateLocalNonBlockingPipe(pipe_fds)) {
DLOG(ERROR) << "Failed to create pipe";
return base::ScopedFD();
}
base::ScopedFD pipe_read_end(pipe_fds[0]);
base::ScopedFD pipe_write_end(pipe_fds[1]);
if (!base::WriteFileDescriptor(pipe_write_end.get(), data)) {
DLOG(ERROR) << "Failed to write to pipe";
return base::ScopedFD();
}
return pipe_read_end;
}
} // namespace data_pipe_utils
} // namespace ash