library/src/filesystem/BP-Filesystem.cc
// This will attempt to get a mode string from a stats buff.  Buffer is returned
// via bpcalloc and must be free'd. (fetches perms for "others", aka non-owner, non-group)
This will attempt to get a mode string from a stats buff.  Buffer is returned
via bpcalloc and must be free'd. (fetches perms for "others", aka non-owner, non-group)
This will attempt to get a mode string from a stats buff . Buffer is returned via bpcalloc and must be free ' d . ( fetches perms for " others " aka non - owner non - group )
char * BP_FStatGetOthersPermissionsModeString(struct stat * stats)
{
	if(!stats)
		return NULL;
	char * mode_str = NULL;
	char * joined_str = NULL;
	if(BP_STAT_MODE_IS_IRWXO(stats->st_mode))
	{
		if(!mode_str)
		{
			mode_str = bpstrdup("oth:");
		}
		else
		{
			joined_str = BP_JoinStrings(mode_str, "oth:", NULL);
			bpfree(mode_str);
			mode_str = joined_str;
		}
	}
	if(BP_STAT_MODE_IS_IROTH(stats->st_mode))
	{
		if(!mode_str)
		{
			mode_str = bpstrdup("R");
		}
		else
		{
			joined_str = BP_JoinStrings(mode_str, "R", NULL);
			bpfree(mode_str);
			mode_str = joined_str;
		}
	}
	if(BP_STAT_MODE_IS_IWOTH(stats->st_mode))
	{
		if(!mode_str)
		{
			mode_str = bpstrdup("W");
		}
		else
		{
			joined_str = BP_JoinStrings(mode_str, "W", NULL);
			bpfree(mode_str);
			mode_str = joined_str;
		}
	}
	if(BP_STAT_MODE_IS_IXOTH(stats->st_mode))
	{
		if(!mode_str)
		{
			mode_str = bpstrdup("X");
		}
		else
		{
			joined_str = BP_JoinStrings(mode_str, "X", NULL);
			bpfree(mode_str);
			mode_str = joined_str;
		}
	}
	char * trimmed = NULL;
	if(mode_str)
	{
		trimmed = BP_StringTrimWhitespace(mode_str, BP_STRING_TRIM_DIRECTION_BOTH, bpstrlen(mode_str));
		if(trimmed)
		{
			bpfree(mode_str);
			mode_str = trimmed;
		}
	}
	return mode_str;
}
char * BP_FStatGetOthersPermissionsModeString ( struct stat * stats ) { if ( ! stats ) return NULL ; char * mode_str = NULL ; char * joined_str = NULL ; if ( BP_STAT_MODE_IS_IRWXO ( stats -> st_mode ) ) { if ( ! mode_str ) { mode_str = bpstrdup ( " " ) ; } else { joined_str = BP_JoinStrings ( mode_str , " " , NULL ) ; bpfree ( mode_str ) ; mode_str = joined_str ; } } if ( BP_STAT_MODE_IS_IROTH ( stats -> st_mode ) ) { if ( ! mode_str ) { mode_str = bpstrdup ( " " ) ; } else { joined_str = BP_JoinStrings ( mode_str , " " , NULL ) ; bpfree ( mode_str ) ; mode_str = joined_str ; } } if ( BP_STAT_MODE_IS_IWOTH ( stats -> st_mode ) ) { if ( ! mode_str ) { mode_str = bpstrdup ( " " ) ; } else { joined_str = BP_JoinStrings ( mode_str , " " , NULL ) ; bpfree ( mode_str ) ; mode_str = joined_str ; } } if ( BP_STAT_MODE_IS_IXOTH ( stats -> st_mode ) ) { if ( ! mode_str ) { mode_str = bpstrdup ( " " ) ; } else { joined_str = BP_JoinStrings ( mode_str , " " , NULL ) ; bpfree ( mode_str ) ; mode_str = joined_str ; } } char * trimmed = NULL ; if ( mode_str ) { trimmed = BP_StringTrimWhitespace ( mode_str , BP_STRING_TRIM_DIRECTION_BOTH , bpstrlen ( mode_str ) ) ; if ( trimmed ) { bpfree ( mode_str ) ; mode_str = trimmed ; } } return mode_str ; }
This will attempt to get a mode string from a stats buff.
This will attempt to get a mode string from a stats buff .
// ensure we have stats // declare mode string and joiner string // --- Blockparty Internal Type Macros ---------- // add RWXU entry // add fmt string // join mode // free old // overwrite // add ROTH entry // add RGRP string // join mode // free old // overwrite // add WOTH entry // add WOTH string // join mode // free old // overwrite // add XOTH entry // add WOTH string // join mode // free old // overwrite // trim string to get rid of whitespace // if we have a string we can trim it // trim whitespace off both ends // if any trimming occured, destroy old mode and reassign with trimmed // return the mode string