예제 #1
0
int main()
{
	struct list l = { NULL };
	struct record *rec, *ref;

	l.head = NULL;
	
	printf("\n testing rec_alloc...");
	rec = rec_alloc(101,"Abi",70);
	if(rec == NULL)
		goto fail;
	else 
		printf("[ok]");
	
	printf("\n testing rec_add [while adding first record]...");
	rec_add(&l, rec);
	if(l.head != rec)
		goto fail;
	else
		printf("[ok]");
	
	printf("\n adding several records...");
	rec = rec_alloc(102,"Anu",80);
	rec_add(&l, rec);
	
	ref = rec_alloc(103,"Balu",85);
	rec_add(&l, ref);
	
	rec = rec_alloc(104,"Chandran",90);
	rec_add(&l, rec);
	
	printf("[ok]");
	
	printf("\n testing rec_insert_before with next pointer...");
	rec = rec_alloc(105,"kiti",95);
	rec_insert_before(&l, ref, rec);

	if( rec->next != ref )
		goto fail;
	printf("[ok]");

	printf("\n testing rec_insert_before with rec_find...");
	rec = rec_find(&l, 105);
	if( rec->next != ref )
		goto fail;
	printf("[ok]\n");

	return 0;

fail:
	printf("[failed]\n");
	return 0;
}
예제 #2
0
int UnzOpr::find_ecrec64(ZInt64 searchlen) /* return PK-class error */
{
	uch byterec[ECREC64_SIZE + 4];

	switch(rec_find(searchlen, EndCentral64Sig /* fend_central64_sig */ ,
			ECREC64_SIZE))
	{
	case 1:
		return PK_OK;
	case 2:
		// if (uO.qflag || uO.zipinfo_mode)
		// Info(slide, 0x401, ((char *)slide, "[%s]\n", fzipfn));
		Notify(IERROR, _T("end-of-central-dir64 signature not found [%s]"),
			fzipfn.c_str());
		// Info(slide, 0x401, ((char *)slide,
		// LoadFarString(Cent64EndSigSearchErr)));
		return PK_ERR;
		/* else: found ECREC64, continue! */
	}

	freal_ecrec_offset = fcur_zipfile_bufstart + (finptr - finbuf);

	if (readbuf((char*)byterec, ECREC64_SIZE + 4) == 0)
		return PK_EOF;

	if (fecrec.number_this_disk == 0xffff)
		fecrec.number_this_disk = makelong(&byterec[NUMBER_THIS_DISK64]);
	if (fecrec.num_disk_start_cdir == 0xffff)
		fecrec.num_disk_start_cdir = makelong
			(&byterec[NUM_DISK_WITH_START_CEN_DIR64]);
	if (fecrec.num_entries_centrl_dir_ths_disk == 0xffff)
		fecrec.num_entries_centrl_dir_ths_disk = makeint64
			(&byterec[NUM_ENTRIES_CEN_DIR_THS_DISK64]);
	if (fecrec.total_entries_central_dir == 0xffff)
		fecrec.total_entries_central_dir = makeint64
			(&byterec[TOTAL_ENTRIES_CENTRAL_DIR64]);
	if (fecrec.size_central_directory == 0xffffffff)
		fecrec.size_central_directory = makeint64
			(&byterec[SIZE_CENTRAL_DIRECTORY64]);
	if (fecrec.offset_start_central_directory == 0xffffffff)
		fecrec.offset_start_central_directory = makeint64
			(&byterec[OFFSET_START_CENTRAL_DIRECTORY64]);

	/* We know its a big file now. The "end of the central directory" mark
	used as break condition for the central-directory scan  is the
	"end_central64" signature. */
	fecrec.is_zip64_archive = TRUE;
	return PK_COOL;
} /* end function find_ecrec64() */
예제 #3
0
/* ===========================================================================
 *                    Function find_ecrec()
 */
int UnzOpr::find_ecrec(ZInt64 searchlen)
{
	/* return PK-class error */
	int // i, numblks,
	found = false;
	int result;
	// /*long*/ZInt64 tail_len;
	ec_byte_rec byterec;

	if (Verbose < 0)
		Notify(ITRACE, _T("in find_ecrec (end of central dir)"));

	/* ---------------------------------------------------------------------------
	 *    Treat case of short zipfile separately.
	 *-------------------------------------------------------------------------- */
	if (fziplen <= INBUFSIZ)
	{
		fUnzInfile->SetPosition(0L, SEEK_SET);
		if ((fincnt = vclRead((char*)finbuf, (unsigned int)fziplen)) == (int)
			fziplen)
		/* 'P' must be at least 22 bytes from end of zipfile */
			for (finptr = finbuf + (int)fziplen - 22; finptr >= finbuf;
				--finptr)
				if (*(ulg*)finptr == EndCentralDirSig)
				// if ((native(* finptr) == 'P') && !strncmp((char *) finptr, fend_central_sig, 4))
				{
					fincnt -= (int)(finptr - finbuf);
					found = true;
					break;
				}

		/* ---------------------------------------------------------------------------
		 *  Zipfile is longer than INBUFSIZ:  may need to loop.  Start with short
		 *  block at end of zipfile (if not TOO short).
		 *--------------------------------------------------------------------------- */
	}
	else
	{
		found = rec_find(searchlen, EndCentralDirSig /* fend_central_sig */ ,
			ECREC_SIZE) == 0;
	}
	/* end if (ziplen > INBUFSIZ) */

	/* ---------------------------------------------------------------------------
	 * Searched through whole region where signature should be without finding
	 * it.  Print informational message and die a horrible death.
	 *--------------------------------------------------------------------------- */
	// fail:
	if (!found)
	{
		// UnzErr(UEN_EOF01);
		DZError(DZ_ERM_NO_CENTRAL);
		return PK_ERR;
		/* failed */
	}

	/* ---------------------------------------------------------------------------
	 * Found the signature, so get the end-central data before returning.  Do
	 * any necessary machine-type conversions (byte ordering, structure padding
	 * compensation) by reading data into character array and copying to struct.
	 *--------------------------------------------------------------------------- */
	freal_ecrec_offset = fcur_zipfile_bufstart + (finptr - finbuf);

	if (Verbose < 0)
	{
		Notify(ITRACE, _T(
				"Found end-of-central-dir signature at offset %Ld (%.8LXh)"),
			freal_ecrec_offset, freal_ecrec_offset);
		Notify(ITRACE, _T(
				"    from beginning of file; offset %d (%.4Xh) within block"),
			finptr - finbuf, finptr - finbuf);
	}

	if (readbuf((char*)byterec, ECREC_SIZE + 4) == 0)
		return PK_EOF;
	fecrec.number_this_disk = makeword(&byterec[NUMBER_THIS_DISK]);
	fecrec.num_disk_start_cdir = makeword
		(&byterec[NUM_DISK_WITH_START_CENTRAL_DIR]);
	fecrec.num_entries_centrl_dir_ths_disk = makeword
		(&byterec[NUM_ENTRIES_CENTRL_DIR_THS_DISK]);
	fecrec.total_entries_central_dir = makeword
		(&byterec[TOTAL_ENTRIES_CENTRAL_DIR]);
	fecrec.size_central_directory = makelong(&byterec[SIZE_CENTRAL_DIRECTORY]);
	fecrec.offset_start_central_directory = makelong
		(&byterec[OFFSET_START_CENTRAL_DIRECTORY]);
	fecrec.zipfile_comment_length = makeword(&byterec[ZIPFILE_COMMENT_LENGTH]);

	if (check_ecrec_zip64())
	{
		result = find_ecrec64(searchlen + 76);
		/* 76 bytes for zip64ec & zip64 locator */
		if (result != PK_COOL)
			return result;
	}

	fexpect_ecrec_offset = fecrec.offset_start_central_directory +
		fecrec.size_central_directory;
	return PK_COOL;
}