71 size_t buflen = sysconf( _SC_GETGR_R_SIZE_MAX );
72 char* buf =
static_cast<char *
>( malloc(buflen) );
if(!buf)
throw runtime_error( bo::str( bo::format(
"failed to allocate %d bytes") % buflen ) );
77 _errno =
::getgrgid_r( __gid, &gbuf, buf, buflen, &gbufp );
78 if( _errno == ERANGE )
81 buf =
static_cast<char *
>( realloc( buf, buflen ) );
if(!buf)
throw runtime_error( bo::str( bo::format(
"failed to allocate %d bytes") % buflen ) );
83 else if( _errno )
throw runtime_error( bo::str( bo::format(
"failed to getgrgid_r '%d': %s") % __gid % strerror( errno ) ) );
86 if( gbufp == NULL )
throw gid_not_found_error( bo::str( bo::format(
"gid '%d' not found") % __gid ) );
88 __group =
cxx_group( gbuf.gr_name, gbuf.gr_passwd, gbuf.gr_gid, gbuf.gr_mem );
95 free(buf); buf = NULL;
112 size_t buflen = sysconf( _SC_GETGR_R_SIZE_MAX );
113 char* buf =
static_cast<char *
>( malloc(buflen) );
if(!buf)
throw runtime_error( bo::str( bo::format(
"failed to allocate %d bytes") % buflen ) );
118 _errno =
::getgrnam_r( __gname.c_str(), &gbuf, buf, buflen, &gbufp );
119 if( _errno == ERANGE )
122 buf =
static_cast<char *
>( realloc( buf, buflen ) );
if(!buf)
throw runtime_error( bo::str( bo::format(
"failed to allocate %d bytes") % buflen ) );
124 else if( _errno )
throw runtime_error( bo::str( bo::format(
"failed to getgrnam_r '%s': %s") % __gname % strerror( errno ) ) );
127 if( gbufp == NULL )
throw gname_not_found_error( bo::str( bo::format(
"gname '%s' not found") % __gname ) );
129 __group =
cxx_group( gbuf.gr_name, gbuf.gr_passwd, gbuf.gr_gid, gbuf.gr_mem );
136 free(buf); buf = NULL;