summaryrefslogtreecommitdiff
path: root/rbutil
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2012-04-28 12:02:48 +0200
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2012-04-28 12:05:11 +0200
commitb4424ca2f3902459571098eb2d955fefca400d9f (patch)
treed30e355eeac5e291593482d56cbb570142523bf5 /rbutil
parentfe3d58004cf28fb98dd29159187d256aaf5d0781 (diff)
downloadrockbox-b4424ca2f3902459571098eb2d955fefca400d9f.tar.gz
rockbox-b4424ca2f3902459571098eb2d955fefca400d9f.zip
Add "ipod" mode to bin2c.
ipod2c is identical to bin2c except it skipping the header of the input files. Add this behaviour as option to bin2c to be able of using bin2c instead of ipod2c. Change-Id: I71afcaca6f2f6b0fce4c6aa3dff6be5bb205f384
Diffstat (limited to 'rbutil')
-rw-r--r--rbutil/tools/bin2c.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/rbutil/tools/bin2c.c b/rbutil/tools/bin2c.c
index 36e245133e..4600746d52 100644
--- a/rbutil/tools/bin2c.c
+++ b/rbutil/tools/bin2c.c
@@ -5,7 +5,6 @@
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * $Id$
9 * 8 *
10 * Copyright (C) 2007 Dave Chapman 9 * Copyright (C) 2007 Dave Chapman
11 * 10 *
@@ -40,6 +39,13 @@
40#define O_BINARY 0 39#define O_BINARY 0
41#endif 40#endif
42 41
42static void usage(void)
43{
44 fprintf(stderr, "bin2c [options] infile cfile\n");
45 fprintf(stderr, " -i ipod mode\n");
46}
47
48
43static off_t filesize(int fd) 49static off_t filesize(int fd)
44{ 50{
45 struct stat buf; 51 struct stat buf;
@@ -116,14 +122,25 @@ int main (int argc, char* argv[])
116 unsigned char* buf; 122 unsigned char* buf;
117 int len; 123 int len;
118 int n; 124 int n;
125 int skip = 0;
126 int opts = 0;
127
119 128
120 if (argc != 3) { 129 if(argc < 2) {
121 fprintf(stderr,"Usage: bin2c file cname\n"); 130 usage();
131 return 0;
132 }
133 if(strcmp(argv[1], "-i") == 0) {
134 skip = 8;
135 opts++;
136 }
137 if (argc < opts + 3) {
138 usage();
122 return 0; 139 return 0;
123 } 140 }
124 141
125 infile=argv[1]; 142 infile=argv[opts + 1];
126 cname=argv[2]; 143 cname=argv[opts + 2];
127 144
128 fd = open(infile,O_RDONLY|O_BINARY); 145 fd = open(infile,O_RDONLY|O_BINARY);
129 if (fd < 0) { 146 if (fd < 0) {
@@ -131,7 +148,12 @@ int main (int argc, char* argv[])
131 return 0; 148 return 0;
132 } 149 }
133 150
134 len = filesize(fd); 151 len = filesize(fd) - skip;
152 n = lseek(fd, skip, SEEK_SET);
153 if (n != skip) {
154 fprintf(stderr,"Seek failed\n");
155 return 0;
156 }
135 157
136 buf = malloc(len); 158 buf = malloc(len);
137 n = read(fd,buf,len); 159 n = read(fd,buf,len);