Mercurial > hg > octave-kai > gnulib-hg
annotate lib/getdomainname.c @ 5459:e88a820ff3bb
Add log for human.h, xgetcwd.c (import from coreutils).
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Wed, 17 Nov 2004 07:32:27 +0000 |
parents | e73a97963451 |
children | a48fb0e98c8c |
rev | line source |
---|---|
4730 | 1 /* getdomainname emulation for systems that doesn't have it. |
2 Copyright (C) 2003 Free Software Foundation, Inc. | |
3 | |
4 This program is free software; you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 2, or (at your option) | |
7 any later version. | |
8 | |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
15 along with this program; if not, write to the Free Software Foundation, | |
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
17 | |
18 /* Written by Simon Josefsson. */ | |
19 | |
20 #ifdef HAVE_CONFIG_H | |
21 # include <config.h> | |
22 #endif | |
23 | |
24 /* Specification. */ | |
25 #include "getdomainname.h" | |
26 | |
27 #include <string.h> | |
4732
3f6a23a84d27
Return -1/EINVAL when the buffer is too small.
Bruno Haible <bruno@clisp.org>
parents:
4730
diff
changeset
|
28 #include <errno.h> |
4730 | 29 |
30 /* Return the NIS domain name of the machine. | |
31 WARNING! The NIS domain name is unrelated to the fully qualified host name | |
32 of the machine. It is also unrelated to email addresses. | |
4734 | 33 WARNING! The NIS domain name is usually the empty string or "(none)" when |
34 not using NIS. | |
4730 | 35 |
36 Put up to LEN bytes of the NIS domain name into NAME. | |
37 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
|
38 If the NIS domain name is longer than LEN, set errno = EINVAL and return -1. |
4730 | 39 Return 0 if successful, otherwise set errno and return -1. */ |
40 int | |
41 getdomainname (char *name, size_t len) | |
42 { | |
4732
3f6a23a84d27
Return -1/EINVAL when the buffer is too small.
Bruno Haible <bruno@clisp.org>
parents:
4730
diff
changeset
|
43 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
|
44 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
|
45 |
3f6a23a84d27
Return -1/EINVAL when the buffer is too small.
Bruno Haible <bruno@clisp.org>
parents:
4730
diff
changeset
|
46 if (result_len > len) |
3f6a23a84d27
Return -1/EINVAL when the buffer is too small.
Bruno Haible <bruno@clisp.org>
parents:
4730
diff
changeset
|
47 { |
3f6a23a84d27
Return -1/EINVAL when the buffer is too small.
Bruno Haible <bruno@clisp.org>
parents:
4730
diff
changeset
|
48 errno = EINVAL; |
3f6a23a84d27
Return -1/EINVAL when the buffer is too small.
Bruno Haible <bruno@clisp.org>
parents:
4730
diff
changeset
|
49 return -1; |
3f6a23a84d27
Return -1/EINVAL when the buffer is too small.
Bruno Haible <bruno@clisp.org>
parents:
4730
diff
changeset
|
50 } |
3f6a23a84d27
Return -1/EINVAL when the buffer is too small.
Bruno Haible <bruno@clisp.org>
parents:
4730
diff
changeset
|
51 memcpy (name, result, result_len); |
3f6a23a84d27
Return -1/EINVAL when the buffer is too small.
Bruno Haible <bruno@clisp.org>
parents:
4730
diff
changeset
|
52 if (result_len < len) |
3f6a23a84d27
Return -1/EINVAL when the buffer is too small.
Bruno Haible <bruno@clisp.org>
parents:
4730
diff
changeset
|
53 name[result_len] = '\0'; |
4730 | 54 return 0; |
55 } |