Welcome to The Fiwix Project
A UNIX-like kernel for the i386 architecture
1 /* 2 * fiwix/kernel/syscalls/getgroups.c 3 * 4 * Copyright 2018, Jordi Sanfeliu. All rights reserved. 5 * Distributed under the terms of the Fiwix License. 6 */ 7 8 #include <fiwix/types.h> 9 #include <fiwix/fs.h> 10 #include <fiwix/process.h> 11 #include <fiwix/errno.h> 12 13 #ifdef __DEBUG__ 14 #include <fiwix/stdio.h> 15 #endif /*__DEBUG__ */ 16 17 int sys_getgroups(__ssize_t size, __gid_t *list) 18 { 19 int n, errno; 20 21 #ifdef __DEBUG__ 22 printk("(pid %d) sys_getgroups(%d, 0x%08x)\n", current->pid, size, (unsigned int)list); 23 #endif /*__DEBUG__ */ 24 25 /* 26 * If size is 0, sys_getgroups() shall return the number of group IDs 27 * that it would otherwise return without modifying the array pointed 28 * to by list. 29 */ 30 if(!size) { 31 for(n = 0; n < NGROUPS_MAX; n++) { 32 if(current->groups[n] == -1) { 33 break; 34 } 35 } 36 return n; 37 } 38 39 if((errno = check_user_area(VERIFY_WRITE, list, sizeof(__gid_t)))) { 40 return errno; 41 } 42 for(n = 0; n < NGROUPS_MAX; n++) { 43 if(current->groups[n] == -1) { 44 break; 45 } 46 if(size) { 47 if(n > size) { 48 return -EINVAL; 49 } 50 list[n] = (__gid_t)current->groups[n]; 51 } 52 } 53 return n; 54 }