mirror of
https://github.com/samba-team/samba.git
synced 2025-08-03 04:22:09 +03:00
build: added interface checking and nicer snprintf checking
use CHECK_CODE()
This commit is contained in:
29
lib/replace/test/snprintf.c
Normal file
29
lib/replace/test/snprintf.c
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
void foo(const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
int len;
|
||||||
|
char buf[20];
|
||||||
|
long long l = 1234567890;
|
||||||
|
l *= 100;
|
||||||
|
|
||||||
|
va_start(ap, format);
|
||||||
|
len = vsnprintf(buf, 0, format, ap);
|
||||||
|
va_end(ap);
|
||||||
|
if (len != 5) exit(1);
|
||||||
|
|
||||||
|
va_start(ap, format);
|
||||||
|
len = vsnprintf(0, 0, format, ap);
|
||||||
|
va_end(ap);
|
||||||
|
if (len != 5) exit(2);
|
||||||
|
|
||||||
|
if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(3);
|
||||||
|
|
||||||
|
if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(4);
|
||||||
|
if (snprintf(buf, 20, "%zu", 123456789) != 9 || strcmp(buf, "123456789") != 0) exit(5);
|
||||||
|
if (snprintf(buf, 20, "%2\$d %1\$d", 3, 4) != 3 || strcmp(buf, "4 3") != 0) exit(6);
|
||||||
|
if (snprintf(buf, 20, "%s", 0) < 3) exit(7);
|
||||||
|
|
||||||
|
printf("1");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
main() { foo("hello"); }
|
@ -119,7 +119,7 @@ def configure(conf):
|
|||||||
conf.CHECK_FUNCS('connect gethostbyname if_nametoindex socketpair')
|
conf.CHECK_FUNCS('connect gethostbyname if_nametoindex socketpair')
|
||||||
conf.CHECK_FUNCS('inet_ntoa inet_aton inet_ntop inet_pton')
|
conf.CHECK_FUNCS('inet_ntoa inet_aton inet_ntop inet_pton')
|
||||||
conf.CHECK_FUNCS('dirfd getdirentries getdents syslog getaddrinfo freeaddrinfo')
|
conf.CHECK_FUNCS('dirfd getdirentries getdents syslog getaddrinfo freeaddrinfo')
|
||||||
conf.CHECK_FUNCS('gai_strerror')
|
conf.CHECK_FUNCS('gai_strerror get_current_dir_name')
|
||||||
conf.CHECK_FUNCS('timegm getifaddrs freeifaddrs mmap setgroups setsid')
|
conf.CHECK_FUNCS('timegm getifaddrs freeifaddrs mmap setgroups setsid')
|
||||||
conf.CHECK_FUNCS('getgrent_r getgrgid_r getgrnam_r getgrouplist getpagesize')
|
conf.CHECK_FUNCS('getgrent_r getgrgid_r getgrnam_r getgrouplist getpagesize')
|
||||||
conf.CHECK_FUNCS('getpwent_r getpwnam_r getpwuid_r epoll_create')
|
conf.CHECK_FUNCS('getpwent_r getpwnam_r getpwuid_r epoll_create')
|
||||||
@ -161,47 +161,11 @@ def configure(conf):
|
|||||||
msg="Checking for va_copy")
|
msg="Checking for va_copy")
|
||||||
|
|
||||||
|
|
||||||
# we could also put code fragments like this in separate files,
|
conf.CHECK_CODE('#include "test/snprintf.c"',
|
||||||
# for example in test/snprintf.c
|
define="HAVE_C99_VSNPRINTF",
|
||||||
conf.check_cc(fragment='''
|
execute=1,
|
||||||
#include <sys/types.h>
|
addmain=False,
|
||||||
#include <stdio.h>
|
msg="Checking for C99 vsnprintf")
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
void foo(const char *format, ...) {
|
|
||||||
va_list ap;
|
|
||||||
int len;
|
|
||||||
char buf[20];
|
|
||||||
long long l = 1234567890;
|
|
||||||
l *= 100;
|
|
||||||
|
|
||||||
va_start(ap, format);
|
|
||||||
len = vsnprintf(buf, 0, format, ap);
|
|
||||||
va_end(ap);
|
|
||||||
if (len != 5) exit(1);
|
|
||||||
|
|
||||||
va_start(ap, format);
|
|
||||||
len = vsnprintf(0, 0, format, ap);
|
|
||||||
va_end(ap);
|
|
||||||
if (len != 5) exit(2);
|
|
||||||
|
|
||||||
if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(3);
|
|
||||||
|
|
||||||
if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(4);
|
|
||||||
if (snprintf(buf, 20, "%zu", 123456789) != 9 || strcmp(buf, "123456789") != 0) exit(5);
|
|
||||||
if (snprintf(buf, 20, "%2\$d %1\$d", 3, 4) != 3 || strcmp(buf, "4 3") != 0) exit(6);
|
|
||||||
if (snprintf(buf, 20, "%s", 0) < 3) exit(7);
|
|
||||||
|
|
||||||
printf("1");
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
main() { foo("hello"); }
|
|
||||||
''',
|
|
||||||
define_name="HAVE_C99_VSNPRINTF",
|
|
||||||
execute=1,
|
|
||||||
define_ret=1,
|
|
||||||
quote=0,
|
|
||||||
msg="Checking for C99 vsnprintf")
|
|
||||||
|
|
||||||
if Options.options.developer:
|
if Options.options.developer:
|
||||||
conf.ADD_CFLAGS('-Wall -g -Wfatal-errors -DDEVELOPER -W -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Werror-implicit-function-declaration -Wformat=2 -Wno-format-y2k')
|
conf.ADD_CFLAGS('-Wall -g -Wfatal-errors -DDEVELOPER -W -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Werror-implicit-function-declaration -Wformat=2 -Wno-format-y2k')
|
||||||
@ -209,6 +173,27 @@ main() { foo("hello"); }
|
|||||||
conf.SAMBA_CONFIG_H()
|
conf.SAMBA_CONFIG_H()
|
||||||
conf.SAMBA_BUILD_ENV()
|
conf.SAMBA_BUILD_ENV()
|
||||||
|
|
||||||
|
# look for a method of finding the list of network interfaces
|
||||||
|
for method in ['HAVE_IFACE_GETIFADDRS', 'HAVE_IFACE_AIX', 'HAVE_IFACE_IFCONF', 'HAVE_IFACE_IFREQ']:
|
||||||
|
if conf.CHECK_CODE('''
|
||||||
|
#define %s 1
|
||||||
|
#define NO_CONFIG_H 1
|
||||||
|
#define AUTOCONF_TEST 1
|
||||||
|
#define SOCKET_WRAPPER_NOT_REPLACE
|
||||||
|
#include "replace.c"
|
||||||
|
#include "inet_ntop.c"
|
||||||
|
#include "snprintf.c"
|
||||||
|
#include "getifaddrs.c"
|
||||||
|
#define getifaddrs_test main
|
||||||
|
#include "test/getifaddrs.c"
|
||||||
|
''' % method,
|
||||||
|
method,
|
||||||
|
addmain=False,
|
||||||
|
execute=True):
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def build(bld):
|
def build(bld):
|
||||||
bld.set_rpath()
|
bld.set_rpath()
|
||||||
|
|
||||||
|
@ -11,4 +11,4 @@ conf.CHECK_FUNCS_IN('flistxattr', 'attr', checklibc=True)
|
|||||||
|
|
||||||
conf.CHECK_STRUCTURE_MEMBER('struct statvfs', 'f_frsize', define='HAVE_FRSIZE')
|
conf.CHECK_STRUCTURE_MEMBER('struct statvfs', 'f_frsize', define='HAVE_FRSIZE')
|
||||||
|
|
||||||
conf.CHECK_CODE_COMPILES('gettimeofday(NULL, NULL)', 'HAVE_GETTIMEOFDAY_TZ')
|
conf.CHECK_CODE('gettimeofday(NULL, NULL)', 'HAVE_GETTIMEOFDAY_TZ', execute=False)
|
||||||
|
Reference in New Issue
Block a user