diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2012-09-02 15:33:47 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2012-09-02 15:33:47 +0200 |
commit | 8019b3a7aea51343f79922928c91ef833344b743 (patch) | |
tree | 37db8a6598b3320a50894f7a54938e6c5e1a89bf /util-linux | |
parent | 11f2c0d4f87ab7b1bb08632bfb67b1eb2df5f0e4 (diff) | |
download | busybox-w32-8019b3a7aea51343f79922928c91ef833344b743.tar.gz busybox-w32-8019b3a7aea51343f79922928c91ef833344b743.tar.bz2 busybox-w32-8019b3a7aea51343f79922928c91ef833344b743.zip |
volume_id: code shrink
function old new delta
volume_id_set_unicode16 200 173 -27
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux')
-rw-r--r-- | util-linux/volume_id/util.c | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/util-linux/volume_id/util.c b/util-linux/volume_id/util.c index dd75c7ba1..69e43dda8 100644 --- a/util-linux/volume_id/util.c +++ b/util-linux/volume_id/util.c | |||
@@ -31,25 +31,29 @@ void volume_id_set_unicode16(char *str, size_t len, const uint8_t *buf, enum end | |||
31 | c = (buf[i+1] << 8) | buf[i]; | 31 | c = (buf[i+1] << 8) | buf[i]; |
32 | else | 32 | else |
33 | c = (buf[i] << 8) | buf[i+1]; | 33 | c = (buf[i] << 8) | buf[i+1]; |
34 | if (c == 0) { | 34 | if (c == 0) |
35 | str[j] = '\0'; | ||
36 | break; | 35 | break; |
37 | } else if (c < 0x80) { | 36 | if (j+1 >= len) |
38 | if (j+1 >= len) | 37 | break; |
39 | break; | 38 | if (c < 0x80) { |
40 | str[j++] = (uint8_t) c; | 39 | /* 0xxxxxxx */ |
41 | } else if (c < 0x800) { | ||
42 | if (j+2 >= len) | ||
43 | break; | ||
44 | str[j++] = (uint8_t) (0xc0 | (c >> 6)); | ||
45 | str[j++] = (uint8_t) (0x80 | (c & 0x3f)); | ||
46 | } else { | 40 | } else { |
47 | if (j+3 >= len) | 41 | uint8_t topbits = 0xc0; |
42 | if (j+2 >= len) | ||
48 | break; | 43 | break; |
49 | str[j++] = (uint8_t) (0xe0 | (c >> 12)); | 44 | if (c < 0x800) { |
50 | str[j++] = (uint8_t) (0x80 | ((c >> 6) & 0x3f)); | 45 | /* 110yyyxx 10xxxxxx */ |
51 | str[j++] = (uint8_t) (0x80 | (c & 0x3f)); | 46 | } else { |
47 | if (j+3 >= len) | ||
48 | break; | ||
49 | /* 1110yyyy 10yyyyxx 10xxxxxx */ | ||
50 | str[j++] = (uint8_t) (0xe0 | (c >> 12)); | ||
51 | topbits = 0x80; | ||
52 | } | ||
53 | str[j++] = (uint8_t) (topbits | ((c >> 6) & 0x3f)); | ||
54 | c = 0x80 | (c & 0x3f); | ||
52 | } | 55 | } |
56 | str[j++] = (uint8_t) c; | ||
53 | } | 57 | } |
54 | str[j] = '\0'; | 58 | str[j] = '\0'; |
55 | } | 59 | } |