From ebcc78644e0cbc4141807c0887ef8d902cb91bb4 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Wed, 24 Jun 2026 21:47:19 +0200 Subject: Vendor import of pkgconf 2.9.90 Obtained from https://github.com/pkgconf/pkgconf/archive/refs/tags/pkgconf-2.9.90.tar.gz SHA1: ebfb0525c019eda14190d463680cb1625f3177f9 - SHA256: f5c10610be8ea7278fc31ad63b943525b5b2a2f6e5038d3c11947f5bd6fd214d - SHA512: f93e6d15d25d02869a03ba339e18582f01a9b7241be89a87183c0f373a3df78d1be005dee376ea464f7942735700f51dab57b8688bc802ec152ff343af721f46 - One test folder in tests/lib1 had to be removed to avoid UTF-8 filenames in the tree. (Breaks `make create-source-packages`) Reviewed by: markj Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D57837 --- libpkgconf/output.c | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 libpkgconf/output.c (limited to 'libpkgconf/output.c') diff --git a/libpkgconf/output.c b/libpkgconf/output.c new file mode 100644 index 000000000000..fc7ab85ea2e1 --- /dev/null +++ b/libpkgconf/output.c @@ -0,0 +1,153 @@ +/* + * output.c + * I/O abstraction layer + * + * SPDX-License-Identifier: pkgconf + * + * Copyright (c) 2025 pkgconf authors (see AUTHORS). + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * This software is provided 'as is' and without any warranty, express or + * implied. In no event shall the authors be liable for any damages arising + * from the use of this software. + */ + +#include +#include + +bool +pkgconf_output_putbuf(pkgconf_output_t *output, pkgconf_output_stream_t stream, const pkgconf_buffer_t *buffer, bool newline) +{ + bool ret; + pkgconf_buffer_t buf = PKGCONF_BUFFER_INITIALIZER; + + if (pkgconf_buffer_len(buffer) != 0) + pkgconf_buffer_append(&buf, pkgconf_buffer_str(buffer)); + + if (newline) + pkgconf_buffer_push_byte(&buf, '\n'); + + ret = output->write(output, stream, &buf); + pkgconf_buffer_finalize(&buf); + + return ret; +} + +bool +pkgconf_output_puts(pkgconf_output_t *output, pkgconf_output_stream_t stream, const char *str) +{ + bool ret; + pkgconf_buffer_t buf = PKGCONF_BUFFER_INITIALIZER; + + pkgconf_buffer_append(&buf, str); + pkgconf_buffer_push_byte(&buf, '\n'); + ret = output->write(output, stream, &buf); + pkgconf_buffer_finalize(&buf); + + return ret; +} + +bool +pkgconf_output_fmt(pkgconf_output_t *output, pkgconf_output_stream_t stream, const char *fmt, ...) +{ + bool ret; + va_list va; + + va_start(va, fmt); + ret = pkgconf_output_vfmt(output, stream, fmt, va); + va_end(va); + + return ret; +} + +bool +pkgconf_output_vfmt(pkgconf_output_t *output, pkgconf_output_stream_t stream, const char *fmt, va_list src_va) +{ + va_list va; + bool ret; + pkgconf_buffer_t buf = PKGCONF_BUFFER_INITIALIZER; + + va_copy(va, src_va); + pkgconf_buffer_append_vfmt(&buf, fmt, va); + va_end(va); + + ret = output->write(output, stream, &buf); + pkgconf_buffer_finalize(&buf); + + return ret; +} + +static bool +pkgconf_output_stdio_write(pkgconf_output_t *output, pkgconf_output_stream_t stream, const pkgconf_buffer_t *buffer) +{ + (void) output; + + FILE *target = stream == PKGCONF_OUTPUT_STDERR ? stderr : stdout; + + if (buffer != NULL) + { + const char *str = pkgconf_buffer_str(buffer); + size_t size = pkgconf_buffer_len(buffer); + + if (size > 0 && !fwrite(str, size, 1, target)) + return false; + } + + fflush(target); + return true; +} + +static pkgconf_output_t pkgconf_default_output = { + .privdata = NULL, + .write = pkgconf_output_stdio_write, +}; + +pkgconf_output_t * +pkgconf_output_default(void) +{ + return &pkgconf_default_output; +} + +/* + * !doc + * + * .. c:function:: bool pkgconf_output_file_vfmt(FILE *f, const char *fmt, va_list va) + * + * Wrapper around :code:`vfprintf` that returns a boolean. + * + * :param FILE *f: Pointer to an open `FILE` pointer. + * :param: const char *fmt: Format string. + * :param va_list va: Variable list. + * :return: :code:`true` on success, :code:`false` on failure. + */ +bool +pkgconf_output_file_vfmt(FILE *f, const char *fmt, va_list va) +{ + int ret = vfprintf(f, fmt, va); + return ret >= 0; +} + +/* + * !doc + * + * .. c:function:: bool pkgconf_output_file_fmt(FILE *f, const char *fmt, va_list va) + * + * Wrapper around :code:`fprintf` that returns a boolean. + * + * :param FILE *f: Pointer to an open `FILE` pointer. + * :param: const char *fmt: Format string. + * :return: :code:`true` on success, :code:`false` on failure. + */ +bool +pkgconf_output_file_fmt(FILE *f, const char *fmt, ...) +{ + va_list va; + va_start(va, fmt); + bool ret = pkgconf_output_file_vfmt(f, fmt, va); + va_end(va); + + return ret; +} -- cgit v1.3