From: Nicolas Cornu Date: Thu, 11 Dec 2014 20:36:08 +0000 (+0100) Subject: Add a support for utf-8 in archive_entry fields X-Git-Tag: v3.1.900a~156^2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bdae59c77256f4325d91a93ea0f95e3e92fdf10f;p=thirdparty%2Flibarchive.git Add a support for utf-8 in archive_entry fields --- diff --git a/libarchive/archive_entry.c b/libarchive/archive_entry.c index 293c7016a..7958a17e3 100644 --- a/libarchive/archive_entry.c +++ b/libarchive/archive_entry.c @@ -418,6 +418,18 @@ archive_entry_gname(struct archive_entry *entry) return (NULL); } +const char * +archive_entry_gname_utf8(struct archive_entry *entry) +{ + const char *p; + if (archive_mstring_get_utf8(entry->archive, &entry->ae_gname, &p) == 0) + return (p); + if (errno == ENOMEM) + __archive_errx(1, "No memory"); + return (NULL); +} + + const wchar_t * archive_entry_gname_w(struct archive_entry *entry) { @@ -450,6 +462,20 @@ archive_entry_hardlink(struct archive_entry *entry) return (NULL); } +const char * +archive_entry_hardlink_utf8(struct archive_entry *entry) +{ + const char *p; + if ((entry->ae_set & AE_SET_HARDLINK) == 0) + return (NULL); + if (archive_mstring_get_utf8( + entry->archive, &entry->ae_hardlink, &p) == 0) + return (p); + if (errno == ENOMEM) + __archive_errx(1, "No memory"); + return (NULL); +} + const wchar_t * archive_entry_hardlink_w(struct archive_entry *entry) { @@ -536,6 +562,18 @@ archive_entry_pathname(struct archive_entry *entry) return (NULL); } +const char * +archive_entry_pathname_utf8(struct archive_entry *entry) +{ + const char *p; + if (archive_mstring_get_utf8( + entry->archive, &entry->ae_pathname, &p) == 0) + return (p); + if (errno == ENOMEM) + __archive_errx(1, "No memory"); + return (NULL); +} + const wchar_t * archive_entry_pathname_w(struct archive_entry *entry) { @@ -637,6 +675,20 @@ archive_entry_symlink(struct archive_entry *entry) return (NULL); } +const char * +archive_entry_symlink_utf8(struct archive_entry *entry) +{ + const char *p; + if ((entry->ae_set & AE_SET_SYMLINK) == 0) + return (NULL); + if (archive_mstring_get_utf8( + entry->archive, &entry->ae_symlink, &p) == 0) + return (p); + if (errno == ENOMEM) + __archive_errx(1, "No memory"); + return (NULL); +} + const wchar_t * archive_entry_symlink_w(struct archive_entry *entry) { @@ -680,6 +732,17 @@ archive_entry_uname(struct archive_entry *entry) return (NULL); } +const char * +archive_entry_uname_utf8(struct archive_entry *entry) +{ + const char *p; + if (archive_mstring_get_utf8(entry->archive, &entry->ae_uname, &p) == 0) + return (p); + if (errno == ENOMEM) + __archive_errx(1, "No memory"); + return (NULL); +} + const wchar_t * archive_entry_uname_w(struct archive_entry *entry) { @@ -768,6 +831,12 @@ archive_entry_set_gname(struct archive_entry *entry, const char *name) archive_mstring_copy_mbs(&entry->ae_gname, name); } +void +archive_entry_set_gname_utf8(struct archive_entry *entry, const char *name) +{ + archive_mstring_copy_utf8(&entry->ae_gname, name); +} + void archive_entry_copy_gname(struct archive_entry *entry, const char *name) { @@ -824,6 +893,16 @@ archive_entry_set_hardlink(struct archive_entry *entry, const char *target) entry->ae_set &= ~AE_SET_HARDLINK; } +void +archive_entry_set_hardlink_utf8(struct archive_entry *entry, const char *target) +{ + archive_mstring_copy_utf8(&entry->ae_hardlink, target); + if (target != NULL) + entry->ae_set |= AE_SET_HARDLINK; + else + entry->ae_set &= ~AE_SET_HARDLINK; +} + void archive_entry_copy_hardlink(struct archive_entry *entry, const char *target) { @@ -962,6 +1041,15 @@ archive_entry_set_link(struct archive_entry *entry, const char *target) archive_mstring_copy_mbs(&entry->ae_hardlink, target); } +void +archive_entry_set_link_utf8(struct archive_entry *entry, const char *target) +{ + if (entry->ae_set & AE_SET_SYMLINK) + archive_mstring_copy_utf8(&entry->ae_symlink, target); + else + archive_mstring_copy_utf8(&entry->ae_hardlink, target); +} + /* Set symlink if symlink is already set, else set hardlink. */ void archive_entry_copy_link(struct archive_entry *entry, const char *target) @@ -1051,6 +1139,12 @@ archive_entry_set_pathname(struct archive_entry *entry, const char *name) archive_mstring_copy_mbs(&entry->ae_pathname, name); } +void +archive_entry_set_pathname_utf8(struct archive_entry *entry, const char *name) +{ + archive_mstring_copy_utf8(&entry->ae_pathname, name); +} + void archive_entry_copy_pathname(struct archive_entry *entry, const char *name) { @@ -1151,6 +1245,16 @@ archive_entry_set_symlink(struct archive_entry *entry, const char *linkname) entry->ae_set &= ~AE_SET_SYMLINK; } +void +archive_entry_set_symlink_utf8(struct archive_entry *entry, const char *linkname) +{ + archive_mstring_copy_utf8(&entry->ae_symlink, linkname); + if (linkname != NULL) + entry->ae_set |= AE_SET_SYMLINK; + else + entry->ae_set &= ~AE_SET_SYMLINK; +} + void archive_entry_copy_symlink(struct archive_entry *entry, const char *linkname) { @@ -1214,6 +1318,12 @@ archive_entry_set_uname(struct archive_entry *entry, const char *name) archive_mstring_copy_mbs(&entry->ae_uname, name); } +void +archive_entry_set_uname_utf8(struct archive_entry *entry, const char *name) +{ + archive_mstring_copy_utf8(&entry->ae_uname, name); +} + void archive_entry_copy_uname(struct archive_entry *entry, const char *name) { diff --git a/libarchive/archive_entry.h b/libarchive/archive_entry.h index ff5350a8e..9f7fafecd 100644 --- a/libarchive/archive_entry.h +++ b/libarchive/archive_entry.h @@ -208,8 +208,10 @@ __LA_DECL void archive_entry_fflags(struct archive_entry *, __LA_DECL const char *archive_entry_fflags_text(struct archive_entry *); __LA_DECL __LA_INT64_T archive_entry_gid(struct archive_entry *); __LA_DECL const char *archive_entry_gname(struct archive_entry *); +__LA_DECL const char *archive_entry_gname_utf8(struct archive_entry *); __LA_DECL const wchar_t *archive_entry_gname_w(struct archive_entry *); __LA_DECL const char *archive_entry_hardlink(struct archive_entry *); +__LA_DECL const char *archive_entry_hardlink_utf8(struct archive_entry *); __LA_DECL const wchar_t *archive_entry_hardlink_w(struct archive_entry *); __LA_DECL __LA_INT64_T archive_entry_ino(struct archive_entry *); __LA_DECL __LA_INT64_T archive_entry_ino64(struct archive_entry *); @@ -220,6 +222,7 @@ __LA_DECL long archive_entry_mtime_nsec(struct archive_entry *); __LA_DECL int archive_entry_mtime_is_set(struct archive_entry *); __LA_DECL unsigned int archive_entry_nlink(struct archive_entry *); __LA_DECL const char *archive_entry_pathname(struct archive_entry *); +__LA_DECL const char *archive_entry_pathname_utf8(struct archive_entry *); __LA_DECL const wchar_t *archive_entry_pathname_w(struct archive_entry *); __LA_DECL __LA_MODE_T archive_entry_perm(struct archive_entry *); __LA_DECL dev_t archive_entry_rdev(struct archive_entry *); @@ -231,9 +234,11 @@ __LA_DECL __LA_INT64_T archive_entry_size(struct archive_entry *); __LA_DECL int archive_entry_size_is_set(struct archive_entry *); __LA_DECL const char *archive_entry_strmode(struct archive_entry *); __LA_DECL const char *archive_entry_symlink(struct archive_entry *); +__LA_DECL const char *archive_entry_symlink_utf8(struct archive_entry *); __LA_DECL const wchar_t *archive_entry_symlink_w(struct archive_entry *); __LA_DECL __LA_INT64_T archive_entry_uid(struct archive_entry *); __LA_DECL const char *archive_entry_uname(struct archive_entry *); +__LA_DECL const char *archive_entry_uname_utf8(struct archive_entry *); __LA_DECL const wchar_t *archive_entry_uname_w(struct archive_entry *); __LA_DECL int archive_entry_is_data_encrypted(struct archive_entry *); __LA_DECL int archive_entry_is_metadata_encrypted(struct archive_entry *); @@ -271,16 +276,19 @@ __LA_DECL const wchar_t *archive_entry_copy_fflags_text_w(struct archive_entry * const wchar_t *); __LA_DECL void archive_entry_set_gid(struct archive_entry *, __LA_INT64_T); __LA_DECL void archive_entry_set_gname(struct archive_entry *, const char *); +__LA_DECL void archive_entry_set_gname_utf8(struct archive_entry *, const char *); __LA_DECL void archive_entry_copy_gname(struct archive_entry *, const char *); __LA_DECL void archive_entry_copy_gname_w(struct archive_entry *, const wchar_t *); __LA_DECL int archive_entry_update_gname_utf8(struct archive_entry *, const char *); __LA_DECL void archive_entry_set_hardlink(struct archive_entry *, const char *); +__LA_DECL void archive_entry_set_hardlink_utf8(struct archive_entry *, const char *); __LA_DECL void archive_entry_copy_hardlink(struct archive_entry *, const char *); __LA_DECL void archive_entry_copy_hardlink_w(struct archive_entry *, const wchar_t *); __LA_DECL int archive_entry_update_hardlink_utf8(struct archive_entry *, const char *); __LA_DECL void archive_entry_set_ino(struct archive_entry *, __LA_INT64_T); __LA_DECL void archive_entry_set_ino64(struct archive_entry *, __LA_INT64_T); __LA_DECL void archive_entry_set_link(struct archive_entry *, const char *); +__LA_DECL void archive_entry_set_link_utf8(struct archive_entry *, const char *); __LA_DECL void archive_entry_copy_link(struct archive_entry *, const char *); __LA_DECL void archive_entry_copy_link_w(struct archive_entry *, const wchar_t *); __LA_DECL int archive_entry_update_link_utf8(struct archive_entry *, const char *); @@ -289,6 +297,7 @@ __LA_DECL void archive_entry_set_mtime(struct archive_entry *, time_t, long); __LA_DECL void archive_entry_unset_mtime(struct archive_entry *); __LA_DECL void archive_entry_set_nlink(struct archive_entry *, unsigned int); __LA_DECL void archive_entry_set_pathname(struct archive_entry *, const char *); +__LA_DECL void archive_entry_set_pathname_utf8(struct archive_entry *, const char *); __LA_DECL void archive_entry_copy_pathname(struct archive_entry *, const char *); __LA_DECL void archive_entry_copy_pathname_w(struct archive_entry *, const wchar_t *); __LA_DECL int archive_entry_update_pathname_utf8(struct archive_entry *, const char *); @@ -301,11 +310,13 @@ __LA_DECL void archive_entry_unset_size(struct archive_entry *); __LA_DECL void archive_entry_copy_sourcepath(struct archive_entry *, const char *); __LA_DECL void archive_entry_copy_sourcepath_w(struct archive_entry *, const wchar_t *); __LA_DECL void archive_entry_set_symlink(struct archive_entry *, const char *); +__LA_DECL void archive_entry_set_symlink_utf8(struct archive_entry *, const char *); __LA_DECL void archive_entry_copy_symlink(struct archive_entry *, const char *); __LA_DECL void archive_entry_copy_symlink_w(struct archive_entry *, const wchar_t *); __LA_DECL int archive_entry_update_symlink_utf8(struct archive_entry *, const char *); __LA_DECL void archive_entry_set_uid(struct archive_entry *, __LA_INT64_T); __LA_DECL void archive_entry_set_uname(struct archive_entry *, const char *); +__LA_DECL void archive_entry_set_uname_utf8(struct archive_entry *, const char *); __LA_DECL void archive_entry_copy_uname(struct archive_entry *, const char *); __LA_DECL void archive_entry_copy_uname_w(struct archive_entry *, const wchar_t *); __LA_DECL int archive_entry_update_uname_utf8(struct archive_entry *, const char *); diff --git a/libarchive/archive_string.c b/libarchive/archive_string.c index 87f9288f1..eebd7642b 100644 --- a/libarchive/archive_string.c +++ b/libarchive/archive_string.c @@ -4061,6 +4061,19 @@ archive_mstring_copy_wcs(struct archive_mstring *aes, const wchar_t *wcs) wcs == NULL ? 0 : wcslen(wcs)); } +int +archive_mstring_copy_utf8(struct archive_mstring *aes, const char *utf8) +{ + if (utf8 == NULL) { + aes->aes_set = 0; + } + aes->aes_set = AES_SET_UTF8; + archive_string_empty(&(aes->aes_mbs)); + archive_string_empty(&(aes->aes_wcs)); + archive_strncpy(&(aes->aes_utf8), utf8, strlen(utf8)); + return strlen(utf8); +} + int archive_mstring_copy_wcs_len(struct archive_mstring *aes, const wchar_t *wcs, size_t len)