1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8 * $Id: ipodio-win32.c 12205 2007-02-05 01:20:20Z dave $
10 * Copyright (C) 2007 Dave Chapman
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
22 #include <sys/types.h>
32 static off_t
filesize(int fd
)
40 static int write_cfile(unsigned char* buf
, off_t len
, char* cname
)
46 snprintf(filename
,256,"%s.c",cname
);
48 fp
= fopen(filename
,"w+");
50 fprintf(stderr
,"Couldn't open %s\n",filename
);
54 fprintf(fp
,"/* Generated by ipod2c */\n\n");
55 fprintf(fp
,"unsigned char %s[] = {",cname
);
62 fprintf(fp
,"0x%02x",buf
[i
]);
64 fprintf(fp
,"0x%02x, ",buf
[i
]);
73 static int write_hfile(unsigned char* buf
, off_t len
, char* cname
)
78 snprintf(filename
,256,"%s.h",cname
);
79 fp
= fopen(filename
,"w+");
81 fprintf(stderr
,"Couldn't open %s\n",filename
);
85 fprintf(fp
,"/* Generated by ipod2c */\n\n");
86 fprintf(fp
,"#define LEN_%s %d\n",cname
,(int)len
);
87 fprintf(fp
,"extern unsigned char %s[];\n",cname
);
92 int main (int argc
, char* argv
[])
102 fprintf(stderr
,"Usage: ipod2c file.ipod cname\n");
109 fd
= open(infile
,O_RDONLY
|O_BINARY
);
111 fprintf(stderr
,"Can not open %s\n",infile
);
115 len
= filesize(fd
) - 8;
117 n
= lseek(fd
,8,SEEK_SET
);
119 fprintf(stderr
,"Seek failed\n");
124 n
= read(fd
,buf
,len
);
126 fprintf(stderr
,"Short read, aborting\n");
131 if (write_cfile(buf
,len
,cname
) < 0) {
134 if (write_hfile(buf
,len
,cname
) < 0) {