1// Copyright (c) 2022 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef TOOLS_GN_ATOMIC_WRITE_H_ 6#define TOOLS_GN_ATOMIC_WRITE_H_ 7 8#include "base/files/file_path.h" 9 10namespace util { 11 12// Writes the given buffer into the file, overwriting any data that was 13// previously there. The write is performed atomically by first writing the 14// contents to a temporary file and then moving it into place. Returns the 15// number of bytes written, or -1 on error. 16int WriteFileAtomically(const base::FilePath& filename, 17 const char* data, 18 int size); 19 20} // namespace util 21 22#endif // TOOLS_GN_ATOMIC_WRITE_H_ 23