openat: don’t close (-1)
[gnulib.git] / tests / test-getdomainname.c
blobbe4fae5aa9756dfb1b1156a058d2aaf14a397a41
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 getdomainname() declaration. */
21 #include <unistd.h>
23 #include "signature.h"
24 SIGNATURE_CHECK (getdomainname, int, (char *, size_t));
26 #include <stdio.h>
27 #include <string.h>
28 #include <errno.h>
30 #define YPMAXDOMAIN 64
32 #define NODOMAINNAME "magic-gnulib-test-string"
34 int
35 main (int argc, _GL_UNUSED char *argv[])
37 char buf[YPMAXDOMAIN];
38 int rc;
40 if (strlen (NODOMAINNAME) >= YPMAXDOMAIN)
42 printf ("YPMAXDOMAIN impossibly small?! %d\n", YPMAXDOMAIN);
43 return 2;
46 strcpy (buf, NODOMAINNAME);
48 rc = getdomainname (buf, sizeof (buf));
50 if (rc != 0)
52 printf ("getdomainname failed, rc %d errno %d\n", rc, errno);
53 return 1;
56 if (strcmp (buf, NODOMAINNAME) == 0)
58 printf ("getdomainname left buffer untouched.\n");
59 return 1;
62 if (argc > 1)
63 printf ("domainname: %s\n", buf);
65 return 0;