setgroups.c 818 B

123456789101112131415161718192021222324252627282930313233343536
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * setgroups() for uClibc
  4. *
  5. * Copyright (C) 2000-2004 by Erik Andersen <andersen@codpoet.org>
  6. *
  7. * GNU Library General Public License (LGPL) version 2 or later.
  8. */
  9. #include "syscalls.h"
  10. #include <unistd.h>
  11. #include <grp.h>
  12. #define __NR___syscall_setgroups __NR_setgroups
  13. static inline _syscall2(int, __syscall_setgroups,
  14. size_t, size, const __kernel_gid_t *, list);
  15. int setgroups(size_t n, const gid_t * groups)
  16. {
  17. if (n > (size_t) sysconf(_SC_NGROUPS_MAX)) {
  18. __set_errno(EINVAL);
  19. return -1;
  20. } else {
  21. size_t i;
  22. __kernel_gid_t kernel_groups[n];
  23. for (i = 0; i < n; i++) {
  24. kernel_groups[i] = (groups)[i];
  25. if (groups[i] != (gid_t) ((__kernel_gid_t) groups[i])) {
  26. __set_errno(EINVAL);
  27. return -1;
  28. }
  29. }
  30. return (__syscall_setgroups(n, kernel_groups));
  31. }
  32. }