blob: 4db3204f6eff45d27343a695a4f2c4705d600386 [file] [log] [blame]
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SRC_DEVICES_BIN_DRIVER_MANAGER_VMO_WRITER_H_
#define SRC_DEVICES_BIN_DRIVER_MANAGER_VMO_WRITER_H_
#include <lib/zx/vmo.h>
#include <utility>
// Wraps a vmo to aid in writing text into it.
class VmoWriter {
public:
explicit VmoWriter(zx::vmo vmo) : vmo_(std::move(vmo)) { status_ = vmo_.get_size(&size_); }
// printf into the vmo.
void Printf(const char* fmt, ...) __PRINTFLIKE(2, 3);
size_t written() const { return written_; }
size_t available() const { return written_; }
const zx::vmo& vmo() const { return vmo_; }
zx_status_t status() const { return status_; }
private:
zx::vmo vmo_;
size_t size_ = 0;
zx_status_t status_ = ZX_OK;
size_t written_ = 0;
size_t available_ = 0;
};
#endif // SRC_DEVICES_BIN_DRIVER_MANAGER_VMO_WRITER_H_