library/src/filesystem/BP-Filesystem.cc
char * BP_FStatGetSpecialPermissionsModeString(struct stat * stats)
{

	// ensure we have stats
	if(!stats)
		return NULL;

	// declare mode string and joiner string
	char * mode_str   = NULL;
	char * joined_str = NULL;



	// --- Blockparty Internal Type Macros ----------

	// add ISVTX entry
	if(BP_STAT_MODE_IS_ISVTX(stats->st_mode))
	{

		// add fmt string
		if(!mode_str)
		{
			mode_str = bpstrdup("SVTX ");
		}
		else
		{

			// join mode
			joined_str = BP_JoinStrings(mode_str, "SVTX ", NULL);

			// free old
			bpfree(mode_str);

			// overwrite
			mode_str = joined_str;

		}

	}


	// add SUID entry
	if(BP_STAT_MODE_IS_ISUID(stats->st_mode))
	{

		// add SUID string
		if(!mode_str)
		{
			mode_str = bpstrdup("SUID ");
		}
		else
		{

			// join mode
			joined_str = BP_JoinStrings(mode_str, "SUID ", NULL);

			// free old
			bpfree(mode_str);

			// overwrite
			mode_str = joined_str;

		}

	}


	// add ISGID entry
	if(BP_STAT_MODE_IS_ISGID(stats->st_mode))
	{

		// add WOTH string
		if(!mode_str)
		{
			mode_str = bpstrdup("SGID ");
		}
		else
		{

			// join mode
			joined_str = BP_JoinStrings(mode_str, "SGID ", NULL);

			// free old
			bpfree(mode_str);

			// overwrite
			mode_str = joined_str;

		}

	}

	// join front part if some modes were matched
	char * tmp_str = NULL;
	if(mode_str)
	{
		tmp_str = BP_JoinStrings("spec:", mode_str);
		if(tmp_str)
		{
			bpfree(mode_str);
			mode_str = tmp_str;
		}
	}


	// trim string to get rid of whitespace
	char * trimmed = NULL;

	// if we have a string we can trim it
	if(mode_str)
	{

		// trim whitespace off both ends
		trimmed = BP_StringTrimWhitespace(mode_str, BP_STRING_TRIM_DIRECTION_BOTH, bpstrlen(mode_str));

		// if any trimming occured, destroy old mode and reassign with trimmed
		if(trimmed)
		{
			bpfree(mode_str);
			mode_str = trimmed;
		}

	}

	// return the mode string
	return mode_str;

}
// 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 "special" aka suid/sgid etc)
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 "special" aka suid/sgid etc)
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 " special " aka suid / sgid etc )
char * BP_FStatGetSpecialPermissionsModeString(struct stat * stats)
{
	if(!stats)
		return NULL;
	char * mode_str   = NULL;
	char * joined_str = NULL;
	if(BP_STAT_MODE_IS_ISVTX(stats->st_mode))
	{
		if(!mode_str)
		{
			mode_str = bpstrdup("SVTX ");
		}
		else
		{
			joined_str = BP_JoinStrings(mode_str, "SVTX ", NULL);
			bpfree(mode_str);
			mode_str = joined_str;
		}
	}
	if(BP_STAT_MODE_IS_ISUID(stats->st_mode))
	{
		if(!mode_str)
		{
			mode_str = bpstrdup("SUID ");
		}
		else
		{
			joined_str = BP_JoinStrings(mode_str, "SUID ", NULL);
			bpfree(mode_str);
			mode_str = joined_str;
		}
	}
	if(BP_STAT_MODE_IS_ISGID(stats->st_mode))
	{
		if(!mode_str)
		{
			mode_str = bpstrdup("SGID ");
		}
		else
		{
			joined_str = BP_JoinStrings(mode_str, "SGID ", NULL);
			bpfree(mode_str);
			mode_str = joined_str;
		}
	}
	char * tmp_str = NULL;
	if(mode_str)
	{
		tmp_str = BP_JoinStrings("spec:", mode_str);
		if(tmp_str)
		{
			bpfree(mode_str);
			mode_str = tmp_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_FStatGetSpecialPermissionsModeString ( struct stat * stats ) { if ( ! stats ) return NULL ; char * mode_str = NULL ; char * joined_str = NULL ; if ( BP_STAT_MODE_IS_ISVTX ( 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_ISUID ( 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_ISGID ( 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 * tmp_str = NULL ; if ( mode_str ) { tmp_str = BP_JoinStrings ( " " , mode_str ) ; if ( tmp_str ) { bpfree ( mode_str ) ; mode_str = tmp_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 ISVTX entry // add fmt string // join mode // free old // overwrite // add SUID entry // add SUID string // join mode // free old // overwrite // add ISGID entry // add WOTH string // join mode // free old // overwrite // join front part if some modes were matched // 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