2 atlc - arbitrary transmission line calculator, for the analysis of
3 transmission lines are directional couplers.
5 Copyright (C) 2002. Dr. David Kirkby, PhD (G8WRB).
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either package_version 2
10 of the License, or (at your option) any later package_version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22 Dr. David Kirkby, e-mail drkirkby@ntlworld.com
25 /* Try to get data. This should work on just about any
26 system going. However, the amount of data collected
27 is not very much, so other C files, that try to
28 get more information are about. */
45 #ifdef HAVE_SYS_UTSNAME_H
46 #include <sys/utsname.h>
60 #define BYTES_PER_MB 1048576
62 int try_portable(struct computer_data *data)
65 /* Check for both uname and sysconf. Any UNIX system should
66 have both, but since someone has done a Windows port, I
67 will start by assming neither sysconf or uname exist */
71 #ifdef HAVE_SYSCONF /* Most UNIX systems have it */
77 #ifdef HAVE_UNAME /* Most if not all UNIX system have it */
78 int ret, i, string_length;
79 struct utsname operating_system;
81 ret=uname(&operating_system);
85 fprintf(stderr,"failure in call to uname in try_portable.c errno=%d\n", errno);
87 fprintf(stderr,"failure in call to uname in try_portable.c\n");
88 #endif /* #ifdef HAVE_ERRNO_H */
91 else /* the call to uname succeesed */
93 /* There is a distint posibility that some data in the operating
94 system structure will have spaces in it. This will screw things
95 up, since benchmark.test is expect a fixed number of arguments.
96 Hence to avoid this, any spaces are replaced by underscores */
98 strcpy(data->sysname,operating_system.sysname);
99 string_length=strlen(data->sysname);
100 for(i=0;i<string_length; ++i)
102 if (data->sysname[i] == ' ')
103 data->sysname[i]='_';
106 /* nodename should be safe, but I'll take no chances */
107 strcpy(data->nodename,operating_system.nodename);
108 string_length=strlen(data->nodename);
109 for(i=0;i<string_length; ++i)
111 if (data->nodename[i] == ' ')
112 data->nodename[i]='_';
115 /* not so with release */
116 strcpy(data->release,operating_system.release);
117 string_length=strlen(data->release);
118 for(i=0;i<string_length; ++i)
120 if (data->release[i] == ' ')
121 data->release[i]='_';
125 strcpy(data->version,operating_system.version);
126 string_length=strlen(data->version);
127 for(i=0;i<string_length; ++i)
129 if (data->version[i] == ' ')
130 data->version[i]='_';
133 strcpy(data->machine,operating_system.machine);
134 string_length=strlen(data->machine);
135 for(i=0;i<string_length; ++i)
137 if (data->machine[i] == ' ')
138 data->machine[i]='_';
140 } /* end of code executed if uname() passed */
141 #endif /* End of #ifdef HAVE_UNAME */
143 /* Try to get the number of processors online. This seems to be
144 at least semi portable, as its used by both AIX and Solaris.
147 #ifdef HAVE_SYSCONF /* many systems seem to have sysconf(),
148 which takes an integer argument and returns a long. The
149 arugment detemines what gets returned. */
151 #ifdef _SC_NPROCESSORS_ONLN /* Get the CPUs online */
152 if(sysconf(_SC_NPROCESSORS_ONLN) >= 1)
153 sprintf(data->cpus,"%ld",sysconf(_SC_NPROCESSORS_ONLN));
156 /* Obtain the RAM. This is a bit of a hack using doubles for
157 this, but longs overflow and long long is not strictly
158 in the ANSI standard. */
160 #ifdef _SC_PHYS_PAGES
163 /* This might look a bit of a hack to use a double to compute
164 memory size in Mb, when any machine now will have an
165 integer multiple of Mb. However, the problem is that the
166 way to do this (multiplying the size of a memory page in
167 bytes by the number of memory pages), produce the ram in bytes.
168 That will likely overflow a long on a 32-bit machine. So a
169 double is used, divided by the number of bytes per Mb, then
172 I hope that makes some sense */
174 if ((long) sysconf(_SC_PHYS_PAGES) > 0L)
176 if ((long) sysconf(_SC_PAGESIZE) > 0L)
178 ram=(double) sysconf(_SC_PAGESIZE);
179 ram*= (double) sysconf(_SC_PHYS_PAGES);
181 ram=ram/BYTES_PER_MB;
182 sprintf(data->memory,"%ld",(long) (ram+0.05));
186 #endif /* End of HAVE__SC_PHYS_PAGES */
187 #endif /* End of HAVE__SC_PHYS_PAGES */
188 #endif /* End of #ifdef HAVE_SYSCONF */