Initial import from FreeBSD RELENG_4:
[dragonfly.git] / contrib / opie / libmissing / uname.c
1 /* uname.c: A replacement for the uname function (sort of)
2
3 %%% copyright-cmetz
4 This software is Copyright 1996 by Craig Metz, All Rights Reserved.
5 The Inner Net License Version 2 applies to this software.
6 You should have received a copy of the license with this software. If
7 you didn't get a copy, you may request one from <license@inner.net>.
8
9         History:
10
11         Modified by cmetz for OPIE 2.3. Ifdef around gethostname().
12         Created by cmetz for OPIE 2.2.
13 */
14 #include "opie_cfg.h"
15 #if HAVE_SYS_PARAM_H
16 #include <sys/param.h>
17 #endif /* HAVE_SYS_PARAM_H */
18 #include "opie.h"
19
20 int uname FUNCTION(struct utsname *buf)
21 {
22 #if HAVE_GETHOSTNAME
23         char hostname[MAXHOSTNAMELEN], *c;
24
25         memset(buf, 0, sizeof(buf));
26
27         if (gethostname(hostname, sizeof(hostname)-1) < 0)
28                 return -1;
29
30         hostname[sizeof(hostname) - 1] = 0;
31
32         if (c = strchr(hostname, '.')) {
33                 *c = 0;
34         }
35
36         strncpy(buf->nodename, hostname, sizeof(buf->nodename) - 1);
37         return 0;
38 #else /* HAVE_GETHOSTNAME */
39         strncpy(buf->nodename, "unknown", sizeof(buf->nodename) - 1);
40         return 0;
41 #endif /* HAVE_GETHOSTNAME */
42 }