diff options
Diffstat (limited to 'rbutil/mks5lboot/main.c')
-rw-r--r-- | rbutil/mks5lboot/main.c | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/rbutil/mks5lboot/main.c b/rbutil/mks5lboot/main.c index 98c85b9bb7..31e16eca82 100644 --- a/rbutil/mks5lboot/main.c +++ b/rbutil/mks5lboot/main.c | |||
@@ -24,7 +24,6 @@ | |||
24 | #include <string.h> | 24 | #include <string.h> |
25 | #include <unistd.h> | 25 | #include <unistd.h> |
26 | #include <fcntl.h> | 26 | #include <fcntl.h> |
27 | #include <time.h> | ||
28 | #include <sys/types.h> | 27 | #include <sys/types.h> |
29 | #include <sys/stat.h> | 28 | #include <sys/stat.h> |
30 | 29 | ||
@@ -35,9 +34,23 @@ | |||
35 | #define O_BINARY 0 | 34 | #define O_BINARY 0 |
36 | #endif | 35 | #endif |
37 | 36 | ||
37 | #ifdef WIN32 | ||
38 | #include <windows.h> | ||
39 | #define sleep_ms(ms) Sleep(ms) | ||
40 | #else | ||
41 | #include <time.h> | ||
42 | static void sleep_ms(unsigned int ms) | ||
43 | { | ||
44 | struct timespec req; | ||
45 | req.tv_sec = ms / 1000; | ||
46 | req.tv_nsec = (ms % 1000) * 1000000; | ||
47 | nanosleep(&req, NULL); | ||
48 | } | ||
49 | #endif | ||
50 | |||
38 | #define DEFAULT_LOOP_PERIOD 1 /* seconds */ | 51 | #define DEFAULT_LOOP_PERIOD 1 /* seconds */ |
39 | 52 | ||
40 | #define ERROR(format, ...) \ | 53 | #define _ERR(format, ...) \ |
41 | do { \ | 54 | do { \ |
42 | snprintf(errstr, errstrsize, "[ERR] "format, __VA_ARGS__); \ | 55 | snprintf(errstr, errstrsize, "[ERR] "format, __VA_ARGS__); \ |
43 | goto error; \ | 56 | goto error; \ |
@@ -48,10 +61,10 @@ static int write_file(char *outfile, unsigned char* buf, | |||
48 | { | 61 | { |
49 | int fd = open(outfile, O_CREAT|O_TRUNC|O_WRONLY|O_BINARY, 0666); | 62 | int fd = open(outfile, O_CREAT|O_TRUNC|O_WRONLY|O_BINARY, 0666); |
50 | if (fd < 0) | 63 | if (fd < 0) |
51 | ERROR("Could not open %s for writing", outfile); | 64 | _ERR("Could not open %s for writing", outfile); |
52 | 65 | ||
53 | if (write(fd, buf, bufsize) != bufsize) | 66 | if (write(fd, buf, bufsize) != bufsize) |
54 | ERROR("Could not write file %s", outfile); | 67 | _ERR("Could not write file %s", outfile); |
55 | 68 | ||
56 | return 1; | 69 | return 1; |
57 | 70 | ||
@@ -68,19 +81,19 @@ static unsigned char *read_file(char *infile, int *bufsize, | |||
68 | 81 | ||
69 | fd = open(infile, O_RDONLY|O_BINARY); | 82 | fd = open(infile, O_RDONLY|O_BINARY); |
70 | if (fd < 0) | 83 | if (fd < 0) |
71 | ERROR("Could not open %s for reading", infile); | 84 | _ERR("Could not open %s for reading", infile); |
72 | 85 | ||
73 | if (fstat(fd, &s) < 0) | 86 | if (fstat(fd, &s) < 0) |
74 | ERROR("Checking size of input file %s", infile); | 87 | _ERR("Checking size of input file %s", infile); |
75 | 88 | ||
76 | *bufsize = s.st_size; | 89 | *bufsize = s.st_size; |
77 | 90 | ||
78 | buf = malloc(*bufsize); | 91 | buf = malloc(*bufsize); |
79 | if (buf == NULL) | 92 | if (buf == NULL) |
80 | ERROR("Could not allocate memory for %s", infile); | 93 | _ERR("Could not allocate memory for %s", infile); |
81 | 94 | ||
82 | if (read(fd, buf, *bufsize) != *bufsize) | 95 | if (read(fd, buf, *bufsize) != *bufsize) |
83 | ERROR("Could not read file %s", infile); | 96 | _ERR("Could not read file %s", infile); |
84 | 97 | ||
85 | return buf; | 98 | return buf; |
86 | 99 | ||
@@ -88,14 +101,6 @@ error: | |||
88 | return NULL; | 101 | return NULL; |
89 | } | 102 | } |
90 | 103 | ||
91 | static void sleep_ms(unsigned int ms) | ||
92 | { | ||
93 | struct timespec req; | ||
94 | req.tv_sec = ms / 1000; | ||
95 | req.tv_nsec = (ms % 1000) * 1000000; | ||
96 | nanosleep(&req, NULL); | ||
97 | } | ||
98 | |||
99 | static void usage(void) | 104 | static void usage(void) |
100 | { | 105 | { |
101 | fprintf(stderr, | 106 | fprintf(stderr, |
@@ -169,7 +174,11 @@ int main(int argc, char* argv[]) | |||
169 | int dfusize; | 174 | int dfusize; |
170 | 175 | ||
171 | fprintf(stderr, | 176 | fprintf(stderr, |
177 | #if defined(WIN32) && defined(USE_LIBUSBAPI) | ||
178 | "mks5lboot Version " VERSION " (libusb)\n" | ||
179 | #else | ||
172 | "mks5lboot Version " VERSION "\n" | 180 | "mks5lboot Version " VERSION "\n" |
181 | #endif | ||
173 | "This is free software; see the source for copying conditions. There is NO\n" | 182 | "This is free software; see the source for copying conditions. There is NO\n" |
174 | "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" | 183 | "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" |
175 | "\n"); | 184 | "\n"); |