annotate lib/getdomainname.c @ 10661:65c9436dc0d3

Move the getdomainname() declaration to <unistd.h>.
author Bruno Haible <bruno@clisp.org>
date Sun, 19 Oct 2008 03:36:00 +0200
parents bbbbbf4cd1c5
children e8d2c6fc33ad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4730
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* getdomainname emulation for systems that doesn't have it.
7302
8a1a9361108c * _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
2
10661
65c9436dc0d3 Move the getdomainname() declaration to <unistd.h>.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3 Copyright (C) 2003, 2006, 2008 Free Software Foundation, Inc.
4730
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7302
diff changeset
5 This program is free software: you can redistribute it and/or modify
4730
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7302
diff changeset
7 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7302
diff changeset
8 (at your option) any later version.
4730
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 GNU General Public License for more details.
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7302
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
4730
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 /* Written by Simon Josefsson. */
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
7302
8a1a9361108c * _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
20 #include <config.h>
4730
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 /* Specification. */
10661
65c9436dc0d3 Move the getdomainname() declaration to <unistd.h>.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
23 #include <unistd.h>
4730
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include <string.h>
4732
3f6a23a84d27 Return -1/EINVAL when the buffer is too small.
Bruno Haible <bruno@clisp.org>
parents: 4730
diff changeset
26 #include <errno.h>
4730
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 /* Return the NIS domain name of the machine.
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 WARNING! The NIS domain name is unrelated to the fully qualified host name
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 of the machine. It is also unrelated to email addresses.
4734
e73a97963451 Fix comment.
Bruno Haible <bruno@clisp.org>
parents: 4732
diff changeset
31 WARNING! The NIS domain name is usually the empty string or "(none)" when
e73a97963451 Fix comment.
Bruno Haible <bruno@clisp.org>
parents: 4732
diff changeset
32 not using NIS.
4730
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 Put up to LEN bytes of the NIS domain name into NAME.
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 Null terminate it if the name is shorter than LEN.
4732
3f6a23a84d27 Return -1/EINVAL when the buffer is too small.
Bruno Haible <bruno@clisp.org>
parents: 4730
diff changeset
36 If the NIS domain name is longer than LEN, set errno = EINVAL and return -1.
4730
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 Return 0 if successful, otherwise set errno and return -1. */
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 int
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 getdomainname (char *name, size_t len)
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 {
4732
3f6a23a84d27 Return -1/EINVAL when the buffer is too small.
Bruno Haible <bruno@clisp.org>
parents: 4730
diff changeset
41 const char *result = ""; /* Hardcode your domain name if you want. */
3f6a23a84d27 Return -1/EINVAL when the buffer is too small.
Bruno Haible <bruno@clisp.org>
parents: 4730
diff changeset
42 size_t result_len = strlen (result);
3f6a23a84d27 Return -1/EINVAL when the buffer is too small.
Bruno Haible <bruno@clisp.org>
parents: 4730
diff changeset
43
3f6a23a84d27 Return -1/EINVAL when the buffer is too small.
Bruno Haible <bruno@clisp.org>
parents: 4730
diff changeset
44 if (result_len > len)
3f6a23a84d27 Return -1/EINVAL when the buffer is too small.
Bruno Haible <bruno@clisp.org>
parents: 4730
diff changeset
45 {
3f6a23a84d27 Return -1/EINVAL when the buffer is too small.
Bruno Haible <bruno@clisp.org>
parents: 4730
diff changeset
46 errno = EINVAL;
3f6a23a84d27 Return -1/EINVAL when the buffer is too small.
Bruno Haible <bruno@clisp.org>
parents: 4730
diff changeset
47 return -1;
3f6a23a84d27 Return -1/EINVAL when the buffer is too small.
Bruno Haible <bruno@clisp.org>
parents: 4730
diff changeset
48 }
3f6a23a84d27 Return -1/EINVAL when the buffer is too small.
Bruno Haible <bruno@clisp.org>
parents: 4730
diff changeset
49 memcpy (name, result, result_len);
3f6a23a84d27 Return -1/EINVAL when the buffer is too small.
Bruno Haible <bruno@clisp.org>
parents: 4730
diff changeset
50 if (result_len < len)
3f6a23a84d27 Return -1/EINVAL when the buffer is too small.
Bruno Haible <bruno@clisp.org>
parents: 4730
diff changeset
51 name[result_len] = '\0';
4730
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 return 0;
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 }