• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqt誰得cocoawindowspythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdombtronvb.netdirectxarduinopreviewerゲームエンジン

external/efibootmgr


Commit MetaInfo

Revision61ae3905dceb2967ad70349d93ed0eb55d6b308c (tree)
Zeit2017-03-08 01:07:06
AutorMartin T. H. Sandsmark <martin.sandsmark@kde....>
CommiterPeter Jones

Log Message

Add support for parsing optional data as ucs2

Ändern Zusammenfassung

Diff

--- a/src/efibootmgr.8
+++ b/src/efibootmgr.8
@@ -106,7 +106,7 @@ Boot Manager timeout, in \fIseconds\fR\&.
106106 Delete Timeout variable.
107107 .TP
108108 \fB-u | --unicode | --UCS-2 \fR
109-pass extra command line arguments as UCS-2 (default is
109+Handle extra command line arguments as UCS-2 (default is
110110 ASCII)
111111 .TP
112112 \fB-v | --verbose\fR
--- a/src/efibootmgr.c
+++ b/src/efibootmgr.c
@@ -868,6 +868,36 @@ err:
868868 return rc;
869869 }
870870
871+#define ev_bits(val, mask, shift) \
872+ (((val) & ((mask) << (shift))) >> (shift))
873+
874+static inline char *
875+ucs2_to_utf8(const uint16_t * const chars, ssize_t limit)
876+{
877+ ssize_t i, j;
878+ char *ret;
879+
880+ ret = alloca(limit * 6 + 1);
881+ if (!ret)
882+ return NULL;
883+ memset(ret, 0, limit * 6 +1);
884+
885+ for (i=0, j=0; chars[i] && i < (limit >= 0 ? limit : i+1); i++,j++) {
886+ if (chars[i] <= 0x7f) {
887+ ret[j] = chars[i];
888+ } else if (chars[i] > 0x7f && chars[i] <= 0x7ff) {
889+ ret[j++] = 0xc0 | ev_bits(chars[i], 0x1f, 6);
890+ ret[j] = 0x80 | ev_bits(chars[i], 0x3f, 0);
891+ } else if (chars[i] > 0x7ff) {
892+ ret[j++] = 0xe0 | ev_bits(chars[i], 0xf, 12);
893+ ret[j++] = 0x80 | ev_bits(chars[i], 0x3f, 6);
894+ ret[j] = 0x80| ev_bits(chars[i], 0x3f, 0);
895+ }
896+ }
897+ ret[j] = '\0';
898+ return strdup(ret);
899+}
900+
871901 static void
872902 show_vars(const char *prefix)
873903 {
@@ -928,19 +958,23 @@ show_vars(const char *prefix)
928958 if (rc < 0)
929959 error(21, "Could not parse optional data");
930960
931- rc = unparse_raw_text(NULL, 0, optional_data,
932- optional_data_len);
933- if (rc < 0)
934- error(22, "Could not parse optional data");
935- rc += 1;
936- text_path_len = rc;
937- text_path = calloc(1, rc);
938- if (!text_path)
939- error(23, "Could not parse optional data");
940- rc = unparse_raw_text(text_path, text_path_len,
941- optional_data, optional_data_len);
942- if (rc < 0)
943- error(24, "Could not parse device path");
961+ if (opts.unicode) {
962+ text_path = ucs2_to_utf8((uint16_t*)optional_data, optional_data_len/2);
963+ } else {
964+ rc = unparse_raw_text(NULL, 0, optional_data,
965+ optional_data_len);
966+ if (rc < 0)
967+ error(22, "Could not parse optional data");
968+ rc += 1;
969+ text_path_len = rc;
970+ text_path = calloc(1, rc);
971+ if (!text_path)
972+ error(23, "Could not parse optional data");
973+ rc = unparse_raw_text(text_path, text_path_len,
974+ optional_data, optional_data_len);
975+ if (rc < 0)
976+ error(24, "Could not parse device path");
977+ }
944978 printf("%s", text_path);
945979 free(text_path);
946980 }
@@ -1211,7 +1245,7 @@ usage()
12111245 printf("\t-q | --quiet be quiet\n");
12121246 printf("\t-t | --timeout seconds set boot manager timeout waiting for user input.\n");
12131247 printf("\t-T | --delete-timeout delete Timeout.\n");
1214- printf("\t-u | --unicode | --UCS-2 pass extra args as UCS-2 (default is ASCII)\n");
1248+ printf("\t-u | --unicode | --UCS-2 handle extra args as UCS-2 (default is ASCII)\n");
12151249 printf("\t-v | --verbose print additional information\n");
12161250 printf("\t-V | --version return version and exit\n");
12171251 printf("\t-w | --write-signature write unique sig to MBR if needed\n");