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