예제 #1
0
void
tar_mode_t(struct bsdtar *bsdtar)
{
	read_archive(bsdtar, 't');
	if (lafe_unmatched_inclusions_warn(bsdtar->matching, "Not found in archive") != 0)
		bsdtar->return_value = 1;
}
예제 #2
0
파일: main.c 프로젝트: Shmalow/sandbox
int main(int argc, char** argv) {
	int result = 0;
	progname = argv[0];
	printf("progname=%s\n", progname);
	manage_options(argc, argv);
	result = read_archive();
	
	return result;
}
예제 #3
0
void	my_unarchive(char *namear, int v)
{
  int	fd;

  if ((fd = open(namear, O_RDONLY)) == -1)
    my_puterror("open", 1);
  read_archive(fd, v);
  close(fd);
}
예제 #4
0
static int
read_archive(int fd, Elf *elf, char *file, char *label, read_cb_f *func,
    void *arg, int require_ctf)
{
	Elf *melf;
	Elf_Cmd cmd = ELF_C_READ;
	Elf_Arhdr *arh;
	int secnum = 1, found = 0;

	while ((melf = elf_begin(fd, cmd, elf)) != NULL) {
		int rc = 0;

		if ((arh = elf_getarhdr(melf)) == NULL) {
			elfterminate(file, "Can't get archive header for "
			    "member %d", secnum);
		}

		/* skip special sections - their names begin with "/" */
		if (*arh->ar_name != '/') {
			size_t memlen = strlen(file) + 1 +
			    strlen(arh->ar_name) + 1 + 1;
			char *memname = xmalloc(memlen);

			snprintf(memname, memlen, "%s(%s)", file, arh->ar_name);

			switch (elf_kind(melf)) {
			case ELF_K_AR:
				rc = read_archive(fd, melf, memname, label,
				    func, arg, require_ctf);
				break;
			case ELF_K_ELF:
				rc = read_file(melf, memname, label,
				    func, arg, require_ctf);
				break;
			default:
				terminate("%s: Unknown elf kind %d\n",
				    memname, elf_kind(melf));
			}

			free(memname);
		}

		cmd = elf_next(melf);
		(void) elf_end(melf);
		secnum++;

		if (rc < 0)
			return (rc);
		else
			found += rc;
	}

	return (found);
}
예제 #5
0
파일: read.c 프로젝트: AhmadTux/freebsd
void
tar_mode_x(struct bsdtar *bsdtar)
{
	struct archive *writer;

	writer = archive_write_disk_new();
	if (writer == NULL)
		lafe_errc(1, ENOMEM, "Cannot allocate disk writer object");
	if (!bsdtar->option_numeric_owner)
		archive_write_disk_set_standard_lookup(writer);
	archive_write_disk_set_options(writer, bsdtar->extract_flags);

	read_archive(bsdtar, 'x', writer);

	if (lafe_unmatched_inclusions_warn(bsdtar->matching, "Not found in archive") != 0)
		bsdtar->return_value = 1;
	archive_write_free(writer);
}
예제 #6
0
파일: zip.c 프로젝트: ccxvii/mio
unsigned char *load_file(const char *filename, int *lenp)
{
	struct directory *dir = dir_head;
	struct archive *zip = zip_head;
	unsigned char *data;
	char buf[512];

	data = read_file(filename, lenp);

	while (!data && dir) {
		strlcpy(buf, dir->name, sizeof buf);
		strlcat(buf, filename, sizeof buf);
		data = read_file(buf, lenp);
		dir = dir->next;
	}

	while (!data && zip) {
		data = read_archive(zip, filename, lenp);
		zip = zip->next;
	}

	return data;
}
예제 #7
0
static int
read_ctf_common(char *file, char *label, read_cb_f *func, void *arg,
    int require_ctf)
{
	Elf *elf;
	int found = 0;
	int fd;

	debug(3, "Reading %s (label %s)\n", file, (label ? label : "NONE"));

	(void) elf_version(EV_CURRENT);

	if ((fd = open(file, O_RDONLY)) < 0)
		terminate("%s: Cannot open for reading", file);
	if ((elf = elf_begin(fd, ELF_C_READ, NULL)) == NULL)
		elfterminate(file, "Cannot read");

	switch (elf_kind(elf)) {
	case ELF_K_AR:
		found = read_archive(fd, elf, file, label,
		    func, arg, require_ctf);
		break;

	case ELF_K_ELF:
		found = read_file(elf, file, label,
		    func, arg, require_ctf);
		break;

	default:
		terminate("%s: Unknown elf kind %d\n", file, elf_kind(elf));
	}

	(void) elf_end(elf);
	(void) close(fd);

	return (found);
}
예제 #8
0
void
ar_mode_x(struct bsdar *bsdar)
{

	read_archive(bsdar, 'x');
}
예제 #9
0
void
ar_mode_t(struct bsdar *bsdar)
{

	read_archive(bsdar, 't');
}
예제 #10
0
void
ar_mode_p(struct bsdar *bsdar)
{

	read_archive(bsdar, 'p');
}