From c5b5533fa093533d1438aeed1d44eca4c61084c5 Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Thu, 13 Feb 2003 21:47:22 +0000 Subject: [PATCH] fix various little bugs --- utilities/hogcreate.c | 21 +++++++++++++++++++-- utilities/hogextract.c | 11 ++++++++++- utilities/mvlcreate.c | 31 ++++++++++++++++++++++++------- utilities/mvlextract.c | 5 ++++- 4 files changed, 57 insertions(+), 11 deletions(-) diff --git a/utilities/hogcreate.c b/utilities/hogcreate.c index 6d004b5a..c9ff134f 100644 --- a/utilities/hogcreate.c +++ b/utilities/hogcreate.c @@ -1,8 +1,13 @@ /* * Written 1999 Jan 29 by Josh Cogliati - * I grant this program to public domain. + * Modified by Bradley Bell, 2002, 2003 + * This program is licensed under the terms of the GPL, version 2 or later */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include #include @@ -11,6 +16,8 @@ #include #include +#define SWAPINT(x) (((x)<<24) | (((uint)(x)) >> 24) | (((x) &0x0000ff00) << 8) | (((x) & 0x00ff0000) >> 8)) + int main(int argc, char *argv[]) { @@ -20,6 +27,7 @@ main(int argc, char *argv[]) char filename[13]; char *buf; struct stat statbuf; + int tmp; if (argc != 2) { printf("Usage: hogcreate hogfile\n" @@ -35,6 +43,11 @@ main(int argc, char *argv[]) dp = opendir("./"); if (dp != NULL) { while ((ep = readdir(dp))) { + if (strlen(ep->d_name) > 12) { + fprintf(stderr, "error: filename %s too long! (12 chars max!)\n", ep->d_name); + return 1; + } + memset(filename, 0, 13); strcpy(filename, ep->d_name); stat(filename, &statbuf); if(! S_ISDIR(statbuf.st_mode)) { @@ -45,7 +58,11 @@ main(int argc, char *argv[]) printf("Unable to allocate memery\n"); } else { fwrite(filename, 13, 1, hogfile); - fwrite(&statbuf.st_size, sizeof(int), 1, hogfile); + tmp = (int)statbuf.st_size; +#ifdef WORDS_BIGENDIAN + tmp = SWAPINT(tmp); +#endif + fwrite(&tmp, 4, 1, hogfile); fread(buf, statbuf.st_size, 1, readfile); fwrite(buf, statbuf.st_size, 1, hogfile); } diff --git a/utilities/hogextract.c b/utilities/hogextract.c index 2f9a7bd3..596ba828 100644 --- a/utilities/hogextract.c +++ b/utilities/hogextract.c @@ -4,6 +4,10 @@ * This program is licensed under the terms of the GPL, version 2 or later */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include #include @@ -11,6 +15,8 @@ #include #include +#define SWAPINT(x) (((x)<<24) | (((uint)(x)) >> 24) | (((x) &0x0000ff00) << 8) | (((x) & 0x00ff0000) >> 8)) + int main(int argc, char *argv[]) { @@ -43,7 +49,10 @@ main(int argc, char *argv[]) free(buf); while(ftell(hogfile) 2 && strcmp(argv[2], filename)) fseek(hogfile, len, SEEK_CUR); else { diff --git a/utilities/mvlcreate.c b/utilities/mvlcreate.c index f6ab30cf..0a89b798 100644 --- a/utilities/mvlcreate.c +++ b/utilities/mvlcreate.c @@ -1,11 +1,13 @@ /* * Written 1999 Jan 29 by Josh Cogliati - * I grant this program to public domain. - * - * Modified for mvl by Bradley Bell, 2002 - * All modifications under GPL, version 2 or later + * Modified by Bradley Bell, 2002, 2003 + * This program is licensed under the terms of the GPL, version 2 or later */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include #include @@ -16,13 +18,15 @@ #define MAX_FILES 256 +#define SWAPINT(x) (((x)<<24) | (((uint)(x)) >> 24) | (((x) &0x0000ff00) << 8) | (((x) & 0x00ff0000) >> 8)) + int main(int argc, char *argv[]) { FILE *mvlfile, *readfile; DIR *dp; struct dirent *ep; - int i, nfiles = 0, len[MAX_FILES]; + int i, nfiles = 0, len[MAX_FILES], tmp; char filename[MAX_FILES][13]; char *buf; struct stat statbuf; @@ -36,6 +40,11 @@ main(int argc, char *argv[]) dp = opendir("./"); if (dp != NULL) { while ((ep = readdir(dp))) { + if (strlen(ep->d_name) > 12) { + fprintf(stderr, "error: filename %s too long! (12 chars max!)\n", ep->d_name); + return 1; + } + memset(filename[nfiles], 0, 13); strcpy(filename[nfiles], ep->d_name); stat(filename[nfiles], &statbuf); if(! S_ISDIR(statbuf.st_mode)) { @@ -54,11 +63,19 @@ main(int argc, char *argv[]) fwrite(buf, 4, 1, mvlfile); free(buf); - fwrite(&nfiles, 4, 1, mvlfile); + tmp = nfiles; +#ifdef WORDS_BIGENDIAN + tmp = SWAPINT(tmp); +#endif + fwrite(&tmp, 4, 1, mvlfile); for (i = 0; i < nfiles; i++) { fwrite(filename[i], 13, 1, mvlfile); - fwrite(&len[i], 4, 1, mvlfile); + tmp = len[i]; +#ifdef WORDS_BIGENDIAN + tmp = SWAPINT(tmp); +#endif + fwrite(&tmp, 4, 1, mvlfile); } for (i = 0; i < nfiles; i++) { diff --git a/utilities/mvlextract.c b/utilities/mvlextract.c index 85b5f92d..de17d857 100644 --- a/utilities/mvlextract.c +++ b/utilities/mvlextract.c @@ -46,8 +46,11 @@ main(int argc, char *argv[]) fread(buf, 4, 1, mvlfile); fread(&nfiles, 4, 1, mvlfile); printf("%d files\n", nfiles); - if (nfiles > MAX_FILES) // must be a bigendian mvl + if (nfiles > MAX_FILES) { // must be a bigendian mvl + fprintf(stderr, "warning: nfiles>%d, trying reverse byte order...", + MAX_FILES); bigendian = 1; + } if (bigendian) nfiles = SWAPINT(nfiles); printf("Extracting from: %s\n", argv[1]); -- 2.39.2