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.
This will attempt to get a mode string from a stats buff.  Buffer is returned
via bpcalloc and must be free'd.
This will attempt to get a mode string from a stats buff . Buffer is returned via bpcalloc and must be free ' d .
char * BP_FStatGetFiletypeModeString(struct stat * stats)
{
	if(!stats)
		return NULL;
	char * mode_str = NULL;
	char * joined_str = NULL;
	if(BP_STAT_MODE_IS_IFMT(stats->st_mode))
	{
		if(!mode_str)
		{
			mode_str = bpstrdup("FMT ");
		}
		else
		{
			joined_str = BP_JoinStrings(mode_str, "FMT ", NULL);
			bpfree(mode_str);
			mode_str = joined_str;
		}
	}
	if(S_ISREG(stats->st_mode))
	{
		if(!mode_str)
		{
			mode_str = bpstrdup("REG ");
		}
		else
		{
			joined_str = BP_JoinStrings(mode_str, "REG ", NULL);
			bpfree(mode_str);
			mode_str = joined_str;
		}
	}
	if(S_ISDIR(stats->st_mode))
	{
		if(!mode_str)
		{
			mode_str = bpstrdup("DIR ");
		}
		else
		{
			joined_str = BP_JoinStrings(mode_str, "DIR ", NULL);
			bpfree(mode_str);
			mode_str = joined_str;
		}
	}
	if(S_ISCHR(stats->st_mode))
	{
		if(!mode_str)
		{
			mode_str = bpstrdup("CHR ");
		}
		else
		{
			joined_str = BP_JoinStrings(mode_str, "CHR ", NULL);
			bpfree(mode_str);
			mode_str = joined_str;
		}
	}
	if(S_ISBLK(stats->st_mode))
	{
		if(!mode_str)
		{
			mode_str = bpstrdup("BLK ");
		}
		else
		{
			joined_str = BP_JoinStrings(mode_str, "BLK ", NULL);
			bpfree(mode_str);
			mode_str = joined_str;
		}
	}
	if(S_ISFIFO(stats->st_mode))
	{
		if(!mode_str)
		{
			mode_str = bpstrdup("FIFO ");
		}
		else
		{
			joined_str = BP_JoinStrings(mode_str, "FIFO ", NULL);
			bpfree(mode_str);
			mode_str = joined_str;
		}
	}
	if(S_ISLNK(stats->st_mode))
	{
		if(!mode_str)
		{
			mode_str = bpstrdup("LNK ");
		}
		else
		{
			joined_str = BP_JoinStrings(mode_str, "LNK ", NULL);
			bpfree(mode_str);
			mode_str = joined_str;
		}
	}
	if(S_ISSOCK(stats->st_mode))
	{
		if(!mode_str)
		{
			mode_str = bpstrdup("SOCK ");
		}
		else
		{
			joined_str = BP_JoinStrings(mode_str, "SOCK ", 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_FStatGetFiletypeModeString ( struct stat * stats ) { if ( ! stats ) return NULL ; char * mode_str = NULL ; char * joined_str = NULL ; if ( BP_STAT_MODE_IS_IFMT ( 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 ( S_ISREG ( 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 ( S_ISDIR ( 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 ( S_ISCHR ( 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 ( S_ISBLK ( 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 ( S_ISFIFO ( 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 ( S_ISLNK ( 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 ( S_ISSOCK ( 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 FMT entry // add fmt string // join mode // free old // overwrite // --- Stdlib Macros // add REG entry // add reg string // join mode // free old // overwrite // add DIR entry // add string // join mode // free old // overwrite // add CHR entry // add string // join mode // free old // overwrite // add BLK entry // add string // join mode // free old // overwrite // add FIFO entry // add string // join mode // free old // overwrite // add LNK entry // add string // join mode // free old // overwrite // add SOCK entry // add 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