Example #1
0
int main(int argc, char *argv[])
{
#ifdef HANDLER
	signal(SIGABRT, sig_abrt);
#endif
	printf("in main:\n");
	l_abort();
	printf("after abort:\n"); /*never arrive */
	return 0;
}
Example #2
0
// Public API
//Open a Zip file and initialize.
void
openZipFileReader(char *fname) {
    if (!zipfp) {
    	zipfp = fopen(fname, "rb");
    	if (!zipfp) {
    	    perror("fopen");
            sprintf(message, "Could not open input zip file %s\n",fname);
    	    l_abort(message);
    	}
    }
}
Example #3
0
// Write data to the ZIP output stream.
void
write_data(void *buff, int len) 
{
    while (len > 0) {
	int rc = fwrite(buff, 1, len, jarfp);
	if (rc <= 0) {
	    sprintf(message, "Write on output file failed err=%d\n",errno);
	    l_abort(message);
	}
	output_file_offset += rc;
	buff = ((char *)buff) + rc;
	len -= rc;
    }
}
Example #4
0
//Read the file and extract its contents to the
//to the directory of the zipfile.
void do_read(char *inputzip, char* outputdir)
{
  char *extract_dir = NULL;

  if (outputdir != NULL)
      extract_dir = dirname(outputdir);
  else
      extract_dir = dirname(inputzip);

  if ( (extract_dir != NULL) && (strlen(extract_dir) > 0) ) 
  {
     // ensure directory is created first
     char *dir = (char *) malloc(strlen(extract_dir) + 2);
     sprintf(dir, "%s/", extract_dir);
     mkdirs(dir);
     free(dir);

     chdir(extract_dir);
  }
  openZipFileReader(inputzip);
  fprintf(stderr,"Archive: %s\n",inputzip);

  bool next = isNext();

  // We must have atleast one entry
  if (!next) {  
    sprintf(message,"Error: no entries in zip file.\n");
    l_abort(message);
  }

  while (next) {
    readAndWrite();
    next = isNext();
  }

  closeZipFileReader();
  if (remove_input_zip_file) remove(inputzip);
}
Example #5
0
static void readAndWrite() {
  char filename[MAX_PATH];
  int rc;

  //Note: We have already read the magic number of 4 bytes.

  //Skip to compression if the file is compressed then abort.
  fseek(zipfp,4,SEEK_CUR);
  ushort compression;
  rc = fread(&compression,1,sizeof(ushort),zipfp);
  if (compression) l_abort("Error: Cannot unzip deflated file entries.\n");

  // Skip over to file length
  fseek(zipfp,12,SEEK_CUR); 
  int file_len;
  rc = fread(&file_len,1,sizeof(int),zipfp);

  ushort filenamelen;
  rc = fread(&filenamelen,1,sizeof(ushort),zipfp);

  ushort extrafieldlen;
  rc = fread(&extrafieldlen,1, sizeof(ushort), zipfp);
  
  rc = fread(filename,filenamelen,sizeof(char),zipfp);
  filename[filenamelen]='\0';
  if (rc <=0) {
    sprintf(message,"Error: Could not read filename <%s>  from zip header\n", filename);
    l_abort(message);
  }

  bool isDir = (filename[filenamelen-1] == '/') ? true : false;

  char *pathname = dirname(filename);
  if (pathname != NULL) {
    mkdirs(filename);
    free(pathname);
  }

  fprintf(stderr,"  extracting: %s",filename);
  
  FILE *filefp=NULL;

  if (!isDir) {
    filefp = fopen(filename,"wb+");
    if (filefp == NULL) {
      sprintf(message,"Error:fopen: while opening file <%s>\n",filename);
      l_abort(message);
    }
  }

  if (extrafieldlen > 0) {
    fseek(zipfp,extrafieldlen,SEEK_CUR);
  }

  if (!isDir) {
    //Read and write our file entry
    rc = 1;
    {
      char *buffer = (char *) malloc(file_len+1);
      rc = fread(buffer, 1, file_len, zipfp);
      int rc2 = fwrite(buffer,1,rc,filefp);
      if (buffer) free(buffer);
    }
    fclose(filefp);
  }
  fprintf(stderr,"\n");
}