[ccan] [PATCH v2 03/13] configurator: Inline err.h functions from musl libc
David Gibson
david at gibson.dropbear.id.au
Tue Sep 27 15:01:10 AEST 2016
On Thu, Sep 22, 2016 at 09:33:06PM -0600, Kevin Locke wrote:
> Since we can't use HAVE_ERR_H in configurator, provide a definition for
> the err.h functions used. The version provided is the one from musl
> libc, since it is concise and shares the MIT License with configurator.
>
> Signed-off-by: Kevin Locke <kevin at kevinlocke.name>
For me this breaks Linux build, because we get "static declaration
follows non-static" on these functions.
I think we instead want to stop using the err() etc. functions and use
similar functions with a different name that we always define locally.
> ---
> tools/configurator/configurator.c | 54 ++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 53 insertions(+), 1 deletion(-)
>
> diff --git a/tools/configurator/configurator.c b/tools/configurator/configurator.c
> index 4eed188..5929355 100644
> --- a/tools/configurator/configurator.c
> +++ b/tools/configurator/configurator.c
> @@ -3,6 +3,9 @@
> *
> * Copyright 2011 Rusty Russell <rusty at rustcorp.com.au>. MIT license.
> *
> + * err, errx, verr, verrx, vwarn, vwarnx functions from musl libc
> + * Copyright 2005-2013 Rich Felker. MIT license.
> + *
> * Permission is hereby granted, free of charge, to any person obtaining a copy
> * of this software and associated documentation files (the "Software"), to deal
> * in the Software without restriction, including without limitation the rights
> @@ -25,9 +28,9 @@
>
> #include <errno.h>
> #include <stdio.h>
> +#include <stdarg.h>
> #include <stdbool.h>
> #include <stdlib.h>
> -#include <err.h>
> #include <string.h>
>
> #ifdef _MSC_VER
> @@ -41,6 +44,7 @@
> #define OUTPUT_FILE "configurator.out"
> #define INPUT_FILE "configuratortest.c"
>
> +static const char *progname = "";
> static int verbose;
>
> enum test_style {
> @@ -370,6 +374,51 @@ static struct test tests[] = {
> },
> };
>
> +static void vwarn(const char *fmt, va_list ap)
> +{
> + fprintf (stderr, "%s: ", progname);
> + if (fmt) {
> + vfprintf(stderr, fmt, ap);
> + fputs (": ", stderr);
> + }
> + perror(0);
> +}
> +
> +static void vwarnx(const char *fmt, va_list ap)
> +{
> + fprintf (stderr, "%s: ", progname);
> + if (fmt) vfprintf(stderr, fmt, ap);
> + putc('\n', stderr);
> +}
> +
> +static void verr(int status, const char *fmt, va_list ap)
> +{
> + vwarn(fmt, ap);
> + exit(status);
> +}
> +
> +static void verrx(int status, const char *fmt, va_list ap)
> +{
> + vwarnx(fmt, ap);
> + exit(status);
> +}
> +
> +static void err(int status, const char *fmt, ...)
> +{
> + va_list ap;
> + va_start(ap, fmt);
> + verr(status, fmt, ap);
> + va_end(ap);
> +}
> +
> +static void errx(int status, const char *fmt, ...)
> +{
> + va_list ap;
> + va_start(ap, fmt);
> + verrx(status, fmt, ap);
> + va_end(ap);
> +}
> +
> static size_t fread_noeintr(void *ptr, size_t size, size_t nitems,
> FILE *stream)
> {
> @@ -610,6 +659,9 @@ int main(int argc, const char *argv[])
> const char *default_args[]
> = { "", DEFAULT_COMPILER, DEFAULT_FLAGS, NULL };
>
> + if (argc > 0)
> + progname = argv[0];
> +
> if (argc > 1) {
> if (strcmp(argv[1], "--help") == 0) {
> printf("Usage: configurator [-v] [<compiler> <flags>...]\n"
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/ccan/attachments/20160927/8c19dfb5/attachment-0001.sig>
More information about the ccan
mailing list