mirror of https://github.com/omar-polo/gmid.git
attempt to deal with the portability fiasco of strnvis(3)
This commit is contained in:
parent
1bc73c3bcb
commit
848189f10a
|
@ -275,6 +275,7 @@ fi
|
|||
HAVE_ENDIAN_H=0
|
||||
HAVE_SYS_ENDIAN_H=0
|
||||
HAVE_MACHINE_ENDIAN=0
|
||||
HAVE_BROKEN_STRNVIS=0
|
||||
|
||||
runtest endian_h ENDIAN_H || \
|
||||
runtest sys_endian_h SYS_ENDIAN_H || \
|
||||
|
@ -317,6 +318,12 @@ runtest tree_h TREE_H || true
|
|||
runtest vasprintf VASPRINTF -D_GNU_SOURCE || true
|
||||
runtest vis VIS -DLIBBSD_OPENBSD_VIS || true
|
||||
|
||||
if [ ${HAVE_VIS} -eq 1 ]; then
|
||||
if singletest broken-strnvis BROKEN_STRNVIS "-Wall -Werror"; then
|
||||
HAVE_BROKEN_STRNVIS=1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ${HAVE_ARC4RANDOM} -eq 1 -a ${HAVE_ARC4RANDOM_BUF} -eq 0 ]; then
|
||||
COMPATS="compat/arc4random.c ${COMPATS}"
|
||||
fi
|
||||
|
@ -648,6 +655,8 @@ cat <<__HEREDOC__
|
|||
# define HOST_NAME_MAX 255
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define HAVE_BROKEN_STRNVIS ${HAVE_BROKEN_STRNVIS}
|
||||
__HEREDOC__
|
||||
|
||||
echo "file config.h: written" 1>&2
|
||||
|
|
2
ge.c
2
ge.c
|
@ -83,7 +83,7 @@ log_request(struct client *c, int code, const char *meta)
|
|||
strlcpy(cntmp, subj + 4, sizeof(cntmp));
|
||||
if ((n = strchr(cntmp, '/')) != NULL)
|
||||
*n = '\0';
|
||||
strnvis(cn, cntmp, sizeof(cn), VIS_WHITE|VIS_DQ);
|
||||
gmid_strnvis(cn, cntmp, sizeof(cn), VIS_WHITE|VIS_DQ);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
2
gmid.c
2
gmid.c
|
@ -140,7 +140,7 @@ log_request(struct client *c, int code, const char *meta)
|
|||
strlcpy(cntmp, subj + 4, sizeof(cntmp));
|
||||
if ((n = strchr(cntmp, '/')) != NULL)
|
||||
*n = '\0';
|
||||
strnvis(cn, cntmp, sizeof(cn), VIS_WHITE|VIS_DQ);
|
||||
gmid_strnvis(cn, cntmp, sizeof(cn), VIS_WHITE|VIS_DQ);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
1
gmid.h
1
gmid.h
|
@ -469,5 +469,6 @@ EVP_PKEY *ssl_load_pkey(const uint8_t *, size_t);
|
|||
struct vhost *new_vhost(void);
|
||||
struct location *new_location(void);
|
||||
struct proxy *new_proxy(void);
|
||||
int gmid_strnvis(char *, const char *, size_t, int);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* public domain
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <vis.h>
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
char buf[128];
|
||||
|
||||
return strnvis(buf, sizeof(buf), "Hello, world!\n", 0);
|
||||
}
|
17
utils.c
17
utils.c
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <vis.h> /* for gmid_strnvis() */
|
||||
|
||||
#include <openssl/ec.h>
|
||||
#include <openssl/err.h>
|
||||
|
@ -496,3 +497,19 @@ new_proxy(void)
|
|||
p->protocols = TLS_PROTOCOLS_DEFAULT;
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
* I can't rant enough about this situation. As far as I've understood,
|
||||
* OpenBSD introduced strnvis(3) with a signature, then NetBSD did it but
|
||||
* with a incompatible signature. FreeBSD followed NetBSD. libbsd followed
|
||||
* OpenBSD but now is thinking to switch. WTF?
|
||||
*/
|
||||
int
|
||||
gmid_strnvis(char *dst, const char *src, size_t destsize, int flag)
|
||||
{
|
||||
#if HAVE_BROKEN_STRNVIS
|
||||
return strnvis(dst, destsize, src, flag);
|
||||
#else
|
||||
return strnvis(dst, src, destsize, flag);
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue