home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Phoenix CD 2.0
/
Phoenix_CD.cdr
/
24b
/
memsave.zip
/
MEMSAVE.C
next >
Wrap
Text File
|
1987-12-02
|
3KB
|
81 lines
/* This program writes a designated range of memory to
a disk file. It requires several parameters, specifying
the output file, the start address in memory and the byte count.
It was compiled with the small model of the MSC 5.0 compiler,
taking advantage of the far pointer capability.
The program will set the errorlevel on output to 22 (EINVAL) if
it gets a bad parameter, or to the value of errno otherwise. The
errors that would typically be encountered are:
ENOSPC 28 out of disk space
ENOENT 2 some component of pathlist invalid
EACCES 13 probably trying to overwrite a r/o file
*/
/* Edition History:
1.0 First version HB
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
main(argc,argv)
int argc;
char **argv;
{
FILE *outfile;
int c;
long memsize;
char far *memptr; /* we use the long pointer type here */
if (argc != 4)
help(argv);
sscanf(argv[2],"%9p",&memptr); /* get the start addr in seg:off form */
sscanf(argv[3],"%9I",&memsize); /* get the size to write in hex */
if ((outfile = fopen(argv[1],"wb")) == NULL) /* open the file in binary mode! */
{
perror("Error opening outfile");
exit(errno);
}
for ( ; memsize > 0; memsize--, memptr++)
{
c = *memptr;
putc(c,outfile);
if (ferror(outfile))
break;
}
if ((ferror(outfile)) | (fflush(outfile))) /*flush the file to see if any errors are generated! */
perror("Error writing output file");
exit(errno);
}
/*************************************************
help routine
gets passed argv to find the name of the program
*************************************************/
help(filenam)
char **filenam;
{
char *prognam;
prognam = strrchr(*filenam,'\\');
prognam++;
fprintf(stderr,"%s\n",*filenam);
fprintf(stderr,"Purpose: Copies a selected portion of memory to a file\n");
fprintf(stderr,"Usage:%s outfile startaddr size\n",prognam);
fprintf(stderr,"where:\n");
fprintf(stderr," outfile = output file name\n");
fprintf(stderr," startaddr = memory starting address in segment:offset form\n");
fprintf(stderr," size = number of bytes to be written\n\n");
fprintf(stderr,"Note that the memory start address must be specified as:\n");
fprintf(stderr," XXXX:YYYY where XXXX is the segment and YYYY is the\n");
fprintf(stderr," offset value, in upper case hexadecimal characters.\n");
fprintf(stderr," The value of size is expected in decimal, but may be\n");
fprintf(stderr," in hex by prefixing the value with 0x.\n");
fprintf(stderr,"\nAuthor: H.Burman\nVersion: 1.0 Dec 2, 1987\n");
exit(EINVAL); /* Invalid argument error */
}