Mercurial > hg > octave-lojdl > gnulib-hg
annotate tests/test-gethostname.c @ 10692:b867b19bccb3
Add gethostname() declaration to <unistd.h>.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Tue, 21 Oct 2008 13:13:09 +0200 |
parents | ae66ca8fbe28 |
children | b465c20bb96c |
rev | line source |
---|---|
9632
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
1 /* |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
2 * Copyright (C) 2008 Free Software Foundation |
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 |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
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 |
10692
b867b19bccb3
Add gethostname() declaration to <unistd.h>.
Bruno Haible <bruno@clisp.org>
parents:
9634
diff
changeset
|
20 #include <unistd.h> |
b867b19bccb3
Add gethostname() declaration to <unistd.h>.
Bruno Haible <bruno@clisp.org>
parents:
9634
diff
changeset
|
21 |
9632
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
22 #include <stdio.h> |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
23 #include <string.h> |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
24 #include <errno.h> |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
25 |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
26 #define NOHOSTNAME "magic-gnulib-test-string" |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
27 |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
28 int |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
29 main (int argc, char *argv[]) |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
30 { |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
31 char buf[2500]; |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
32 int rc; |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
33 |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
34 strcpy (buf, NOHOSTNAME); |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
35 |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
36 rc = gethostname (buf, sizeof (buf)); |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
37 |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
38 if (rc != 0) |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
39 { |
9634 | 40 printf ("gethostname failed, rc %d errno %d\n", rc, errno); |
9632
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
41 return 1; |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
42 } |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
43 |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
44 if (strcmp (buf, NOHOSTNAME) == 0) |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
45 { |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
46 printf ("gethostname left buffer untouched.\n"); |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
47 return 1; |
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 |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
50 if (argc > 1) |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
51 printf ("hostname: %s\n", buf); |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
52 |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
53 return 0; |
2afb25a39ffb
New module gethostname-tests.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
54 } |