This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #include <config.h>
19
20
21 #include <unistd.h>
22
23 #include "signature.h"
24 SIGNATURE_CHECK (gethostname, int, (char *, size_t));
25
26
27 #include <limits.h>
28
29 #include <stdio.h>
30 #include <string.h>
31 #include <errno.h>
32
33 #define NOHOSTNAME "magic-gnulib-test-string"
34
35 int
36 main (int argc, _GL_UNUSED char *argv[])
37 {
38 char buf[HOST_NAME_MAX];
39 int rc;
40
41 if (strlen (NOHOSTNAME) >= HOST_NAME_MAX)
42 {
43 printf ("HOST_NAME_MAX impossibly small?! %d\n", HOST_NAME_MAX);
44 return 2;
45 }
46
47 strcpy (buf, NOHOSTNAME);
48
49 rc = gethostname (buf, sizeof (buf));
50
51 if (rc != 0)
52 {
53 printf ("gethostname failed, rc %d errno %d\n", rc, errno);
54 return 1;
55 }
56
57 if (strcmp (buf, NOHOSTNAME) == 0)
58 {
59 printf ("gethostname left buffer untouched.\n");
60 return 1;
61 }
62
63 if (argc > 1)
64 printf ("hostname: %s\n", buf);
65
66 return 0;
67 }