annotate lib/xgetdomainname.c @ 7584:a88f85e4728f

* lib/arcfour.c: Assume config.h. * lib/arctwo.c: Likewise. * lib/base64.c: Likewise. * lib/check-version.c: Likewise. * lib/crc.c: Likewise. * lib/des.c: Likewise. * lib/gc-gnulib.c: Likewise. * lib/gc-libgcrypt.c: Likewise. * lib/gc-pbkdf2-sha1.c: Likewise. * lib/getaddrinfo.c: Likewise. * lib/getdelim.c: Likewise. * lib/getline.c: Likewise. * lib/hmac-md5.c: Likewise. * lib/hmac-sha1.c: Likewise. * lib/iconvme.c: Likewise. * lib/md2.c: Likewise. * lib/md4.c: Likewise. * lib/memxor.c: Likewise. * lib/read-file.c: Likewise. * lib/readline.c: Likewise. * lib/rijndael-alg-fst.c: Likewise. * lib/rijndael-api-fst.c: Likewise. * lib/xgetdomainname.c: Likewise.
author Eric Blake <ebb9@byu.net>
date Sun, 29 Oct 2006 21:52:55 +0000 (2006-10-29)
parents a48fb0e98c8c
children bbbbbf4cd1c5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4731
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* xgetdomainname.c -- Return the NIS domain name, without size limitations.
7584
a88f85e4728f * lib/arcfour.c: Assume config.h.
Eric Blake <ebb9@byu.net>
parents: 5848
diff changeset
2 Copyright (C) 1992, 1996, 2000, 2001, 2003, 2004, 2006 Free Software
a88f85e4728f * lib/arcfour.c: Assume config.h.
Eric Blake <ebb9@byu.net>
parents: 5848
diff changeset
3 Foundation, Inc.
4731
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 This program is free software; you can redistribute it and/or modify
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 the Free Software Foundation; either version 2, or (at your option)
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8 any later version.
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 GNU General Public License for more details.
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 along with this program; if not, write to the Free Software Foundation,
5848
a48fb0e98c8c *** empty log message ***
Paul Eggert <eggert@cs.ucla.edu>
parents: 5139
diff changeset
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
4731
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 /* Based on xgethostname.c, written by Jim Meyering. */
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
7584
a88f85e4728f * lib/arcfour.c: Assume config.h.
Eric Blake <ebb9@byu.net>
parents: 5848
diff changeset
21 #include <config.h>
4731
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 /* Specification. */
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include "xgetdomainname.h"
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 /* Get getdomainname. */
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #include "getdomainname.h"
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 /* Get errno. */
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 #include <errno.h>
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31
5139
dc1fbdf89b31 2004-08-01 Simon Josefsson <jas@extundo.com>
Bruno Haible <bruno@clisp.org>
parents: 4734
diff changeset
32 /* Get free. */
dc1fbdf89b31 2004-08-01 Simon Josefsson <jas@extundo.com>
Bruno Haible <bruno@clisp.org>
parents: 4734
diff changeset
33 #include <stdlib.h>
dc1fbdf89b31 2004-08-01 Simon Josefsson <jas@extundo.com>
Bruno Haible <bruno@clisp.org>
parents: 4734
diff changeset
34
4731
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 #include "xalloc.h"
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 #ifndef INITIAL_DOMAINNAME_LENGTH
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 # define INITIAL_DOMAINNAME_LENGTH 34
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 #endif
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 /* Return the NIS domain name of the machine, in malloc'd storage.
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 WARNING! The NIS domain name is unrelated to the fully qualified host name
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 of the machine. It is also unrelated to email addresses.
4734
e73a97963451 Fix comment.
Bruno Haible <bruno@clisp.org>
parents: 4731
diff changeset
44 WARNING! The NIS domain name is usually the empty string or "(none)" when
e73a97963451 Fix comment.
Bruno Haible <bruno@clisp.org>
parents: 4731
diff changeset
45 not using NIS.
4731
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 If malloc fails, exit.
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 Upon any other failure, set errno and return NULL. */
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 char *
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 xgetdomainname (void)
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 {
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 char *domainname;
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 size_t size;
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 size = INITIAL_DOMAINNAME_LENGTH;
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 domainname = xmalloc (size);
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 while (1)
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 {
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 int k = size - 1;
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 int err;
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 errno = 0;
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 domainname[k] = '\0';
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 err = getdomainname (domainname, size);
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 if (err >= 0 && domainname[k] == '\0')
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 break;
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 else if (err < 0 && errno != EINVAL)
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 {
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 int saved_errno = errno;
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 free (domainname);
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 errno = saved_errno;
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 return NULL;
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 }
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 size *= 2;
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 domainname = xrealloc (domainname, size);
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 }
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 return domainname;
d160b0c1905e New modules 'xgetdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 }