예제 #1
0
	/*******************************************************
		Function: extract_archive_member

		Given an archive of WHIRL objects, extract the one
		specified and put it into a separate file.

	 *******************************************************/
static int
extract_archive_member (bfd *abfd, string path)
{
    int fd = -1;
    int mode = 0666;
    pointer addr = (pointer)-1;
    struct areltdata *p_areltdata = (struct areltdata *)abfd->arelt_data;
    struct ar_hdr *p_hdr = arch_hdr(abfd);

    if ((fd = OPEN (path, O_RDWR|O_CREAT|O_TRUNC, mode)) != -1)
	addr = (pointer) MMAP ( 0, 
	    	    	    	p_hdr->ar_size,  
				PROT_READ|PROT_WRITE,
    	    	    	    	MAP_SHARED, 
				fd, 
				0);
	
    if (fd == -1 || addr == (pointer)-1 || FCHMOD (fd, mode) != 0 ) {
    	perror("cannot create intermediate file");
    	return -1;
    }

    CLOSE (fd);

    MEMCPY (addr, bfd_tell(abfd), p_hdr->ar_size);

    MUNMAP (addr, p_hdr->ar_size);

    return 0;

} /* extract_archive_member */
예제 #2
0
	/*******************************************************
		Function: extract_archive_member

		Given an archive of WHIRL objects, extract the one
		specified and put it into a separate file.

	 *******************************************************/
int
extract_archive_member (bfd *abfd, string path)
{
    int fd = -1;
    int mode = 0644;
    //pointer addr = (pointer)-1;
    struct ar_hdr *p_hdr = arch_hdr(abfd);
    size_t parsed_size;
    char *buf;

    parsed_size = strtol (p_hdr->ar_size, NULL, 10);
    if ((fd = OPEN (path, O_WRONLY|O_CREAT|O_TRUNC, mode)) != -1) {
	/*
	addr = (pointer) MMAP ( 0, 
	    	    	    	parsed_size,
				PROT_READ|PROT_WRITE,
    	    	    	    	MAP_SHARED, 
				fd, 
				0);
				*/
    }
	
    if (fd == -1 || FCHMOD (fd, mode) != 0 ) {
    	perror("cannot create intermediate file");
    	return -1;
    }

    if ((buf = malloc(parsed_size)) == NULL) {
	fprintf(stderr, "malloc failed for member %s\n", abfd->filename);
	return -1;
    }

    if (bfd_seek(abfd, 0, SEEK_SET) != 0) {
	fprintf(stderr, "bfd_seek failed for member %s\n", abfd->filename);
	return -1;
    }
    if (bfd_bread(buf, parsed_size, abfd) != parsed_size) {
	fprintf(stderr, "bfd_read failed for member %s\n", abfd->filename);
	return -1;
    }

    /* MEMCPY (addr, buf, parsed_size); */

    /* MUNMAP (addr, parsed_size); */
    if (write(fd, buf, parsed_size) < 0) {
	perror("cant write extracted archive object");
	return -1;
    }

    CLOSE (fd);
    free(buf);

    return 0;

} /* extract_archive_member */
예제 #3
0
int
fchmod3d(int fd, mode_t mode)
{
#if FS
	Mount_t*	mp;

	if (!fscall(NiL, MSG_fchmod, 0, fd, mode))
		return(state.ret);
	mp = monitored();
#endif
	if (FCHMOD(fd, mode))
		return(-1);
#if FS
	if (mp)
		fscall(mp, MSG_fchmod, 0, fd, mode);
	for (mp = state.global; mp; mp = mp->global)
		if (fssys(mp, MSG_fchmod))
			fscall(mp, MSG_fchmod, 0, fd, mode);
#endif
	return(0);
}