diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-09-14 13:48:52 +1000 |
---|---|---|
committer | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-09-14 13:48:52 +1000 |
commit | 53899dc573f4203d5d2a030b4404f7b30f92d202 (patch) | |
tree | 5439d5c9081fbe1839893fc846d673257f36684d /libbb | |
parent | e6c77ec19ac157f85f81ac85b008ef77f229c9ac (diff) | |
parent | 9768a82eb0ef8b742034d2b22c32e0cc97633604 (diff) | |
download | busybox-w32-53899dc573f4203d5d2a030b4404f7b30f92d202.tar.gz busybox-w32-53899dc573f4203d5d2a030b4404f7b30f92d202.tar.bz2 busybox-w32-53899dc573f4203d5d2a030b4404f7b30f92d202.zip |
Merge branch 'origin/master' (early part)
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/Kbuild.src | 3 | ||||
-rw-r--r-- | libbb/appletlib.c | 2 | ||||
-rw-r--r-- | libbb/get_cpu_count.c | 47 | ||||
-rw-r--r-- | libbb/strrstr.c | 2 |
4 files changed, 52 insertions, 2 deletions
diff --git a/libbb/Kbuild.src b/libbb/Kbuild.src index a4f77414b..a6a163f3e 100644 --- a/libbb/Kbuild.src +++ b/libbb/Kbuild.src | |||
@@ -158,6 +158,9 @@ lib-$(CONFIG_MOUNT) += find_mount_point.o | |||
158 | lib-$(CONFIG_HWCLOCK) += rtc.o | 158 | lib-$(CONFIG_HWCLOCK) += rtc.o |
159 | lib-$(CONFIG_RTCWAKE) += rtc.o | 159 | lib-$(CONFIG_RTCWAKE) += rtc.o |
160 | 160 | ||
161 | lib-$(CONFIG_IOSTAT) += get_cpu_count.o | ||
162 | lib-$(CONFIG_MPSTAT) += get_cpu_count.o | ||
163 | |||
161 | # We shouldn't build xregcomp.c if we don't need it - this ensures we don't | 164 | # We shouldn't build xregcomp.c if we don't need it - this ensures we don't |
162 | # require regex.h to be in the include dir even if we don't need it thereby | 165 | # require regex.h to be in the include dir even if we don't need it thereby |
163 | # allowing us to build busybox even if uclibc regex support is disabled. | 166 | # allowing us to build busybox even if uclibc regex support is disabled. |
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index cae7da48a..b470f30f9 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c | |||
@@ -9,7 +9,7 @@ | |||
9 | * Based in part on code from sash, Copyright (c) 1999 by David I. Bell | 9 | * Based in part on code from sash, Copyright (c) 1999 by David I. Bell |
10 | * Permission has been granted to redistribute this code under the GPL. | 10 | * Permission has been granted to redistribute this code under the GPL. |
11 | * | 11 | * |
12 | * Licensed under GPLv2 or later, see file License in this tarball for details. | 12 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
13 | */ | 13 | */ |
14 | 14 | ||
15 | /* We are trying to not use printf, this benefits the case when selected | 15 | /* We are trying to not use printf, this benefits the case when selected |
diff --git a/libbb/get_cpu_count.c b/libbb/get_cpu_count.c new file mode 100644 index 000000000..edb7e6d37 --- /dev/null +++ b/libbb/get_cpu_count.c | |||
@@ -0,0 +1,47 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Factored out of mpstat/iostat. | ||
4 | * | ||
5 | * Copyright (C) 2010 Marek Polacek <mmpolacek@gmail.com> | ||
6 | * | ||
7 | * Licensed under GPLv2, see file LICENSE in this tarball for details. | ||
8 | */ | ||
9 | #include "libbb.h" | ||
10 | |||
11 | /* Does str start with "cpu"? */ | ||
12 | int FAST_FUNC starts_with_cpu(const char *str) | ||
13 | { | ||
14 | return ((str[0] - 'c') | (str[1] - 'p') | (str[2] - 'u')) == 0; | ||
15 | } | ||
16 | |||
17 | /* | ||
18 | * Get number of processors. Uses /proc/stat. | ||
19 | * Return value 0 means one CPU and non SMP kernel. | ||
20 | * Otherwise N means N processor(s) and SMP kernel. | ||
21 | */ | ||
22 | unsigned FAST_FUNC get_cpu_count(void) | ||
23 | { | ||
24 | FILE *fp; | ||
25 | char line[256]; | ||
26 | int proc_nr = -1; | ||
27 | |||
28 | fp = xfopen_for_read("/proc/stat"); | ||
29 | while (fgets(line, sizeof(line), fp)) { | ||
30 | if (!starts_with_cpu(line)) { | ||
31 | if (proc_nr >= 0) | ||
32 | break; /* we are past "cpuN..." lines */ | ||
33 | continue; | ||
34 | } | ||
35 | if (line[3] != ' ') { /* "cpuN" */ | ||
36 | int num_proc; | ||
37 | if (sscanf(line + 3, "%u", &num_proc) == 1 | ||
38 | && num_proc > proc_nr | ||
39 | ) { | ||
40 | proc_nr = num_proc; | ||
41 | } | ||
42 | } | ||
43 | } | ||
44 | |||
45 | fclose(fp); | ||
46 | return proc_nr + 1; | ||
47 | } | ||
diff --git a/libbb/strrstr.c b/libbb/strrstr.c index a803dd983..d201f5172 100644 --- a/libbb/strrstr.c +++ b/libbb/strrstr.c | |||
@@ -4,7 +4,7 @@ | |||
4 | * | 4 | * |
5 | * Copyright (C) 2008 Bernhard Reutner-Fischer | 5 | * Copyright (C) 2008 Bernhard Reutner-Fischer |
6 | * | 6 | * |
7 | * Licensed under GPLv2 or later, see file License in this tarball for details. | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #ifdef __DO_STRRSTR_TEST | 10 | #ifdef __DO_STRRSTR_TEST |