home *** CD-ROM | disk | FTP | other *** search
- /* Res.c Drops the 128 byte file header that Dos 3.2's backup places
- on each file. By doing this you may be able to fix a file that
- dos won't restore. This should work with other versions of
- dos. The source code is for Turbo C. For best results compile
- in the compact, large, or huge models.*/
-
- #include <io.h>
- #include <alloc.h>
- #include <stdio.h>
- #include <fcntl.h>
- #include <string.h>
- #include <process.h>
- #include <stat.h>
- #define MAXBUFSIZE 65534L /*can't be > 65534 due to read fcn*/
- main(int argc, char *argv[])
- {
- int in_han, out_han;
- char *databuffer;
- unsigned long filesize, bufsize;
- unsigned int amt_to_transfer;
-
- printf("RES version 2.0 by S. Ostrander\n\n");
-
- bufsize = coreleft(); /* allocate memory for data buffer*/
- if (bufsize > MAXBUFSIZE)
- bufsize = MAXBUFSIZE;
- bufsize -= 100;
- if ((databuffer = malloc(bufsize)) == NULL)
- {
- printf("Not enough memory to run\n");
- exit (1);
- }
-
- if (argc != 3)
- {
- printf("Usage is RES infile outfile\n Res removes the 128 byte header created by dos's Backup\n A restore is not needed after using Res.\n");
- printf(" WARNING don't use on backuped files that extend accross more than one disk\n without consulting the operating instruction.\n");
- exit(2);
- }
- if ((stricmp(argv[1],argv[2])) == 0)
- {
- printf("Input and output files with the same name are not allowed\n");
- exit(3);
- }
-
- _fmode = O_BINARY; /* open files*/
- if ((in_han = open(argv[1], O_RDONLY)) == -1)
- {
- printf("Error opening input file\n");
- exit(4);
- }
- if ((out_han = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE)) == -1)
- {
- printf("Error opening output file\n");
- exit (5);
- }
-
- filesize = filelength(in_han);
- amt_to_transfer = (filesize < bufsize) ? filesize : bufsize;
-
- /* read and write first buffer and drop restore header */
-
- if ((read(in_han, databuffer, amt_to_transfer)) == -1)
- {
- printf("error reading file");
- exit (6);
- }
- if ((write(out_han, databuffer + 128, amt_to_transfer - 128)) == -1)
- {
- printf("Error writing file");
- exit (7);
- }
-
- /* do the rest of the file */
-
- while ((filesize -= amt_to_transfer) != 0)
- {
- amt_to_transfer = (filesize < bufsize) ? filesize : bufsize;
- if ((read(in_han, databuffer, amt_to_transfer)) == -1)
- {
- printf("error reading file");
- exit (8);
- }
- if ((write(out_han, databuffer, amt_to_transfer)) == -1)
- {
- printf("Error writing file");
- exit (9);
- }
- }
- printf("Restoration is completed.\n");
- exit (0);
-
- }