summaryrefslogtreecommitdiffstats
path: root/rbutil/tools/bin2c.c
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2009-11-07 20:03:32 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2009-11-07 20:03:32 +0000
commit992b57324e60b5b264e9f80f8ddee1da5413a5ad (patch)
tree50bd921b646a8865939e2563005dcac5e7b34f68 /rbutil/tools/bin2c.c
parent513a76e14eaedbc83779a862ea5e3991ed348489 (diff)
downloadrockbox-992b57324e60b5b264e9f80f8ddee1da5413a5ad.tar.gz
rockbox-992b57324e60b5b264e9f80f8ddee1da5413a5ad.tar.bz2
rockbox-992b57324e60b5b264e9f80f8ddee1da5413a5ad.zip
Allow the bin2c output filename stem to contain a path.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23557 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'rbutil/tools/bin2c.c')
-rw-r--r--rbutil/tools/bin2c.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/rbutil/tools/bin2c.c b/rbutil/tools/bin2c.c
index 75b44d5df7..36e245133e 100644
--- a/rbutil/tools/bin2c.c
+++ b/rbutil/tools/bin2c.c
@@ -34,6 +34,7 @@
#define close _close
#define read _read
#endif
+#include <libgen.h>
#ifndef O_BINARY
#define O_BINARY 0
@@ -50,10 +51,14 @@ static off_t filesize(int fd)
static int write_cfile(const unsigned char* buf, off_t len, const char* cname)
{
char filename[256];
+ char filebase[256];
+ char* bn;
FILE* fp;
int i;
snprintf(filename,256,"%s.c",cname);
+ strncpy(filebase, cname, 256);
+ bn = basename(filebase);
fp = fopen(filename,"w+");
if (fp == NULL) {
@@ -62,7 +67,7 @@ static int write_cfile(const unsigned char* buf, off_t len, const char* cname)
}
fprintf(fp,"/* Generated by bin2c */\n\n");
- fprintf(fp,"unsigned char %s[] = {",cname);
+ fprintf(fp,"unsigned char %s[] = {",bn);
for (i=0;i<len;i++) {
if ((i % 16) == 0) {
@@ -83,9 +88,13 @@ static int write_cfile(const unsigned char* buf, off_t len, const char* cname)
static int write_hfile(off_t len, const char* cname)
{
char filename[256];
+ char filebase[256];
+ char* bn;
FILE* fp;
snprintf(filename,256,"%s.h",cname);
+ strncpy(filebase, cname, 256);
+ bn = basename(filebase);
fp = fopen(filename,"w+");
if (fp == NULL) {
fprintf(stderr,"Couldn't open %s\n",filename);
@@ -93,8 +102,8 @@ static int write_hfile(off_t len, const char* cname)
}
fprintf(fp,"/* Generated by bin2c */\n\n");
- fprintf(fp,"#define LEN_%s %d\n",cname,(int)len);
- fprintf(fp,"extern unsigned char %s[];\n",cname);
+ fprintf(fp,"#define LEN_%s %d\n",bn,(int)len);
+ fprintf(fp,"extern unsigned char %s[];\n",bn);
fclose(fp);
return 0;
}