Browse Source

Add ts_hex_dump_buf()

Georgi Chorbadzhiyski 13 years ago
parent
commit
9f94b2ac34
2 changed files with 12 additions and 4 deletions
  1. 1
    0
      tsfuncs.h
  2. 11
    4
      tsfuncs_misc.c

+ 1
- 0
tsfuncs.h View File

@@ -256,6 +256,7 @@ int				ts_crc32_section_check		(struct ts_section_header *section_header, char *
256 256
 int				dec2bcd						(int dec);
257 257
 int				bcd2dec						(int bcd);
258 258
 void			ts_compare_data   			(char *prefix, uint8_t *a, uint8_t *b, int size);
259
+void			ts_hex_dump_buf    			(char *buf, int bufsz, uint8_t *d, int size, int col);
259 260
 char *			ts_hex_dump      			(uint8_t *d, int size, int col);
260 261
 void			ts_print_bytes				(char *prefix, uint8_t *d, int size);
261 262
 char *			init_dvb_string_utf8		(char *text);

+ 11
- 4
tsfuncs_misc.c View File

@@ -15,17 +15,24 @@ int bcd2dec(int bcd) {
15 15
 	return ((bcd>>4) * 10) + bcd % 16;
16 16
 }
17 17
 
18
-char *ts_hex_dump(uint8_t *d, int size, int col) {
18
+void ts_hex_dump_buf(char *buf, int bufsz, uint8_t *d, int size, int col) {
19 19
 	int i;
20
-	char *buf = calloc(1, size * 6);
21
-	if (!buf)
22
-		return NULL;
20
+	if (bufsz < size * 6)
21
+		return;
22
+	memset(buf, 0, bufsz);
23 23
 	for (i=0;i<size;i++) {
24 24
 		if (col && (i % col == col - 1))
25 25
 			sprintf(buf+(i*3), "%02x\n", d[i]);
26 26
 		else
27 27
 			sprintf(buf+(i*3), "%02x ", d[i]);
28 28
 	}
29
+}
30
+
31
+char *ts_hex_dump(uint8_t *d, int size, int col) {
32
+	char *buf = malloc(size * 6);
33
+	if (!buf)
34
+		return NULL;
35
+	ts_hex_dump_buf(buf, size * 6, d, size, col);
29 36
 	return buf;
30 37
 }
31 38
 

Loading…
Cancel
Save