]> err.no Git - util-linux/commitdiff
libblkid: create a generic blkid_encode_to_utf8()
authorKarel Zak <kzak@redhat.com>
Tue, 15 Sep 2009 18:45:47 +0000 (20:45 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 15 Sep 2009 18:45:47 +0000 (20:45 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
shlibs/blkid/src/blkidP.h
shlibs/blkid/src/encode.c
shlibs/blkid/src/probe.c

index c12fdb13f4a7b401aa4e71d1be0ab12335a825fd..4ad76bd1e5416b92691b8bb1ad6c095ff441bd46 100644 (file)
@@ -340,6 +340,9 @@ extern int blkid_probe_set_uuid_as(blkid_probe pr, unsigned char *uuid, const ch
 
 extern void blkid_unparse_uuid(const unsigned char *uuid, char *str, size_t len);
 
+extern size_t blkid_encode_to_utf8(int enc, unsigned char *dest, size_t len,
+                       const unsigned char *src, size_t count);
+
 #define BLKID_ENC_UTF16BE      0
 #define BLKID_ENC_UTF16LE      1
 
index 0317be1fc7ebadc4c5b22a8865229679a4995b79..38c5d231f4b8f4bac2cc58d0c088a57f41053c3f 100644 (file)
@@ -227,6 +227,41 @@ static int replace_chars(char *str, const char *white)
        return replaced;
 }
 
+size_t blkid_encode_to_utf8(int enc, unsigned char *dest, size_t len,
+                       const unsigned char *src, size_t count)
+{
+       size_t i, j;
+       uint16_t c;
+
+       for (j = i = 0; i + 2 <= count; i += 2) {
+               if (enc == BLKID_ENC_UTF16LE)
+                       c = (src[i+1] << 8) | src[i];
+               else /* BLKID_ENC_UTF16BE */
+                       c = (src[i] << 8) | src[i+1];
+               if (c == 0) {
+                       dest[j] = '\0';
+                       break;
+               } else if (c < 0x80) {
+                       if (j+1 >= len)
+                               break;
+                       dest[j++] = (uint8_t) c;
+               } else if (c < 0x800) {
+                       if (j+2 >= len)
+                               break;
+                       dest[j++] = (uint8_t) (0xc0 | (c >> 6));
+                       dest[j++] = (uint8_t) (0x80 | (c & 0x3f));
+               } else {
+                       if (j+3 >= len)
+                               break;
+                       dest[j++] = (uint8_t) (0xe0 | (c >> 12));
+                       dest[j++] = (uint8_t) (0x80 | ((c >> 6) & 0x3f));
+                       dest[j++] = (uint8_t) (0x80 | (c & 0x3f));
+               }
+       }
+       dest[j] = '\0';
+       return j;
+}
+
 /**
  * blkid_encode_string:
  * @str: input string to be encoded
index 1b7d4b8b3c8c822ebdb8d1b31825801eedd65f9b..b9d67add49d7cdd2fde2c69ae52f67458bb57d58 100644 (file)
@@ -717,41 +717,6 @@ int blkid_probe_set_label(blkid_probe pr, unsigned char *label, size_t len)
        return 0;
 }
 
-static size_t encode_to_utf8(int enc, unsigned char *dest, size_t len,
-                       unsigned char *src, size_t count)
-{
-       size_t i, j;
-       uint16_t c;
-
-       for (j = i = 0; i + 2 <= count; i += 2) {
-               if (enc == BLKID_ENC_UTF16LE)
-                       c = (src[i+1] << 8) | src[i];
-               else /* BLKID_ENC_UTF16BE */
-                       c = (src[i] << 8) | src[i+1];
-               if (c == 0) {
-                       dest[j] = '\0';
-                       break;
-               } else if (c < 0x80) {
-                       if (j+1 >= len)
-                               break;
-                       dest[j++] = (uint8_t) c;
-               } else if (c < 0x800) {
-                       if (j+2 >= len)
-                               break;
-                       dest[j++] = (uint8_t) (0xc0 | (c >> 6));
-                       dest[j++] = (uint8_t) (0x80 | (c & 0x3f));
-               } else {
-                       if (j+3 >= len)
-                               break;
-                       dest[j++] = (uint8_t) (0xe0 | (c >> 12));
-                       dest[j++] = (uint8_t) (0x80 | ((c >> 6) & 0x3f));
-                       dest[j++] = (uint8_t) (0x80 | (c & 0x3f));
-               }
-       }
-       dest[j] = '\0';
-       return j;
-}
-
 int blkid_probe_set_utf8label(blkid_probe pr, unsigned char *label,
                                size_t len, int enc)
 {
@@ -766,7 +731,7 @@ int blkid_probe_set_utf8label(blkid_probe pr, unsigned char *label,
        if (!v)
                return -1;
 
-       v->len = encode_to_utf8(enc, v->data, sizeof(v->data), label, len);
+       v->len = blkid_encode_to_utf8(enc, v->data, sizeof(v->data), label, len);
        return 0;
 }