diff options
author | Omar Polo <op@omarpolo.com> | 2023-08-07 15:39:57 +0000 |
---|---|---|
committer | Omar Polo <op@omarpolo.com> | 2023-08-07 15:39:57 +0000 |
commit | d13b044d59619a52277c229eb37d38265690fb64 (patch) | |
tree | 89429e47360307453a0e48e86a1be6278889d93b /have | |
parent | ddbcd3c13f2159113bb7e9921a1bec13755c5d43 (diff) |
address the strnvis(3) portability fiasco
strnvis originates on OpenBSD. When NetBSD added it to their libc
they decided to swap the argument. Without starting a holy war on
the "best" argument order, adding an implementation of a function
that's widely available and making its signature purposefully
incompatible is beyond justification. FreeBSD (and so macos too?)
followed NetBSD in this, so we end up with *two* major and incompatible
strnvis implementations. libbsd is in a limbo, they started with
the OpenBSD version but they'll probably switch to the NetBSD version
in the future.
That's why we can't have nice things.
Do the right thing(tm) and check for the presence of the original
strnvis(3), if not available or broken use the bundled one.
Diffstat (limited to 'have')
-rw-r--r-- | have/Makefile | 3 | ||||
-rw-r--r-- | have/vis.c | 26 |
2 files changed, 28 insertions, 1 deletions
diff --git a/have/Makefile b/have/Makefile index ee214d5..9fd19e8 100644 --- a/have/Makefile +++ b/have/Makefile @@ -24,7 +24,8 @@ DISTFILES = Makefile \ strlcpy.c \ strtonum.c \ tree_h.c \ - vasprintf.c + vasprintf.c \ + vis.c all: false diff --git a/have/vis.c b/have/vis.c new file mode 100644 index 0000000..85a4307 --- /dev/null +++ b/have/vis.c @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 Omar Polo <op@omarpolo.com> + * + * Permission to use, copy, modify, and 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. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <stdlib.h> +#include <vis.h> + +int +main(void) +{ + char buf[128]; + + return strnvis(buf, "Hello, world!\n", sizeof(buf), 0); +} |