00001 /* 00002 00003 Copyright (C) 2000, 2001 Silicon Graphics, Inc. All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify it 00006 under the terms of version 2.1 of the GNU Lesser General Public License 00007 as published by the Free Software Foundation. 00008 00009 This program is distributed in the hope that it would be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 00013 Further, this software is distributed without any warranty that it is 00014 free of the rightful claim of any third person regarding infringement 00015 or the like. Any license provided herein, whether implied or 00016 otherwise, applies only to this software file. Patent licenses, if 00017 any, provided herein do not apply to combinations of this program with 00018 other software, or any other product whatsoever. 00019 00020 You should have received a copy of the GNU Lesser General Public 00021 License along with this program; if not, write the Free Software 00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, 00023 USA. 00024 00025 Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00026 Mountain View, CA 94043, or: 00027 00028 http://www.sgi.com 00029 00030 For further information regarding this notice, see: 00031 00032 http://oss.sgi.com/projects/GenInfo/NoticeExplan 00033 00034 */ 00035 00036 00037 #pragma ident "@(#) libf/pxf/pxfgetgroups.c 92.2 09/15/99 10:41:12" 00038 00039 00040 #include <fortran.h> 00041 #include <errno.h> 00042 #include <liberrno.h> 00043 #include <unistd.h> 00044 00045 #ifdef _UNICOS 00046 #include <sys/types.h> 00047 #include <sys/param.h> 00048 #elif defined(_LITTLE_ENDIAN) 00049 #include <sys/types.h> 00050 #include <sys/param.h> 00051 #else 00052 #include <limits.h> 00053 #endif 00054 00055 /* 00056 * PXFGETGROUPS -- get supplementary group IDs 00057 * (section 4.2.3 of Posix 1003.9-1992) 00058 * 00059 * Call from Fortran: 00060 * 00061 * SUBROUTINE PXFGETGROUPS(IGIDSETSIZE,IGROUPLIST,NGROUPS,IERROR) 00062 * INTERGER IGIDSETSIZE,IGROUPLIST(IGIDSETSIZE),NGROUPS,IERROR 00063 * 00064 * Where: 00065 * 00066 * IGIDSETSIZE is an input integer variable containing the size of 00067 * the IGROUPLIST integer array. 00068 * 00069 * IGROUPLIST is an output integer variable or array element that 00070 * will contain a set of supplemental group IDs for the 00071 * calling process. 00072 * 00073 * NGROUPS is an output interger variable that will contain the 00074 * number of supplemental group IDs for the calling process. 00075 * 00076 * IERROR is an output integer variable that will contain 00077 * the status: 00078 * 00079 * zero - variable was changed. 00080 * 00081 * nonzero - PXFGETGROUPS was not successful. 00082 * 00083 * PXFGETGROUPS may return any of the following error 00084 * values: 00085 * 00086 * EINVAL If the IGIDSETSIZE is not equal to zero and is 00087 * is less than the number of supplementary group 00088 * IDs. 00089 * 00090 */ 00091 00092 #ifdef _UNICOS 00093 void 00094 PXFGETGROUPS( 00095 #else 00096 void 00097 _PXFGETGROUPS( 00098 #endif 00099 _f_int *IGIDSETSIZE, 00100 _f_int *IGROUPLIST, 00101 _f_int *ngroups, 00102 _f_int *IERROR 00103 ) 00104 { 00105 gid_t grplistbuf[NGROUPS_MAX]; 00106 int i, groups, gidsetsize; 00107 00108 gidsetsize = *IGIDSETSIZE; 00109 00110 /* get groups using a group list buffer of size NGROUPS_MAX */ 00111 if ((groups = getgroups(NGROUPS_MAX, grplistbuf)) == -1) { 00112 *IERROR = errno; 00113 } else { 00114 /* check if user array IGROUPLIST is too small to hold all of the group IDs */ 00115 if ((gidsetsize < groups) && (gidsetsize != 0)) { 00116 *IERROR = EINVAL; 00117 } else { 00118 00119 /* If gidsetsize is zero the user just wants the number of 00120 * supplemental groups IDs, other wise the group IDs need 00121 * to be coppied into the IGROUPLIST array and the number of 00122 * groups assigned to ngroups user variable. 00123 */ 00124 00125 if (gidsetsize != 0) { 00126 00127 /* copy the group ID elements into IGROUPLIST */ 00128 for (i=0; i < groups; i++) { 00129 IGROUPLIST[i] = grplistbuf[i]; 00130 } 00131 } 00132 00133 *IERROR = 0; 00134 *ngroups = groups; 00135 } 00136 } 00137 } 00138 00139 #ifndef _UNICOS 00140 void 00141 pxfgetgroups_( 00142 _f_int *IGIDSETSIZE, 00143 _f_int *IGROUPLIST, 00144 _f_int *ngroups, 00145 _f_int *IERROR 00146 ) 00147 { 00148 _PXFGETGROUPS(IGIDSETSIZE, IGROUPLIST, ngroups, IERROR); 00149 } 00150 #endif
1.5.6