system_getgrgid Function

public function system_getgrgid(gid) result(gname)

NAME

system_getgrgid(3f) - [M_system:QUERY] get groupd name associated with a GID
(LICENSE:PD)

SYNOPSIS

function system_getgrgid(gid) result (gname)

class(*),intent(in)          :: gid   ! any INTEGER type
character(len=:),allocatable :: gname

DESCRIPTION

The system_getlogin() function returns a string containing the group
name associated with the given GID. If no match is found
it returns a null string and sets errno to indicate the error.

OPTION

gid    GID to try to look up associated group for. Can be of any
       INTEGER type.

RETURN VALUE

gname  returns the group name. Blank if an error occurs

EXAMPLE

Sample program:

program demo_system_getgrgid
use M_system, only : system_getgrgid
use M_system, only : system_getgid
implicit none
character(len=:),allocatable :: name
name=system_getgrgid( system_getgid() )
write(*,'("group[",a,"] for ",i0)')name,system_getgid()
end program demo_system_getgrgid

Results:

group[default] for 197121

AUTHOR

John S. Urban

LICENSE

Public Domain

Arguments

Type IntentOptional Attributes Name
class(*), intent(in) :: gid

Return Value character(len=:), allocatable


Contents

Source Code


Source Code

function system_getgrgid(gid) result (gname)
class(*),intent(in)                        :: gid
character(len=:),allocatable               :: gname
   character(kind=c_char,len=1)            :: groupname(4097)  ! assumed long enough for any groupname
   integer                                 :: ierr
   integer(kind=c_long_long)               :: gid_local

interface
   function c_getgrgid(c_gid,c_groupname) bind(c,name="my_getgrgid") result(c_ierr)
      import c_int, c_ptr, c_char,c_long_long
      integer(kind=c_long_long),value,intent(in) :: c_gid
      character(kind=c_char),intent(out)         :: c_groupname(*)
      integer(kind=c_int)                        :: c_ierr
   end function c_getgrgid
end interface
!-----------------------------------------------------------------------------------------------------------------------------------
   gid_local=anyinteger_to_64bit(gid)
   ierr = c_getgrgid(gid_local,groupname)
   if(ierr.eq.0)then
      gname=trim(arr2str(groupname))
   else
      gname=''
   endif
!-----------------------------------------------------------------------------------------------------------------------------------
end function system_getgrgid