char * mfile_name_concat (char const *dir, char const *abase, char **base_in_result) { char const *dirbase = last_component (dir); size_t dirbaselen = base_len (dirbase); size_t dirlen = dirbase - dir + dirbaselen; size_t needs_separator = (dirbaselen && ! ISSLASH (dirbase[dirbaselen - 1])); char const *base = longest_relative_suffix (abase); size_t baselen = strlen (base); char *p_concat = malloc (dirlen + needs_separator + baselen + 1); char *p; if (p_concat == NULL) return NULL; p = mempcpy (p_concat, dir, dirlen); *p = DIRECTORY_SEPARATOR; p += needs_separator; if (base_in_result) *base_in_result = p - IS_ABSOLUTE_FILE_NAME (abase); p = mempcpy (p, base, baselen); *p = '\0'; return p_concat; }
char *mfile_name_concat( char *dir, char *abase, char **base_in_result ) { char *dirbase = last_component( dir ); size_t dirbaselen = base_len( dirbase ); size_t dirlen = dirbaselen + ( dirbase - dir ); size_t needs_separator = dirbaselen == 0 || dirbase[ dirbaselen - 1 ] == '/' ? 0 : 1; char *base = longest_relative_suffix( abase ); size_t baselen = strlen( base ); char *p_concat = malloc( ( baselen + needs_separator + dirlen + 1 ) * sizeof( char ) ); char *p; if ( p_concat == 0 ) { return 0; } p = mempcpy( p_concat, dir, dirlen ); p[0] = '/'; p = &p[ needs_separator ]; if ( base_in_result != 0 ) base_in_result[0] = &p[ ( abase[0] == '/' ) * -1 ]; p = mempcpy( p, base, baselen ); p[0] = 0; return p_concat; }