1313#include "romimg.h"
1414#include "SonyRX.h"
1515
16- #define BUFCHK (X ) (X[0] == '\0') ? "" : X
1716#define IMAGE_COMMENT_BASESIZE 31
1817
1918struct ROMImgStat
@@ -160,7 +159,7 @@ int CreateBlankROMImg(const char *filename, ROMIMG *ROMImg)
160159 GetCurrentWorkingDirectory (cwd , sizeof (cwd ));
161160 /* Comment format: YYYYMMDD-XXXYYY,conffile,<filename>,<user>@<localhost>/<image path> */
162161 CommentLength = IMAGE_COMMENT_BASESIZE + strlen (filename ) + sizeof (LocalhostName ) + sizeof (UserName ) + MAX_PATH ;
163- ROMImg -> comment = (char * )calloc ( 0 , CommentLength + 1 );
162+ ROMImg -> comment = (char * )malloc ( CommentLength + 1 );
164163 if (!ROMImg -> comment ) return ENOMEM ;
165164 snprintf (ROMImg -> comment , CommentLength , "%08x,conffile,%s,%s@%s/%s" , ROMImg -> date , filename , BUFCHK (UserName ), BUFCHK (LocalhostName ), cwd );
166165
@@ -453,15 +452,26 @@ static int AddExtInfoStat(struct FileEntry *file, unsigned char type, void *data
453452 return result ;
454453}
455454
456- int AddFile (ROMIMG * ROMImg , const char * path )
455+ int AddFile (ROMIMG * ROMImg , const char * path , int upperconv )
457456{
457+ char tbuf [10 ] = "\0" ; // we dont need a large buf, this is for filling in the filename on ROMFS
458458 FILE * InputFile ;
459459 int result ;
460460 unsigned int FileDateStamp ;
461461 unsigned short FileVersion ;
462462 if ((InputFile = fopen (path , "rb" )) != NULL ) {
463463 const char * fname = strrchr (path , PATHSEP );
464464 if (fname == NULL ) fname = path ; else fname ++ ;
465+ if (upperconv ) {
466+ strncpy (tbuf , fname , sizeof (tbuf ));
467+ tbuf [sizeof (tbuf ) - 1 ] = '\0' ;
468+ if (tbuf [0 ] != '\0' ) {
469+ upperbuff (tbuf );
470+ fname = tbuf ;
471+ char * T = strrchr (fname , '.' );
472+ if (T != NULL ) * T = '\0' ; //null terminate extension
473+ }
474+ }
465475 int size ;
466476 fseek (InputFile , 0 , SEEK_END );
467477 size = ftell (InputFile );
@@ -477,7 +487,7 @@ int AddFile(ROMIMG *ROMImg, const char *path)
477487 file = & ROMImg -> files [ROMImg -> NumFiles - 1 ];
478488 memset (& ROMImg -> files [ROMImg -> NumFiles - 1 ], 0 , sizeof (struct FileEntry ));
479489
480- strncpy (file -> RomDir .name , fname , sizeof (file -> RomDir .name ) - 1 );
490+ strncpy (file -> RomDir .name , fname , sizeof (file -> RomDir .name ));
481491 file -> RomDir .name [sizeof (file -> RomDir .name ) - 1 ] = '\0' ;
482492 file -> RomDir .ExtInfoEntrySize = 0 ;
483493
0 commit comments