maint: update copyright
[gnulib.git] / tests / test-getdomainname.c
1 /*
2  * Copyright (C) 2008-2014 Free Software Foundation, Inc.
3  * Written by Simon Josefsson.
4  *
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.
9  *
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.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17
18 #include <config.h>
19
20 /* Get getdomainname() declaration.  */
21 #include <unistd.h>
22
23 #include "signature.h"
24 SIGNATURE_CHECK (getdomainname, int, (char *, size_t));
25
26 #include <stdio.h>
27 #include <string.h>
28 #include <errno.h>
29
30 #define YPMAXDOMAIN 64
31
32 #define NODOMAINNAME "magic-gnulib-test-string"
33
34 int
35 main (int argc, char *argv[] _GL_UNUSED)
36 {
37   char buf[YPMAXDOMAIN];
38   int rc;
39
40   if (strlen (NODOMAINNAME) >= YPMAXDOMAIN)
41     {
42       printf ("YPMAXDOMAIN impossibly small?! %d\n", YPMAXDOMAIN);
43       return 2;
44     }
45
46   strcpy (buf, NODOMAINNAME);
47
48   rc = getdomainname (buf, sizeof (buf));
49
50   if (rc != 0)
51     {
52       printf ("getdomainname failed, rc %d errno %d\n", rc, errno);
53       return 1;
54     }
55
56   if (strcmp (buf, NODOMAINNAME) == 0)
57     {
58       printf ("getdomainname left buffer untouched.\n");
59       return 1;
60     }
61
62   if (argc > 1)
63     printf ("domainname: %s\n", buf);
64
65   return 0;
66 }