diff options
| author | Roy Marples <roy@marples.name> | 2019-06-18 11:33:53 +0100 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2019-06-18 11:33:53 +0100 |
| commit | ae3c3144861a285e77d69e888cd7cd732fb2d7a1 (patch) | |
| tree | d692e469c71cd8f9e64a0fb62d701ae48bbbfc5e /configure | |
| parent | 6da1356363264bcfb6237797965ef59c234fa795 (diff) | |
| download | dhcpcd-ae3c3144861a285e77d69e888cd7cd732fb2d7a1.tar.xz | |
script: Write variables to a FILE
Each variable is NULL terminated inside the file just like the
control stream which saves us from having to flatten it when
writing to the control stream.
Once written, create env pointers to the start of each string
just after the NULL terminator.
This also means that we just need to free two buffers when
dhcpcd exits (FILE buffer and env buffer) rather than each variable
individually.
If open_memstream(3) is not supported by libc then dhcpcd will
write to a file in /tmp instead.
Diffstat (limited to 'configure')
| -rwxr-xr-x | configure | 53 |
1 files changed, 37 insertions, 16 deletions
@@ -15,6 +15,7 @@ ARC4RANDOM= CLOSEFROM= RBTREE= CONSTTIME_MEMEQUAL= +OPEN_MEMSTREAM= STRLCPY= UDEV= OS= @@ -741,29 +742,25 @@ if [ "$ARC4RANDOM_UNIFORM" = no ]; then echo "#include \"compat/arc4random_uniform.h\"" >>$CONFIG_H fi - -if [ -z "$STRLCPY" ]; then - printf "Testing for strlcpy ... " - cat <<EOF >_strlcpy.c -#include <string.h> +if [ -z "$OPEN_MEMSTREAM" ]; then + printf "Testing for open_memstream ... " + cat <<EOF >_open_memstream.c +#include <stdio.h> int main(void) { - const char s1[] = "foo"; - char s2[10]; - strlcpy(s2, s1, sizeof(s2)); + open_memstream(NULL, NULL); return 0; } EOF - if $XCC _strlcpy.c -o _strlcpy 2>&3; then - STRLCPY=yes + if $XCC _open_memstream.c -o _open_memstream 2>&3; then + OPEN_MEMSTREAM=yes else - STRLCPY=no + OPEN_MEMSTREAM=no fi - echo "$STRLCPY" - rm -f _strlcpy.c _strlcpy + echo "$OPEN_MEMSTREAM" + rm -f _open_memstream.c _open_memstream fi -if [ "$STRLCPY" = no ]; then - echo "COMPAT_SRCS+= compat/strlcpy.c" >>$CONFIG_MK - echo "#include \"compat/strlcpy.h\"" >>$CONFIG_H +if [ "$OPEN_MEMSTREAM" = yes ]; then + echo "#define HAVE_OPEN_MEMSTREAM" >>$CONFIG_H fi if [ -z "$PIDFILE_LOCK" ]; then @@ -824,6 +821,30 @@ if [ "$SETPROCTITLE" = yes ]; then echo "#define HAVE_SETPROCTITLE" >>$CONFIG_H fi +if [ -z "$STRLCPY" ]; then + printf "Testing for strlcpy ... " + cat <<EOF >_strlcpy.c +#include <string.h> +int main(void) { + const char s1[] = "foo"; + char s2[10]; + strlcpy(s2, s1, sizeof(s2)); + return 0; +} +EOF + if $XCC _strlcpy.c -o _strlcpy 2>&3; then + STRLCPY=yes + else + STRLCPY=no + fi + echo "$STRLCPY" + rm -f _strlcpy.c _strlcpy +fi +if [ "$STRLCPY" = no ]; then + echo "COMPAT_SRCS+= compat/strlcpy.c" >>$CONFIG_MK + echo "#include \"compat/strlcpy.h\"" >>$CONFIG_H +fi + if [ -z "$STRTOI" ]; then printf "Testing for strtoi ... " cat <<EOF >_strtoi.c |
