Mercurial > hg > octave-shane > gnulib-hg
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 |
rev | line source |
---|---|
4730 | 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 | 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 | 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 | 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 | |
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 | 17 |
18 /* Written by Simon Josefsson. */ | |
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 | 21 |
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 | 24 |
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 | 27 |
28 /* Return the NIS domain name of the machine. | |
29 WARNING! The NIS domain name is unrelated to the fully qualified host name | |
30 of the machine. It is also unrelated to email addresses. | |
4734 | 31 WARNING! The NIS domain name is usually the empty string or "(none)" when |
32 not using NIS. | |
4730 | 33 |
34 Put up to LEN bytes of the NIS domain name into NAME. | |
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 | 37 Return 0 if successful, otherwise set errno and return -1. */ |
38 int | |
39 getdomainname (char *name, size_t len) | |
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 | 52 return 0; |
53 } |