use binary mode for reading/writing files

This commit is contained in:
Bradley Bell 2003-10-05 22:31:42 +00:00
parent d3b646ad17
commit 4cead8d554
5 changed files with 13 additions and 9 deletions

View file

@ -1,5 +1,9 @@
2003-10-05 Bradley Bell <btb@icculus.org>
* utilities/hogcreate.c, utilities/hogextract.c,
utilities/mvlcreate.c, utilities/mvlextract.c: use binary mode for
reading/writing files
* arch/win32/Makefile.am, arch/win32/include/ipx_udp.h,
arch/win32/ipx_udp.c, arch/win32/winnet.c, main/menu.c: added UDP
support for win32

View file

@ -34,7 +34,7 @@ main(int argc, char *argv[])
"creates hogfile using all the files in the current directory\n");
exit(0);
}
hogfile = fopen(argv[1], "w");
hogfile = fopen(argv[1], "wb");
buf = (char *)malloc(3);
strncpy(buf, "DHF", 3);
fwrite(buf, 3, 1, hogfile);
@ -52,7 +52,7 @@ main(int argc, char *argv[])
stat(filename, &statbuf);
if(! S_ISDIR(statbuf.st_mode)) {
printf("Filename: %s \tLength: %i\n", filename, (int)statbuf.st_size);
readfile = fopen(filename, "r");
readfile = fopen(filename, "rb");
buf = (char *)malloc(statbuf.st_size);
if (buf == NULL) {
printf("Unable to allocate memery\n");

View file

@ -40,7 +40,7 @@ main(int argc, char *argv[])
" v View files, don't extract\n");
exit(0);
}
hogfile = fopen(argv[1], "r");
hogfile = fopen(argv[1], "rb");
stat(argv[1], &statbuf);
printf("%i\n", (int)statbuf.st_size);
buf = (char *)malloc(3);
@ -49,7 +49,7 @@ main(int argc, char *argv[])
free(buf);
while(ftell(hogfile)<statbuf.st_size) {
fread(filename, 13, 1, hogfile);
fread(&len, 4, 1, hogfile);
fread(&len, 1, 4, hogfile);
#ifdef WORDS_BIGENDIAN
len = SWAPINT(len);
#endif
@ -65,7 +65,7 @@ main(int argc, char *argv[])
printf("Unable to allocate memory\n");
} else {
fread(buf, len, 1, hogfile);
writefile = fopen(filename, "w");
writefile = fopen(filename, "wb");
fwrite(buf, len, 1, writefile);
fclose(writefile);
free(buf);

View file

@ -57,7 +57,7 @@ main(int argc, char *argv[])
closedir(dp);
printf("Creating: %s\n", argv[1]);
mvlfile = fopen(argv[1], "w");
mvlfile = fopen(argv[1], "wb");
buf = (char *)malloc(4);
strncpy(buf, "DMVL", 4);
fwrite(buf, 4, 1, mvlfile);
@ -79,7 +79,7 @@ main(int argc, char *argv[])
}
for (i = 0; i < nfiles; i++) {
readfile = fopen(filename[i], "r");
readfile = fopen(filename[i], "rb");
buf = (char *)malloc(len[i]);
if (buf == NULL) {
printf("Unable to allocate memory\n");

View file

@ -39,7 +39,7 @@ main(int argc, char *argv[])
" v View files, don't extract\n");
exit(0);
}
mvlfile = fopen(argv[1], "r");
mvlfile = fopen(argv[1], "rb");
stat(argv[1], &statbuf);
printf("%i\n", (int)statbuf.st_size);
buf = (char *)malloc(4);
@ -78,7 +78,7 @@ main(int argc, char *argv[])
printf("Unable to allocate memory\n");
} else {
fread(buf, len[i], 1, mvlfile);
writefile = fopen(filename[i], "w");
writefile = fopen(filename[i], "wb");
fwrite(buf, len[i], 1, writefile);
fclose(writefile);
free(buf);