1 /*
2 * Copyright (c) 2000 Sasha Vasko <sasha at aftercode.net>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library 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 GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19 #include "config.h"
20
21 #include <string.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <sys/types.h>
25
26 #include "astypes.h"
27 #include "output.h"
28 #include "mystring.h"
29 #include "safemalloc.h"
30 #include "os.h"
31 #include "audit.h"
32
33 #if defined (__sun__) && defined (SVR4)
34 /* Solaris has sysinfo instead of gethostname. */
35 #include <sys/systeminfo.h>
36 #endif
37
38 #if HAVE_UNAME
39 /* define mygethostname() by using uname() */
40
41 #include <sys/utsname.h>
42
43 Bool
mygethostname(char * client,size_t length)44 mygethostname (char *client, size_t length)
45 {
46 struct utsname sysname;
47
48 if( client == NULL )
49 return 0;
50 uname (&sysname);
51 strncpy (client, sysname.nodename, length);
52 return (*client != '\0');
53 }
54
55 /* return a string indicating the OS type (i.e. "Linux", "SINIX-D", ... ) */
56 char*
mygetostype(void)57 mygetostype (void)
58 {
59 char* str = NULL;
60 struct utsname sysname;
61
62 if (uname (&sysname) != -1)
63 str = mystrdup(sysname.sysname);
64
65 return str;
66 }
67
68 #else
69 #if HAVE_GETHOSTNAME
70 /* define mygethostname() by using gethostname() :-) */
71
72 Bool
mygethostname(char * client,size_t length)73 mygethostname (char *client, size_t length)
74 {
75 if( client == NULL )
76 return False;
77 gethostname (client, length);
78 return (*client != '\0');
79 }
80
81 #else
82 Bool
mygethostname(char * client,size_t length)83 mygethostname (char *client, size_t length)
84 {
85 *client = 0;
86 return False ;
87 }
88
89 #endif
90
91 char*
mygetostype(void)92 mygetostype (void)
93 {
94 return NULL;
95 }
96
97 #endif
98
99 int
get_fd_width(void)100 get_fd_width (void)
101 {
102 int r;
103
104 #ifdef _SC_OPEN_MAX
105 r = sysconf (_SC_OPEN_MAX);
106 #else
107 r = getdtablesize ();
108 #endif
109 #ifdef FD_SETSIZE
110 return (r > FD_SETSIZE ? FD_SETSIZE : r);
111 #else
112 return r;
113 #endif
114 }
115