]> icculus.org git repositories - btb/d2x.git/blob - utility/hogcreate.c
added utilities
[btb/d2x.git] / utility / hogcreate.c
1 /* Written 1999 Jan 29 by Josh Cogliati
2    I grant this program to public domain.
3 */
4 #include<stdio.h>
5 #include<sys/types.h>
6 #include<sys/stat.h>
7 #include<fcntl.h>
8 #include<dirent.h>
9
10
11 void main(int argc, char *argv[]){
12   FILE * hogfile, * readfile;
13   DIR * dp;
14   struct dirent *ep;
15   int fp, len, fseekret=0;
16   char filename[13];
17   char * buf;
18   struct stat statbuf;
19   if(argc != 2){
20     printf("Usage: hogcreate hogfile\n"
21            "creates hogfile using all the files in the current directory\n"
22            );
23     exit(0);
24   }
25   hogfile = fopen(argv[1],"w"); 
26   buf = (char *)malloc(3);
27   strncpy(buf,"DHF",3);
28   fwrite(buf,3,1,hogfile);
29   printf("Creating: %s\n",argv[1]);
30   free(buf);
31   dp = opendir("./");
32   if (dp != NULL) {
33     while (ep = readdir(dp)) {
34       strcpy(filename, ep->d_name);
35       stat(filename,&statbuf);
36       if(! S_ISDIR(statbuf.st_mode)) {
37         printf("Filename: %s \tLength: %i\n",filename,statbuf.st_size);
38         readfile = fopen(filename,"r");
39         buf = (char *)malloc(statbuf.st_size);
40         if(buf == NULL) {
41           printf("Unable to allocate memery\n");
42         } else {
43           fwrite(filename, 13,1,hogfile);
44           fwrite(&statbuf.st_size, sizeof(int),1,hogfile);
45           fread(buf,statbuf.st_size, 1 , readfile);
46           fwrite(buf,statbuf.st_size, 1 , hogfile);
47         }
48         fclose(readfile);
49
50       }
51     }
52     closedir(dp);
53   }
54   fclose(hogfile);
55 }
56
57