Mercurial > gnulib
annotate tests/test-gethostname.c @ 40231:9b3c79fdfe0b
strtod: fix clash with strtold
Problem reported for RHEL 5 by Jesse Caldwell (Bug#34817).
* lib/strtod.c (compute_minus_zero, minus_zero):
Simplify by remving the macro / external variable,
and having just a function. User changed. This avoids
the need for an external variable that might clash.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Mon, 11 Mar 2019 16:40:29 -0700 |
parents | b06060465f09 |
children |
rev | line source |
---|---|
9632
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
1 /* |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
2 * Copyright (C) 2008-2019 Free Software Foundation, Inc. |
9632
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
3 * Written by Simon Josefsson. |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
4 * |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
5 * This program is free software: you can redistribute it and/or modify |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
6 * it under the terms of the GNU General Public License as published by |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
7 * the Free Software Foundation; either version 3 of the License, or |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
8 * (at your option) any later version. |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
9 * |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
10 * This program is distributed in the hope that it will be useful, |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
13 * GNU General Public License for more details. |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
14 * |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License |
19190 | 16 * along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
9632
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
17 |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
18 #include <config.h> |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
19 |
11754
796e82b1141e
Make the gethostname test compile again.
Bruno Haible <bruno@clisp.org>
parents:
11753
diff
changeset
|
20 /* Get gethostname() declaration. */ |
10692
b867b19bccb3
Add gethostname() declaration to <unistd.h>.
Bruno Haible <bruno@clisp.org>
parents:
9634
diff
changeset
|
21 #include <unistd.h> |
12489 | 22 |
23 #include "signature.h" | |
24 SIGNATURE_CHECK (gethostname, int, (char *, size_t)); | |
25 | |
11754
796e82b1141e
Make the gethostname test compile again.
Bruno Haible <bruno@clisp.org>
parents:
11753
diff
changeset
|
26 /* Get HOST_NAME_MAX definition. */ |
796e82b1141e
Make the gethostname test compile again.
Bruno Haible <bruno@clisp.org>
parents:
11753
diff
changeset
|
27 #include <limits.h> |
10692
b867b19bccb3
Add gethostname() declaration to <unistd.h>.
Bruno Haible <bruno@clisp.org>
parents:
9634
diff
changeset
|
28 |
9632
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
29 #include <stdio.h> |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
30 #include <string.h> |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
31 #include <errno.h> |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
32 |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
33 #define NOHOSTNAME "magic-gnulib-test-string" |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
34 |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
35 int |
12482
11bc92a9e2bc
gnulib-common: prefer _GL_UNUSED over _UNUSED_PARAMETER_
Eric Blake <ebb9@byu.net>
parents:
12210
diff
changeset
|
36 main (int argc, char *argv[] _GL_UNUSED) |
9632
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
37 { |
11753
b465c20bb96c
Ensure HOST_NAME_MAX as part of the gethostname module.
Bruno Haible <bruno@clisp.org>
parents:
10692
diff
changeset
|
38 char buf[HOST_NAME_MAX]; |
9632
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
39 int rc; |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
40 |
11753
b465c20bb96c
Ensure HOST_NAME_MAX as part of the gethostname module.
Bruno Haible <bruno@clisp.org>
parents:
10692
diff
changeset
|
41 if (strlen (NOHOSTNAME) >= HOST_NAME_MAX) |
b465c20bb96c
Ensure HOST_NAME_MAX as part of the gethostname module.
Bruno Haible <bruno@clisp.org>
parents:
10692
diff
changeset
|
42 { |
b465c20bb96c
Ensure HOST_NAME_MAX as part of the gethostname module.
Bruno Haible <bruno@clisp.org>
parents:
10692
diff
changeset
|
43 printf ("HOST_NAME_MAX impossibly small?! %d\n", HOST_NAME_MAX); |
b465c20bb96c
Ensure HOST_NAME_MAX as part of the gethostname module.
Bruno Haible <bruno@clisp.org>
parents:
10692
diff
changeset
|
44 return 2; |
b465c20bb96c
Ensure HOST_NAME_MAX as part of the gethostname module.
Bruno Haible <bruno@clisp.org>
parents:
10692
diff
changeset
|
45 } |
b465c20bb96c
Ensure HOST_NAME_MAX as part of the gethostname module.
Bruno Haible <bruno@clisp.org>
parents:
10692
diff
changeset
|
46 |
9632
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
47 strcpy (buf, NOHOSTNAME); |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
48 |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
49 rc = gethostname (buf, sizeof (buf)); |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
50 |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
51 if (rc != 0) |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
52 { |
9634 | 53 printf ("gethostname failed, rc %d errno %d\n", rc, errno); |
9632
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
54 return 1; |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
55 } |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
56 |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
57 if (strcmp (buf, NOHOSTNAME) == 0) |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
58 { |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
59 printf ("gethostname left buffer untouched.\n"); |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
60 return 1; |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
61 } |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
62 |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
63 if (argc > 1) |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
64 printf ("hostname: %s\n", buf); |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
65 |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
66 return 0; |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
67 } |