diff --git a/libc/Android.mk b/libc/Android.mk index 3c387d2e1..74175ba0d 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -170,7 +170,6 @@ libc_common_src_files := \ bionic/recv.c \ bionic/sched_cpualloc.c \ bionic/sched_cpucount.c \ - bionic/sched_getaffinity.c \ bionic/sched_getcpu.c \ bionic/semaphore.c \ bionic/send.c \ @@ -264,6 +263,7 @@ libc_bionic_src_files := \ bionic/raise.cpp \ bionic/sbrk.cpp \ bionic/scandir.cpp \ + bionic/sched_getaffinity.cpp \ bionic/__set_errno.cpp \ bionic/setlocale.cpp \ bionic/signalfd.cpp \ diff --git a/libc/bionic/sched_getaffinity.c b/libc/bionic/sched_getaffinity.cpp similarity index 77% rename from libc/bionic/sched_getaffinity.c rename to libc/bionic/sched_getaffinity.cpp index 7313822a2..26f22b110 100644 --- a/libc/bionic/sched_getaffinity.c +++ b/libc/bionic/sched_getaffinity.cpp @@ -25,17 +25,21 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ + #define _GNU_SOURCE 1 #include +#include -int sched_getaffinity(pid_t pid, size_t setsize, cpu_set_t* set) -{ - int ret = __sched_getaffinity(pid, setsize, set); - if (ret >= 0) { - if ((size_t)ret < setsize) { - memset((char*)set + ret, '\0', setsize - (size_t)ret); - } - ret = 0; - } - return ret; +extern "C" int __sched_getaffinity(pid_t, size_t, cpu_set_t*); + +int sched_getaffinity(pid_t pid, size_t set_size, cpu_set_t* set) { + int rc = __sched_getaffinity(pid, set_size, set); + if (rc == -1) { + return -1; + } + + // Clear any bytes the kernel didn't touch. + // (The kernel returns the number of bytes written on success.) + memset(reinterpret_cast(set) + rc, 0, set_size - rc); + return 0; }