Back to index

glibc  2.9
getresgid.c
Go to the documentation of this file.
00001 /* getresgid -- fetch real group ID, effective group ID, and saved-set group ID
00002    Copyright (C) 2002, 2006 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <errno.h>
00021 #include <unistd.h>
00022 #include <hurd.h>
00023 #include <hurd/id.h>
00024 
00025 /* Fetch the real group ID, effective group ID, and saved-set group ID,
00026    of the calling process.  */
00027 int
00028 __getresgid (gid_t *rgid, gid_t *egid, gid_t *sgid)
00029 {
00030   error_t err;
00031   gid_t real, eff, saved;
00032 
00033   HURD_CRITICAL_BEGIN;
00034   __mutex_lock (&_hurd_id.lock);
00035 
00036   err = _hurd_check_ids ();
00037   if (!err)
00038     {
00039       if (_hurd_id.aux.ngids < 1)
00040        /* We do not even have a real GID.  */
00041        err = EGRATUITOUS;
00042       else
00043        {
00044          real = _hurd_id.aux.gids[0];
00045          eff = _hurd_id.gen.ngids < 1 ? real : _hurd_id.gen.gids[0];
00046          saved = _hurd_id.aux.ngids < 2 ? real : _hurd_id.aux.gids[1];
00047        }
00048     }
00049 
00050   __mutex_unlock (&_hurd_id.lock);
00051   HURD_CRITICAL_END;
00052 
00053   if (err)
00054     return __hurd_fail (err);
00055 
00056   *rgid = real;
00057   *egid = eff;
00058   *sgid = saved;
00059   return 0;
00060 }
00061 libc_hidden_def (__getresgid)
00062 weak_alias (__getresgid, getresgid)