Subversion Repositories freemyipod

Rev

Rev 694 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
693 user890104 1
#include <stdio.h>
2
 
3
#include <libusb-1.0/libusb.h>
4
 
5
#include "misc.h"
6
 
7
const char *libusb_error_messages[13] = {
8
	"No error",					/* LIBUSB_SUCCESS = 0 */
9
	"Input/output error",		/* LIBUSB_ERROR_IO = -1 */
10
	"Invalid parameter",		/* LIBUSB_ERROR_INVALID_PARAM = -2 */
11
	"Access denied",			/* LIBUSB_ERROR_ACCESS = -3 */
12
	"No such device",			/* LIBUSB_ERROR_NO_DEVICE = -4 */
13
	"Entity not found",			/* LIBUSB_ERROR_NOT_FOUND = -5 */
14
	"Resource busy",			/* LIBUSB_ERROR_BUSY = -6 */
15
	"Operation timed out",		/* LIBUSB_ERROR_TIMEOUT = -7 */
16
	"Overflow",					/* LIBUSB_ERROR_OVERFLOW = -8 */
17
	"Pipe error",				/* LIBUSB_ERROR_PIPE = -9 */
18
	"System call interrupted",	/* LIBUSB_ERROR_INTERRUPTED = -10 */
19
	"Insufficient memory",		/* LIBUSB_ERROR_NO_MEM = -11 */
20
	"Operation not supported",	/* LIBUSB_ERROR_NOT_SUPPORTED = -12 */
21
};
22
 
23
long int fgetsize(FILE *fp) {
24
	static long int pos, size;
25
 
26
	if (-1L == (pos = ftell(fp))) {
27
		perror("ftell");
28
 
29
		return -1L;
30
	}
31
 
32
	if(fseek(fp, 0L, SEEK_END)) {
33
		perror("fseek");
34
 
35
		return -1L;
36
	}
37
 
38
	if (-1L == (size = ftell(fp))) {
39
		perror("ftell");
40
 
41
		return -1L;
42
	}
43
 
44
	if (fseek(fp, pos, SEEK_SET)) {
45
		perror("fseek");
46
 
47
		return -1L;
48
	}
49
 
50
	return size;
51
}
52
 
53
void dump_packet(const unsigned char *data, const unsigned int length) {
54
	static unsigned int i;
55
 
56
	for (i = 0; i < length; ++i) {
57
		printf("%02x ", data[i]);
58
 
59
		if (i % 4 == 3) {
60
			printf(" ");
61
		}
62
 
63
		if (i % 16 == 15 && i + 1 < length) {
64
			printf("\n");
65
		}
66
	}
67
 
68
	printf("\n");
69
}
70
 
71
void print_error(const int code) {
72
	if (code > 0) {	
73
		fprintf(stderr, "error: code %d\n", code);
74
	}
75
	else {
76
		fprintf(stderr, "libusb error: %s (code %d)\n", (
77
			LIBUSB_ERROR_OTHER == code || code > 0 ?
78
				"unspecified" :
79
				libusb_error_messages[-code]
80
		), code);
81
	}
82
}