OSDN Git Service

blkid: fix warnings and remove duplicate code
authorChih-Wei Huang <cwhuang@linux.org.tw>
Fri, 21 Aug 2015 09:59:13 +0000 (17:59 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Fri, 21 Aug 2015 09:59:13 +0000 (17:59 +0800)
Move unicode_16le_to_utf8 to probe.c and export it
so probe_*.c can use it.

lib/blkid/blkidP.h
lib/blkid/probe.c
lib/blkid/probe_exfat.c
lib/blkid/probe_f2fs.c

index c421312..83507c4 100644 (file)
@@ -186,6 +186,10 @@ extern int blkid_set_tag(blkid_dev dev, const char *name,
 extern blkid_dev blkid_new_dev(void);
 extern void blkid_free_dev(blkid_dev dev);
 
+/* probe.c */
+extern void unicode_16le_to_utf8(char *s, int out_len,
+                                 const unsigned char *buf, int in_len);
+
 #ifdef __cplusplus
 }
 #endif
index 83f5e2e..3c18c11 100644 (file)
@@ -44,6 +44,38 @@ extern int probe_f2fs(struct blkid_probe *probe,
                      struct blkid_magic *id __BLKID_ATTR((unused)),
                      unsigned char *buf);
 
+void unicode_16le_to_utf8(char *s, int out_len,
+                          const unsigned char *buf, int in_len)
+{
+       int i, j;
+       unsigned int c;
+       unsigned char *str = (unsigned char *)s;
+
+       for (i = j = 0; i + 2 <= in_len; i += 2) {
+               c = (buf[i+1] << 8) | buf[i];
+               if (c == 0) {
+                       str[j] = '\0';
+                       break;
+               } else if (c < 0x80) {
+                       if (j+1 >= out_len)
+                               break;
+                       str[j++] = (unsigned char) c;
+               } else if (c < 0x800) {
+                       if (j+2 >= out_len)
+                               break;
+                       str[j++] = (unsigned char) (0xc0 | (c >> 6));
+                       str[j++] = (unsigned char) (0x80 | (c & 0x3f));
+               } else {
+                       if (j+3 >= out_len)
+                               break;
+                       str[j++] = (unsigned char) (0xe0 | (c >> 12));
+                       str[j++] = (unsigned char) (0x80 | ((c >> 6) & 0x3f));
+                       str[j++] = (unsigned char) (0x80 | (c & 0x3f));
+               }
+       }
+       str[j] = '\0';
+}
+
 static int figure_label_len(const unsigned char *label, int len)
 {
        const unsigned char *end = label + len - 1;
index 0396ad4..d433c57 100644 (file)
@@ -125,38 +125,6 @@ static struct exfat_entry_label *find_label(blkid_probe pr,
        }
 }
 
-static void unicode_16le_to_utf8(char *s, int out_len,
-                                const unsigned char *buf, int in_len)
-{
-       int i, j;
-       unsigned int c;
-       unsigned char *str = (unsigned char *)s;
-
-       for (i = j = 0; i + 2 <= in_len; i += 2) {
-               c = (buf[i+1] << 8) | buf[i];
-               if (c == 0) {
-                       str[j] = '\0';
-                       break;
-               } else if (c < 0x80) {
-                       if (j+1 >= out_len)
-                               break;
-                       str[j++] = (unsigned char) c;
-               } else if (c < 0x800) {
-                       if (j+2 >= out_len)
-                               break;
-                       str[j++] = (unsigned char) (0xc0 | (c >> 6));
-                       str[j++] = (unsigned char) (0x80 | (c & 0x3f));
-               } else {
-                       if (j+3 >= out_len)
-                               break;
-                       str[j++] = (unsigned char) (0xe0 | (c >> 12));
-                       str[j++] = (unsigned char) (0x80 | ((c >> 6) & 0x3f));
-                       str[j++] = (unsigned char) (0x80 | (c & 0x3f));
-               }
-       }
-       str[j] = '\0';
-}
-
 int probe_exfat(struct blkid_probe *probe,
                      struct blkid_magic *id __BLKID_ATTR((unused)),
                      unsigned char *buf)
index d1d81a4..ecd15b0 100644 (file)
@@ -63,37 +63,6 @@ struct f2fs_super_block {                            /* According to version 1.1 */
 #endif
 } __attribute__((packed));
 
-static void unicode_16le_to_utf8(unsigned char *str, int out_len,
-                                const unsigned char *buf, int in_len)
-{
-       int i, j;
-       unsigned int c;
-
-       for (i = j = 0; i + 2 <= in_len; i += 2) {
-               c = (buf[i+1] << 8) | buf[i];
-               if (c == 0) {
-                       str[j] = '\0';
-                       break;
-               } else if (c < 0x80) {
-                       if (j+1 >= out_len)
-                               break;
-                       str[j++] = (unsigned char) c;
-               } else if (c < 0x800) {
-                       if (j+2 >= out_len)
-                               break;
-                       str[j++] = (unsigned char) (0xc0 | (c >> 6));
-                       str[j++] = (unsigned char) (0x80 | (c & 0x3f));
-               } else {
-                       if (j+3 >= out_len)
-                               break;
-                       str[j++] = (unsigned char) (0xe0 | (c >> 12));
-                       str[j++] = (unsigned char) (0x80 | ((c >> 6) & 0x3f));
-                       str[j++] = (unsigned char) (0x80 | (c & 0x3f));
-               }
-       }
-       str[j] = '\0';
-}
-
 int probe_f2fs(struct blkid_probe *probe,
                      struct blkid_magic *id __BLKID_ATTR((unused)),
                      unsigned char *buf)
@@ -114,7 +83,7 @@ int probe_f2fs(struct blkid_probe *probe,
                return 0;
 
        if (*((unsigned char *) sb->volume_name)) {
-               unsigned char utf8_label[512];
+               char utf8_label[512];
                unicode_16le_to_utf8(utf8_label, sizeof(utf8_label),
                        (unsigned char *) sb->volume_name, sizeof(sb->volume_name));
                blkid_set_tag(probe->dev, "LABEL", utf8_label, 0);