home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <io.h>
- #include <fcntl.h>
- #include <sys\stat.h>
- #include <stdlib.h>
- #include <process.h>
- #include <alloc.h>
-
- void main(int parnum,char *pars[],char *env[])
- {
- int hfileexe,
- hfiledata,
- flmodulo,
- fl,
- rrbytes,
- checksumexe;
- long fileexel,
- filedatal;
- char far *buff;
-
- printf("LINKPLUS v1.0ß by Psycho/TSI (C) '92\n\n");
- if(parnum!=3)
- {
- printf("Too ");
- if(parnum<3) printf("few ");
- else printf("much ");
- printf("parameters!!\n");
- printf("USAGE: linkplus <exefile> <datafile>\n\n");
- exit(EXIT_FAILURE);
- }
- if((hfileexe=open(pars[1],O_RDWR|O_BINARY))==-1||
- (hfiledata=open(pars[2],O_RDONLY|O_BINARY))==-1)
- {
- printf("Error in file operations!!\n");
- printf("USAGE: linkplus <exefile> <datafile>\n\n");
- exit(EXIT_FAILURE);
- }
- printf("Checking file header...");
- read(hfileexe,&checksumexe,2);
- if(checksumexe!=0x5a4d)
- {
- printf("The %s is not exefile!!\n",pars[1]);
- exit(EXIT_FAILURE);
- }
- fileexel=filelength(hfileexe);
- filedatal=filelength(hfiledata);
- printf("Allocating memory...");
- if(!(buff=(char far *) farmalloc(32000)))
- {
- printf("Not enough memory!!\n\n");
- exit(EXIT_FAILURE);
- }
- printf("\nSize of %s %li bytes.\n",pars[1],fileexel);
- printf("Size of %s %li bytes.\n",pars[2],filedatal);
- fileexel+=filedatal;
- printf("New size of %s %li bytes.\n",pars[1],fileexel);
- flmodulo=(int) (fileexel%512L);
- fl=(int) (fileexel/512L);
- if(flmodulo) fl++;
- write(hfileexe,&flmodulo,2);
- write(hfileexe,&fl,2);
- lseek(hfileexe,0,SEEK_END);
- printf("Linking...");
- do {
- if((rrbytes=read(hfiledata,buff,32000))==-1)
- {
- printf("Read error!!\n\n");
- exit(EXIT_FAILURE);
- }
- if(rrbytes!=write(hfileexe,buff,rrbytes))
- {
- printf("Write error!!\n\n");
- exit(EXIT_FAILURE);
- }
- } while(rrbytes==32000);
- printf("\nLinking has successful.\n");
- exit(EXIT_SUCCESS);
- }
-