@@ -341,6 +341,33 @@ void ot_common_configure_devices_with_id(
341
341
ibex_connect_devices (devices , defs , count );
342
342
}
343
343
344
+ int ot_common_string_ends_with (const char * str , const char * suffix )
345
+ {
346
+ size_t str_len = strlen (str );
347
+ size_t suffix_len = strlen (suffix );
348
+
349
+ return (str_len >= suffix_len ) &&
350
+ (!memcmp (str + str_len - suffix_len , suffix , suffix_len ));
351
+ }
352
+
353
+ int ot_common_parse_hexa_str (uint8_t * out , const char * xstr , size_t olen ,
354
+ bool reverse , bool exact )
355
+ {
356
+ for (size_t ix = 0 ; ix < olen ; ix ++ ) {
357
+ gint hi = g_ascii_xdigit_value (xstr [ix * 2u ]);
358
+ if (hi < 0 ) {
359
+ return hi ;
360
+ }
361
+ gint lo = g_ascii_xdigit_value (xstr [ix * 2u + 1u ]);
362
+ if (lo < 0 ) {
363
+ return lo ;
364
+ }
365
+ out [reverse ? olen - ix - 1u : ix ] = (uint8_t )(hi << 4 ) | (uint8_t )(lo );
366
+ }
367
+
368
+ return (!exact || !xstr [olen * 2u ]) ? 0 : 1 ;
369
+ }
370
+
344
371
/*
345
372
* Unfortunately, there is no QEMU API to properly disable serial control lines
346
373
*/
@@ -364,12 +391,3 @@ void ot_common_ignore_chr_status_lines(CharBackend *chr)
364
391
tcsetattr (fioc -> fd , TCSANOW , & tty );
365
392
#endif
366
393
}
367
-
368
- int ot_common_string_ends_with (const char * str , const char * suffix )
369
- {
370
- size_t str_len = strlen (str );
371
- size_t suffix_len = strlen (suffix );
372
-
373
- return (str_len >= suffix_len ) &&
374
- (!memcmp (str + str_len - suffix_len , suffix , suffix_len ));
375
- }
0 commit comments