usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-gethostname.c
blobd60cf206aed7d5b7ca699e9e0e39b37deac5730f
1 /*
2 * Copyright (C) 2008-2024 Free Software Foundation, Inc.
3 * Written by Simon Josefsson.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 #include <config.h>
20 /* Get gethostname() declaration. */
21 #include <unistd.h>
23 #include "signature.h"
24 SIGNATURE_CHECK (gethostname, int, (char *, size_t));
26 /* Get HOST_NAME_MAX definition. */
27 #include <limits.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <errno.h>
33 #define NOHOSTNAME "magic-gnulib-test-string"
35 int
36 main (int argc, _GL_UNUSED char *argv[])
38 char buf[HOST_NAME_MAX];
39 int rc;
41 if (strlen (NOHOSTNAME) >= HOST_NAME_MAX)
43 printf ("HOST_NAME_MAX impossibly small?! %d\n", HOST_NAME_MAX);
44 return 2;
47 strcpy (buf, NOHOSTNAME);
49 rc = gethostname (buf, sizeof (buf));
51 if (rc != 0)
53 printf ("gethostname failed, rc %d errno %d\n", rc, errno);
54 return 1;
57 if (strcmp (buf, NOHOSTNAME) == 0)
59 printf ("gethostname left buffer untouched.\n");
60 return 1;
63 if (argc > 1)
64 printf ("hostname: %s\n", buf);
66 return 0;