diff --git a/libisofs/ecma119_tree.c b/libisofs/ecma119_tree.c index 63c150d..e6f890b 100644 --- a/libisofs/ecma119_tree.c +++ b/libisofs/ecma119_tree.c @@ -508,7 +508,7 @@ sort_tree(struct ecma119_tree_node *root) * "HELLOTHE03.TXT" */ static void -mangle_name(char **name, int num_change, int level, int seq_num) +mangle_name(char **name, int num_change, int level, int relaxed, int seq_num) { char *dot = strrchr(*name, '.'); char *semi = strrchr(*name, ';'); @@ -521,6 +521,24 @@ mangle_name(char **name, int num_change, int level, int seq_num) return; } strncpy(base, *name, len+1); + + if (relaxed & ECMA119_RELAXED_FILENAMES) { + /* relaxed filenames, don't care about extension */ + int maxlen = (relaxed & (1<<1)) ? 37 : 31; + base[maxlen - num_change] = '\0'; + baselen = strlen(base); + if (relaxed & ECMA119_OMIT_VERSION_NUMBERS) { + sprintf(fmt, "%%s%%0%1dd", num_change); + *name = realloc(*name, baselen + num_change + 1); + } else { + sprintf(fmt, "%%s%%0%1dd;1", num_change); + *name = realloc(*name, baselen + num_change + 3); + } + + sprintf(*name, fmt, base, seq_num); + return; + } + if (dot) { base[dot - *name] = '\0'; strncpy(ext, dot+1, len+1); @@ -533,14 +551,24 @@ mangle_name(char **name, int num_change, int level, int seq_num) } baselen = strlen(base); extlen = strlen(ext); - if (level == 1 && baselen + num_change > 8) { + + if (relaxed & (1<<1)) { + /* 37 char filenames */ + base[36 - extlen - num_change] = '\0'; + } else if (level == 1 && baselen + num_change > 8) { base[8 - num_change] = '\0'; } else if (level != 1 && baselen + extlen + num_change > 30) { base[30 - extlen - num_change] = '\0'; } - sprintf(fmt, "%%s%%0%1dd.%%s;1", num_change); - *name = realloc(*name, baselen + extlen + num_change + 4); + if (relaxed & ECMA119_OMIT_VERSION_NUMBERS) { + sprintf(fmt, "%%s%%0%1dd.%%s", num_change); + *name = realloc(*name, baselen + extlen + num_change + 1); + } else { + sprintf(fmt, "%%s%%0%1dd.%%s;1", num_change); + *name = realloc(*name, baselen + extlen + num_change + 4); + } + sprintf(*name, fmt, base, seq_num, ext); } @@ -575,6 +603,7 @@ mangle_all(struct ecma119_tree_node *dir) mangle_name(&(d.children[i+k]->iso_name), n_change, dir->target->iso_level, + dir->target->relaxed_constraints, k); d.children[i+k]->dirent_len = calc_dirent_len(d.children[i+k]);