summaryrefslogtreecommitdiffstats
path: root/libblkid
diff options
context:
space:
mode:
authorPali Rohár2017-05-16 23:51:50 +0200
committerPali Rohár2017-05-16 23:51:50 +0200
commit98bc12ab483858bbbd8b2c4b8de33e9679e957e3 (patch)
treefbe56fe9b789d5e790e1ddb654f374b084905547 /libblkid
parentsu: remove duplicate const declaration (diff)
downloadkernel-qcow2-util-linux-98bc12ab483858bbbd8b2c4b8de33e9679e957e3.tar.gz
kernel-qcow2-util-linux-98bc12ab483858bbbd8b2c4b8de33e9679e957e3.tar.xz
kernel-qcow2-util-linux-98bc12ab483858bbbd8b2c4b8de33e9679e957e3.zip
libblkid: Add support for Latin1 encoding in blkid_encode_to_utf8()
Diffstat (limited to 'libblkid')
-rw-r--r--libblkid/src/blkidP.h1
-rw-r--r--libblkid/src/encode.c17
2 files changed, 15 insertions, 3 deletions
diff --git a/libblkid/src/blkidP.h b/libblkid/src/blkidP.h
index de41473a8..4a148357a 100644
--- a/libblkid/src/blkidP.h
+++ b/libblkid/src/blkidP.h
@@ -543,5 +543,6 @@ extern size_t blkid_encode_to_utf8(int enc, unsigned char *dest, size_t len,
#define BLKID_ENC_UTF16BE 0
#define BLKID_ENC_UTF16LE 1
+#define BLKID_ENC_LATIN1 2
#endif /* _BLKID_BLKIDP_H */
diff --git a/libblkid/src/encode.c b/libblkid/src/encode.c
index b5b4363af..33d349127 100644
--- a/libblkid/src/encode.c
+++ b/libblkid/src/encode.c
@@ -239,11 +239,22 @@ size_t blkid_encode_to_utf8(int enc, unsigned char *dest, size_t len,
size_t i, j;
uint16_t c;
- for (j = i = 0; i + 2 <= count; i += 2) {
- if (enc == BLKID_ENC_UTF16LE)
+ for (j = i = 0; i < count; i++) {
+ if (enc == BLKID_ENC_UTF16LE) {
+ if (i+2 > count)
+ break;
c = (src[i+1] << 8) | src[i];
- else /* BLKID_ENC_UTF16BE */
+ i++;
+ } else if (enc == BLKID_ENC_UTF16BE) {
+ if (i+2 > count)
+ break;
c = (src[i] << 8) | src[i+1];
+ i++;
+ } else if (enc == BLKID_ENC_LATIN1) {
+ c = src[i];
+ } else {
+ return 0;
+ }
if (c == 0) {
dest[j] = '\0';
break;