am b632857a: Merge "Add missing include and function prototype for sched_getaffinity."

* commit 'b632857a50a1fd2b759316d07ace6c36f6f418cf':
  Add missing include and function prototype for sched_getaffinity.
This commit is contained in:
Elliott Hughes 2013-04-10 17:56:22 -07:00 committed by Android Git Automerger
commit 76db50ddc9
2 changed files with 15 additions and 11 deletions

View file

@ -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 \

View file

@ -25,17 +25,21 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#define _GNU_SOURCE 1
#include <sched.h>
#include <string.h>
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<char*>(set) + rc, 0, set_size - rc);
return 0;
}