Mercurial > hg > octave-kai > gnulib-hg
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 |
rev | line source |
---|---|
4731 | 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 | 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 2, or (at your option) | |
8 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, 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 | 18 |
19 /* Based on xgethostname.c, written by Jim Meyering. */ | |
20 | |
7584
a88f85e4728f
* lib/arcfour.c: Assume config.h.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
21 #include <config.h> |
4731 | 22 |
23 /* Specification. */ | |
24 #include "xgetdomainname.h" | |
25 | |
26 /* Get getdomainname. */ | |
27 #include "getdomainname.h" | |
28 | |
29 /* Get errno. */ | |
30 #include <errno.h> | |
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 | 35 #include "xalloc.h" |
36 | |
37 #ifndef INITIAL_DOMAINNAME_LENGTH | |
38 # define INITIAL_DOMAINNAME_LENGTH 34 | |
39 #endif | |
40 | |
41 /* Return the NIS domain name of the machine, in malloc'd storage. | |
42 WARNING! The NIS domain name is unrelated to the fully qualified host name | |
43 of the machine. It is also unrelated to email addresses. | |
4734 | 44 WARNING! The NIS domain name is usually the empty string or "(none)" when |
45 not using NIS. | |
4731 | 46 If malloc fails, exit. |
47 Upon any other failure, set errno and return NULL. */ | |
48 char * | |
49 xgetdomainname (void) | |
50 { | |
51 char *domainname; | |
52 size_t size; | |
53 | |
54 size = INITIAL_DOMAINNAME_LENGTH; | |
55 domainname = xmalloc (size); | |
56 while (1) | |
57 { | |
58 int k = size - 1; | |
59 int err; | |
60 | |
61 errno = 0; | |
62 domainname[k] = '\0'; | |
63 err = getdomainname (domainname, size); | |
64 if (err >= 0 && domainname[k] == '\0') | |
65 break; | |
66 else if (err < 0 && errno != EINVAL) | |
67 { | |
68 int saved_errno = errno; | |
69 free (domainname); | |
70 errno = saved_errno; | |
71 return NULL; | |
72 } | |
73 size *= 2; | |
74 domainname = xrealloc (domainname, size); | |
75 } | |
76 | |
77 return domainname; | |
78 } |