Browse Source

ucs2tochar{,_dup} functions to convert USB string descriptors to char* format

Luke Dashjr 12 years ago
parent
commit
93421574ce
2 changed files with 17 additions and 0 deletions
  1. 14 0
      util.c
  2. 3 0
      util.h

+ 14 - 0
util.c

@@ -722,6 +722,20 @@ badchar:
 	return likely(!hexstr[0]);
 }
 
+void ucs2tochar(char * const out, const uint16_t * const in, const size_t sz)
+{
+	for (int i = 0; i < sz; ++i)
+		out[i] = in[i];
+}
+
+char *ucs2tochar_dup(uint16_t * const in, const size_t sz)
+{
+	char *out = malloc(sz + 1);
+	ucs2tochar(out, in, sz);
+	out[sz] = '\0';
+	return out;
+}
+
 void hash_data(unsigned char *out_hash, const unsigned char *data)
 {
 	unsigned char blkheader[80];

+ 3 - 0
util.h

@@ -112,6 +112,9 @@ extern json_t *json_rpc_call_completed(CURL *, int rc, bool probe, int *rolltime
 
 extern char *absolute_uri(char *uri, const char *ref);  // ref must be a root URI
 
+extern void ucs2tochar(char *out, const uint16_t *in, size_t sz);
+extern char *ucs2tochar_dup(uint16_t *in, size_t sz);
+
 extern void gen_hash(unsigned char *data, unsigned char *hash, int len);
 extern void hash_data(unsigned char *out_hash, const unsigned char *data);
 extern void real_block_target(unsigned char *target, const unsigned char *data);