dxx-rebirth/utilities/hogcreate.c

62 lines
1.3 KiB
C
Raw Normal View History

2002-08-13 06:56:57 +00:00
/*
* Written 1999 Jan 29 by Josh Cogliati
* I grant this program to public domain.
*/
2002-08-13 07:12:00 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>
2002-08-13 06:45:00 +00:00
2002-08-13 07:12:00 +00:00
int
2002-08-13 06:56:57 +00:00
main(int argc, char *argv[])
{
FILE *hogfile, *readfile;
DIR *dp;
struct dirent *ep;
char filename[13];
char *buf;
struct stat statbuf;
2002-08-13 06:45:00 +00:00
2002-08-13 06:56:57 +00:00
if (argc != 2) {
printf("Usage: hogcreate hogfile\n"
"creates hogfile using all the files in the current directory\n");
exit(0);
2002-08-13 06:45:00 +00:00
}
2002-08-13 06:56:57 +00:00
hogfile = fopen(argv[1], "w");
buf = (char *)malloc(3);
strncpy(buf, "DHF", 3);
fwrite(buf, 3, 1, hogfile);
printf("Creating: %s\n", argv[1]);
free(buf);
dp = opendir("./");
if (dp != NULL) {
2002-08-13 07:12:00 +00:00
while ((ep = readdir(dp))) {
2002-08-13 06:56:57 +00:00
strcpy(filename, ep->d_name);
stat(filename, &statbuf);
if(! S_ISDIR(statbuf.st_mode)) {
2002-08-13 07:12:00 +00:00
printf("Filename: %s \tLength: %i\n", filename, (int)statbuf.st_size);
2002-08-13 06:56:57 +00:00
readfile = fopen(filename, "r");
buf = (char *)malloc(statbuf.st_size);
if (buf == NULL) {
printf("Unable to allocate memery\n");
} else {
fwrite(filename, 13, 1, hogfile);
fwrite(&statbuf.st_size, sizeof(int), 1, hogfile);
fread(buf, statbuf.st_size, 1, readfile);
fwrite(buf, statbuf.st_size, 1, hogfile);
}
fclose(readfile);
2002-08-13 06:45:00 +00:00
2002-08-13 06:56:57 +00:00
}
}
closedir(dp);
}
fclose(hogfile);
2002-08-13 07:12:00 +00:00
return 0;
2002-08-13 06:45:00 +00:00
}