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
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.
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2 Copyright (C) 2003 Free Software Foundation, Inc.
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 2, or (at your option)
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 any later version.
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program; if not, write to the Free Software Foundation,
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 #ifdef HAVE_CONFIG_H
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 # include <config.h>
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 #endif
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 /* Specification. */
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include "getdomainname.h"
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 /* Return the NIS domain name of the machine.
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 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
32 of the machine. It is also unrelated to email addresses.
4734
e73a97963451 Fix comment.
Bruno Haible <bruno@clisp.org>
parents: 4732
diff changeset
33 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
34 not using NIS.
4730
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 Put up to LEN bytes of the NIS domain name into NAME.
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 Return 0 if successful, otherwise set errno and return -1. */
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 int
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 getdomainname (char *name, size_t len)
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 return 0;
64e0a1bfa9bb New module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 }