Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. #define OFF             20
  2.  
  3. #include<stdio.h>
  4. #include<stdlib.h>
  5. #include<string.h>
  6.  
  7. int main(int argc,char * argv[])
  8. {
  9.  FILE * f;
  10.  char * buf;
  11.  unsigned long sz,newsz;
  12.  if(argc<3)
  13.  {
  14.   printf("Usage:\n");
  15.   printf("%s filename memsize_hex\n",argv[0]);
  16.   printf("Example:\n\t%s test.app 100000\n",argv[0]);
  17.   return -1;
  18.  }
  19.  sscanf(argv[2],"%x",&newsz);
  20.  if(newsz<0x10000 || newsz>0x2000000) /* Min 64kB max 32MB */
  21.  {
  22.   printf("Impossibly large memory size %x\n",newsz);
  23.   return -1;
  24.  }
  25.  f=fopen(argv[1],"rb");
  26.  if(!f)
  27.  {
  28.   printf("Unable to open file\n");
  29.   return -1;
  30.  }
  31.  fseek(f,0,SEEK_END);
  32.  sz=ftell(f);
  33.  fseek(f,0,SEEK_SET);
  34.  buf=malloc(sz);
  35.  if(!buf)
  36.  {
  37.   printf("Unable to allocate temporary buffer\n");
  38.   fclose(f);
  39.   return -1;
  40.  }
  41.  fread(buf,1,sz,f);
  42.  fclose(f);
  43.  f=fopen(argv[1],"wb");
  44.  *((unsigned long *)(buf+OFF))=newsz;
  45.  fwrite(buf,1,sz,f);
  46.  fclose(f);
  47.  free(buf);
  48.  return 0;
  49. }
  50.