aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2000-12-06 23:17:37 +0000
committerEric Andersen <andersen@codepoet.org>2000-12-06 23:17:37 +0000
commitbc5941a5408c9b55628b1757d0ea89df1218ec5c (patch)
tree6e0ea07a1546037736c35fed783d67279ed5b56f
parentbfa54143f62a0de98d2b0c47b64f73c6fa25cdae (diff)
downloadbusybox-w32-bc5941a5408c9b55628b1757d0ea89df1218ec5c.tar.gz
busybox-w32-bc5941a5408c9b55628b1757d0ea89df1218ec5c.tar.bz2
busybox-w32-bc5941a5408c9b55628b1757d0ea89df1218ec5c.zip
Close but #1071...
-rw-r--r--init.c31
-rw-r--r--init/init.c31
2 files changed, 28 insertions, 34 deletions
diff --git a/init.c b/init.c
index 17e605ba0..c4440894c 100644
--- a/init.c
+++ b/init.c
@@ -288,30 +288,27 @@ void set_term(int fd)
288 tcsetattr(fd, TCSANOW, &tty); 288 tcsetattr(fd, TCSANOW, &tty);
289} 289}
290 290
291/* How much memory does this machine have? */ 291/* How much memory does this machine have?
292 Units are kBytes to avoid overflow on 4GB machines */
292static int check_free_memory() 293static int check_free_memory()
293{ 294{
294 struct sysinfo info; 295 struct sysinfo info;
296 unsigned int result, u, s=10;
295 297
296 /* Pre initialize mem_unit in case this kernel is something prior to
297 * the linux 2.4 kernel (which will actually fill in mem_unit... */
298 sysinfo(&info);
299 if (sysinfo(&info) != 0) { 298 if (sysinfo(&info) != 0) {
300 printf("Error checking free memory: %s\n", strerror(errno)); 299 perrorMsg("Error checking free memory: ");
301 return -1; 300 return -1;
302 } 301 }
303 /* Kernels prior to 2.4.x will return info.mem_unit==0, so cope... */ 302
304 if (info.mem_unit==0) { 303 /* Kernels 2.0.x and 2.2.x return info.mem_unit==0 with values in bytes.
305 info.mem_unit=1; 304 * Kernels 2.4.0 return info.mem_unit in bytes. */
306 } 305 u = info.mem_unit;
307 info.mem_unit*=1024; 306 if (u==0) u=1;
308 307 while ( (u&1) == 0 && s > 0 ) { u>>=1; s--; }
309 /* Note: These values can in theory overflow a 32 bit unsigned long (i.e. 308 result = (info.totalram>>s) + (info.totalswap>>s);
310 * mem >= Gib), but who puts more then 4GiB ram+swap on an embedded 309 result = result*u;
311 * system? */ 310 if (result < 0) result = INT_MAX;
312 info.totalram/=info.mem_unit; 311 return result;
313 info.totalswap/=info.mem_unit;
314 return(info.totalram+info.totalswap);
315} 312}
316 313
317static void console_init() 314static void console_init()
diff --git a/init/init.c b/init/init.c
index 17e605ba0..c4440894c 100644
--- a/init/init.c
+++ b/init/init.c
@@ -288,30 +288,27 @@ void set_term(int fd)
288 tcsetattr(fd, TCSANOW, &tty); 288 tcsetattr(fd, TCSANOW, &tty);
289} 289}
290 290
291/* How much memory does this machine have? */ 291/* How much memory does this machine have?
292 Units are kBytes to avoid overflow on 4GB machines */
292static int check_free_memory() 293static int check_free_memory()
293{ 294{
294 struct sysinfo info; 295 struct sysinfo info;
296 unsigned int result, u, s=10;
295 297
296 /* Pre initialize mem_unit in case this kernel is something prior to
297 * the linux 2.4 kernel (which will actually fill in mem_unit... */
298 sysinfo(&info);
299 if (sysinfo(&info) != 0) { 298 if (sysinfo(&info) != 0) {
300 printf("Error checking free memory: %s\n", strerror(errno)); 299 perrorMsg("Error checking free memory: ");
301 return -1; 300 return -1;
302 } 301 }
303 /* Kernels prior to 2.4.x will return info.mem_unit==0, so cope... */ 302
304 if (info.mem_unit==0) { 303 /* Kernels 2.0.x and 2.2.x return info.mem_unit==0 with values in bytes.
305 info.mem_unit=1; 304 * Kernels 2.4.0 return info.mem_unit in bytes. */
306 } 305 u = info.mem_unit;
307 info.mem_unit*=1024; 306 if (u==0) u=1;
308 307 while ( (u&1) == 0 && s > 0 ) { u>>=1; s--; }
309 /* Note: These values can in theory overflow a 32 bit unsigned long (i.e. 308 result = (info.totalram>>s) + (info.totalswap>>s);
310 * mem >= Gib), but who puts more then 4GiB ram+swap on an embedded 309 result = result*u;
311 * system? */ 310 if (result < 0) result = INT_MAX;
312 info.totalram/=info.mem_unit; 311 return result;
313 info.totalswap/=info.mem_unit;
314 return(info.totalram+info.totalswap);
315} 312}
316 313
317static void console_init() 314static void console_init()