diff options
Diffstat (limited to 'coreutils/nproc.c')
-rw-r--r-- | coreutils/nproc.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/coreutils/nproc.c b/coreutils/nproc.c index f1d11fa5a..5259921f1 100644 --- a/coreutils/nproc.c +++ b/coreutils/nproc.c | |||
@@ -29,7 +29,11 @@ | |||
29 | int nproc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 29 | int nproc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
30 | int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | 30 | int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) |
31 | { | 31 | { |
32 | #if !ENABLE_PLATFORM_MINGW32 | ||
32 | unsigned long mask[1024]; | 33 | unsigned long mask[1024]; |
34 | #else | ||
35 | DWORD_PTR affinity, process_affinity, system_affinity; | ||
36 | #endif | ||
33 | int count = 0; | 37 | int count = 0; |
34 | #if ENABLE_LONG_OPTS | 38 | #if ENABLE_LONG_OPTS |
35 | int ignore = 0; | 39 | int ignore = 0; |
@@ -38,7 +42,10 @@ int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
38 | "all\0" No_argument "\xff" | 42 | "all\0" No_argument "\xff" |
39 | , &ignore | 43 | , &ignore |
40 | ); | 44 | ); |
45 | #endif | ||
41 | 46 | ||
47 | #if !ENABLE_PLATFORM_MINGW32 | ||
48 | #if ENABLE_LONG_OPTS | ||
42 | if (opts & (1 << 1)) { | 49 | if (opts & (1 << 1)) { |
43 | DIR *cpusd = opendir("/sys/devices/system/cpu"); | 50 | DIR *cpusd = opendir("/sys/devices/system/cpu"); |
44 | if (cpusd) { | 51 | if (cpusd) { |
@@ -63,6 +70,17 @@ int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
63 | } | 70 | } |
64 | } | 71 | } |
65 | } | 72 | } |
73 | #else /* ENABLE_PLATFORM_MINGW32 */ | ||
74 | if (GetProcessAffinityMask(GetCurrentProcess(), &process_affinity, | ||
75 | &system_affinity)) { | ||
76 | affinity = (ENABLE_LONG_OPTS && opts & (1 << 1)) ? | ||
77 | system_affinity : process_affinity; | ||
78 | while (affinity) { | ||
79 | count += affinity & 1; | ||
80 | affinity >>= 1; | ||
81 | } | ||
82 | } | ||
83 | #endif /* ENABLE_PLATFORM_MINGW32 */ | ||
66 | 84 | ||
67 | IF_LONG_OPTS(count -= ignore;) | 85 | IF_LONG_OPTS(count -= ignore;) |
68 | if (count <= 0) | 86 | if (count <= 0) |