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