2021-11-21 23:59:44 +00:00
|
|
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
2021-04-03 09:10:35 +01:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
2020-10-29 00:35:09 +00:00
|
|
|
|
|
|
|
#include <stdarg.h>
|
2021-02-23 22:31:01 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2020-10-29 00:35:09 +00:00
|
|
|
|
2022-08-26 19:32:10 +01:00
|
|
|
#include "binary_buffer.h"
|
|
|
|
#include "drgn.h"
|
|
|
|
|
2020-10-29 00:35:09 +00:00
|
|
|
static struct drgn_error *binary_buffer_error_vat(struct binary_buffer *bb,
|
|
|
|
const char *pos,
|
|
|
|
const char *format,
|
|
|
|
va_list ap)
|
|
|
|
{
|
|
|
|
char *message;
|
|
|
|
int ret = vasprintf(&message, format, ap);
|
|
|
|
if (ret == -1)
|
|
|
|
return &drgn_enomem;
|
|
|
|
struct drgn_error *err = bb->error_fn(bb, pos, message);
|
|
|
|
free(message);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct drgn_error *binary_buffer_error(struct binary_buffer *bb,
|
|
|
|
const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
|
|
|
struct drgn_error *err = binary_buffer_error_vat(bb, bb->prev, format,
|
|
|
|
ap);
|
|
|
|
va_end(ap);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct drgn_error *binary_buffer_error_at(struct binary_buffer *bb,
|
|
|
|
const char *pos, const char *format,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
|
|
|
struct drgn_error *err = binary_buffer_error_vat(bb, pos, format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
return err;
|
|
|
|
}
|