diff --git a/libisofs/rockridge_read.c b/libisofs/rockridge_read.c index 4f47d67..4b10280 100644 --- a/libisofs/rockridge_read.c +++ b/libisofs/rockridge_read.c @@ -302,7 +302,7 @@ int read_rr_NM(struct susp_sys_user_entry *nm, char **name, int *cont) *name = realloc(*name, strlen(*name) + nm->len_sue[0] - 5 + 1); strncat(*name, (char*)nm->data.NM.name, nm->len_sue[0] - 5); } else { - *name = strcopy((char*)nm->data.NM.name, nm->len_sue[0] - 5); + *name = iso_util_strcopy((char*)nm->data.NM.name, nm->len_sue[0] - 5); } if (*name == NULL) { return ISO_OUT_OF_MEM; @@ -380,7 +380,7 @@ int read_rr_SL(struct susp_sys_user_entry *sl, char **dest, int *cont) /* we don't have to add the '/' */ strncat(*dest, comp, len); } else { - *dest = strcopy(comp, len); + *dest = iso_util_strcopy(comp, len); } if (*dest == NULL) { return ISO_OUT_OF_MEM; diff --git a/libisofs/util.c b/libisofs/util.c index 227c20a..3ef6a8e 100644 --- a/libisofs/util.c +++ b/libisofs/util.c @@ -1381,6 +1381,10 @@ int iso_eaccess(const char *path) return ISO_SUCCESS; } + +#ifdef NIX +/* <<< Buggy and not used any more */ + char *strcopy(const char *buf, size_t len) { char *str; @@ -1401,24 +1405,37 @@ char *strcopy(const char *buf, size_t len) return str; } -char *iso_util_strcopy_untail(const char *buf, size_t len) +#endif /* NIX */ + + +char *iso_util_strcopy(const char *buf, size_t len) { char *str; - str = malloc((len + 1) * sizeof(char)); + str = calloc(len + 1, 1); if (str == NULL) { return NULL; } strncpy(str, buf, len); - str[len] = 0; + str[len] = '\0'; + return str; +} + + +char *iso_util_strcopy_untail(const char *buf, size_t len) +{ + char *str; + str = iso_util_strcopy(buf, len); + if (str == NULL) { + return NULL; + } /* remove trailing spaces */ for (len = len-1; len >= 0; --len) { if (str[len] != ' ') break; str[len] = 0; } - return str; } diff --git a/libisofs/util.h b/libisofs/util.h index 9f51390..ec8c06d 100644 --- a/libisofs/util.h +++ b/libisofs/util.h @@ -246,6 +246,9 @@ time_t iso_datetime_read_17(const uint8_t *buf); */ int iso_eaccess(const char *path); +#ifdef NIX +/* <<< Buggy and not used any more */ + /** * Copy up to \p len chars from \p buf and return this newly allocated * string. The new string is null-terminated. @@ -255,6 +258,14 @@ int iso_eaccess(const char *path); */ char *strcopy(const char *buf, size_t len); +#endif /* NIX */ + +/** + * Copy up to \p len chars from \p buf and return this newly allocated + * string. The new string is null-terminated. + */ +char *iso_util_strcopy(const char *buf, size_t len); + /** * Copy up to \p len chars from \p buf and return this newly allocated * string. The new string is null-terminated.