From 99e8c6b00e5399e9d22fd5a0d27dc523d9ea0373 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 3 Dec 2011 15:57:00 +0100 Subject: [PATCH] sethostname tests: Fix link error on mingw. * tests/test-sethostname1.c: New file, extracted from tests/test-sethostname.c. * tests/test-sethostname2.c: New file, extracted from tests/test-sethostname.c. * tests/test-sethostname.c: Remove file. * modules/sethostname-tests (Files): Add tests/test-sethostname1.c, tests/test-sethostname2.c. Remove tests/test-sethostname.c. (Depends-on): Add gethostname. (Makefile.am): Compile both test-sethostname1 and test-sethostname2. Link the latter with $(GETHOSTNAME_LIB). --- ChangeLog | 12 ++++++ modules/sethostname-tests | 9 +++-- tests/test-sethostname1.c | 37 +++++++++++++++++++ ...test-sethostname.c => test-sethostname2.c} | 3 -- 4 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 tests/test-sethostname1.c rename tests/{test-sethostname.c => test-sethostname2.c} (97%) diff --git a/ChangeLog b/ChangeLog index ee3a78cb88..f21d38ff6b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2011-12-03 Bruno Haible + sethostname tests: Fix link error on mingw. + * tests/test-sethostname1.c: New file, extracted from + tests/test-sethostname.c. + * tests/test-sethostname2.c: New file, extracted from + tests/test-sethostname.c. + * tests/test-sethostname.c: Remove file. + * modules/sethostname-tests (Files): Add tests/test-sethostname1.c, + tests/test-sethostname2.c. Remove tests/test-sethostname.c. + (Depends-on): Add gethostname. + (Makefile.am): Compile both test-sethostname1 and test-sethostname2. + Link the latter with $(GETHOSTNAME_LIB). + sethostname tests: Fix compilation error on mingw. * tests/test-sethostname.c: Don't include . (geteuid): Use a dummy value without uid_t. diff --git a/modules/sethostname-tests b/modules/sethostname-tests index 4435769f4c..3529abb2c9 100644 --- a/modules/sethostname-tests +++ b/modules/sethostname-tests @@ -1,13 +1,16 @@ Files: -tests/test-sethostname.c +tests/test-sethostname1.c +tests/test-sethostname2.c tests/signature.h tests/macros.h Depends-on: +gethostname configure.ac: AC_CHECK_FUNCS_ONCE([geteuid]) Makefile.am: -TESTS += test-sethostname -check_PROGRAMS += test-sethostname +TESTS += test-sethostname1 test-sethostname2 +check_PROGRAMS += test-sethostname1 test-sethostname2 +test_sethostname2_LDADD = $(LDADD) @GETHOSTNAME_LIB@ diff --git a/tests/test-sethostname1.c b/tests/test-sethostname1.c new file mode 100644 index 0000000000..86db8eae96 --- /dev/null +++ b/tests/test-sethostname1.c @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2011 Free Software Foundation, Inc. + * Written by Ben Walton. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ + +#include + +#include + +#include "signature.h" +SIGNATURE_CHECK (sethostname, int, (const char *, size_t)); + +int do_dangerous_things; + +int +main () +{ + /* Some code that has a link-time dependency to the sethostname() function + and that is likely not optimized away by compilers. */ + if (do_dangerous_things) + /* Never executed. */ + sethostname ("oprah", 5); + + return 0; +} diff --git a/tests/test-sethostname.c b/tests/test-sethostname2.c similarity index 97% rename from tests/test-sethostname.c rename to tests/test-sethostname2.c index 41d7151cee..51f92aeeb1 100644 --- a/tests/test-sethostname.c +++ b/tests/test-sethostname2.c @@ -19,9 +19,6 @@ #include -#include "signature.h" -SIGNATURE_CHECK (sethostname, int, (const char *, size_t)); - /* for HOST_NAME_MAX */ #include /* for strlen */ -- 2.39.5