Skip to content

Commit

Permalink
Merge branch 'fix_groupname' of https://github.com/mgmarino/xrootd
Browse files Browse the repository at this point in the history
  • Loading branch information
ljanyst committed Nov 19, 2013
2 parents 1d4d0af + 27e525f commit ab6fb04
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/XrdOuc/XrdOucUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,12 @@ int XrdOucUtils::GroupName(gid_t gID, char *gName, int gNsz)
struct group *gEnt, gStruct;
char gBuff[1024], *gBp = gBuff;
int glen, gBsz = sizeof(gBuff), aOK = 1;
int retVal = 0;

// Get the the group struct. If we don't have a large enough buffer, get a
// larger one and try again up to the maximum buffer we will tolerate.
//
while((getgrgid_r(gID, &gStruct, gBp, gBsz, &gEnt) != 0) && errno == ERANGE)
while(( retVal = getgrgid_r(gID, &gStruct, gBp, gBsz, &gEnt) ) == ERANGE)
{if (gBsz >= maxgBsz) {aOK = 0; break;}
if (gBsz > addGsz) free(gBp);
gBsz += addGsz;
Expand All @@ -267,7 +268,7 @@ int XrdOucUtils::GroupName(gid_t gID, char *gName, int gNsz)

// Return a group name if all went well
//
if (aOK)
if (aOK && retVal == 0 && gEnt != NULL)
{glen = strlen(gEnt->gr_name);
if (glen >= gNsz) glen = 0;
else strcpy(gName, gEnt->gr_name);
Expand Down

0 comments on commit ab6fb04

Please sign in to comment.