From 5475502dc8eb8494d107b5c127366f38bddb5fc6 Mon Sep 17 00:00:00 2001 From: Vreixo Formoso Date: Tue, 8 Jan 2008 16:07:50 +0100 Subject: [PATCH] Different function for generate dir and files names for Joliet. The "." is not mandatory on dirs. --- src/joliet.c | 9 +++++++-- src/util.c | 29 +++++++++++++++++++++++++++-- src/util.h | 19 +++++++++++++++---- 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/src/joliet.c b/src/joliet.c index aef2344..59df677 100644 --- a/src/joliet.c +++ b/src/joliet.c @@ -36,7 +36,11 @@ int get_joliet_name(Ecma119Image *t, IsoNode *iso, uint16_t **name) } // TODO add support for relaxed constraints - jname = iso_j_id(ucs_name); + if (iso->type == LIBISO_DIR) { + jname = iso_j_dir_id(ucs_name); + } else { + jname = iso_j_file_id(ucs_name); + } free(ucs_name); if (jname != NULL) { *name = jname; @@ -125,6 +129,7 @@ int create_node(Ecma119Image *t, IsoNode *iso, JolietNode **node) joliet->node = iso; iso_node_ref(iso); + *node = joliet; return ISO_SUCCESS; } @@ -138,7 +143,7 @@ static int create_tree(Ecma119Image *t, IsoNode *iso, JolietNode **tree, int pathlen) { int ret, max_path; - JolietNode *node; + JolietNode *node = NULL; uint16_t *jname = NULL; if (t == NULL || iso == NULL || tree == NULL) { diff --git a/src/util.c b/src/util.c index 89aff88..65fc0a9 100644 --- a/src/util.c +++ b/src/util.c @@ -491,11 +491,11 @@ char *iso_2_fileid(const char *src) return strdup(dest); } -uint16_t *iso_j_id(const uint16_t *src) +uint16_t *iso_j_file_id(const uint16_t *src) { uint16_t *dot; size_t lname, lext, lnname, lnext, pos, i; - uint16_t dest[66]; /* 65 = 64 (name + ext) + 1 (.) + 1 (\0) */ + uint16_t dest[66]; /* 66 = 64 (name + ext) + 1 (.) + 1 (\0) */ if (src == NULL) { return NULL; @@ -554,6 +554,31 @@ uint16_t *iso_j_id(const uint16_t *src) return ucsdup(dest); } +uint16_t *iso_j_dir_id(const uint16_t *src) +{ + size_t len, i; + uint16_t dest[65]; /* 65 = 64 + 1 (\0) */ + + if (src == NULL) { + return NULL; + } + + len = ucslen(src); + if (len > 64) { + len = 64; + } + for (i = 0; i < len; i++) { + uint16_t c = src[i]; + if (valid_j_char(c)) { + dest[i] = c; + } else { + set_ucsbe(dest + i, '_'); + } + } + set_ucsbe(dest + len, '\0'); + return ucsdup(dest); +} + size_t ucslen(const uint16_t *str) { size_t i; diff --git a/src/util.h b/src/util.h index 6e78c8d..1e8a339 100644 --- a/src/util.h +++ b/src/util.h @@ -114,9 +114,9 @@ char *iso_1_fileid(const char *src); char *iso_2_fileid(const char *src); /** - * Create a Joliet file or directory identifier that consists of name and - * extension. The combined name and extension length will not exceed 128 bytes, - * and the name and extension will be separated (.). All characters consist of + * Create a Joliet file identifier that consists of name and extension. The + * combined name and extension length will not exceed 128 bytes, and the + * name and extension will be separated (.). All characters consist of * 2 bytes and the resulting string is NULL-terminated by a 2-byte NULL. * * Note that version number and (;1) is not appended. @@ -124,7 +124,18 @@ char *iso_2_fileid(const char *src); * @return * NULL if the original name and extension both are of length 0. */ -uint16_t *iso_j_id(const uint16_t *src); +uint16_t *iso_j_file_id(const uint16_t *src); + +/** + * Create a Joliet directory identifier that consists of name and optionally + * extension. The combined name and extension length will not exceed 128 bytes, + * and the name and extension will be separated (.). All characters consist of + * 2 bytes and the resulting string is NULL-terminated by a 2-byte NULL. + * + * @return + * NULL if the original name and extension both are of length 0. + */ +uint16_t *iso_j_dir_id(const uint16_t *src); /** * Like strlen, but for Joliet strings.